Authored-By: OpenAI (GPT-5) <noreply@openai.com>
This commit is contained in:
+77
-1
@@ -113,6 +113,30 @@ class ConfigContractTests(unittest.TestCase):
|
||||
self.assertEqual(["/dist", "/"], [route["path"] for route in cfg["routes"]])
|
||||
credentials = {artifact["name"]: artifact["credentials"] for artifact in cfg["artifacts"]}
|
||||
self.assertNotEqual(credentials["distributions"], credentials["portal"])
|
||||
distributions = next(
|
||||
artifact for artifact in cfg["artifacts"] if artifact["name"] == "distributions"
|
||||
)
|
||||
self.assertEqual(["*"], distributions["cors_origins"])
|
||||
|
||||
def test_cors_origins_are_https_origins_or_wildcard(self):
|
||||
self.assert_invalid(
|
||||
lambda raw: raw["artifacts"][1].__setitem__(
|
||||
"cors_origins", ["http://consumer.example"]
|
||||
),
|
||||
"must contain '\\*' or HTTPS origins",
|
||||
)
|
||||
self.assert_invalid(
|
||||
lambda raw: raw["artifacts"][1].__setitem__(
|
||||
"cors_origins", ["https://consumer.example", "https://consumer.example"]
|
||||
),
|
||||
"must not contain duplicates",
|
||||
)
|
||||
|
||||
def test_protected_route_rejects_wildcard_cors(self):
|
||||
self.assert_invalid(
|
||||
lambda raw: raw["artifacts"][0].__setitem__("cors_origins", ["*"]),
|
||||
"protected route portal cannot allow wildcard CORS",
|
||||
)
|
||||
|
||||
def test_equivalent_route_paths_are_ambiguous(self):
|
||||
self.assert_invalid(lambda raw: raw["routes"].append({
|
||||
@@ -131,6 +155,7 @@ class ConfigContractTests(unittest.TestCase):
|
||||
raw["routes"][1]["access"] = {
|
||||
"mode": "protected", "middleware": "authentik-forwardauth"
|
||||
}
|
||||
raw["artifacts"][1]["cors_origins"] = []
|
||||
raw["artifacts"][0]["cache"]["rules"][0]["cache_control"] = (
|
||||
"public, max-age=0, must-revalidate"
|
||||
)
|
||||
@@ -317,6 +342,30 @@ class BuildTests(unittest.TestCase):
|
||||
|
||||
|
||||
class PublishingTests(unittest.TestCase):
|
||||
def test_cors_policy_is_reconciled_as_read_only_browser_access(self):
|
||||
captured = {}
|
||||
|
||||
def capture(command, **_kwargs):
|
||||
config_path = command[command.index("--cors-configuration") + 1]
|
||||
captured["command"] = command
|
||||
captured["config"] = json.loads(Path(config_path.removeprefix("file://")).read_text())
|
||||
|
||||
with patch.object(deploy, "run", side_effect=capture):
|
||||
deploy.configure_cors(
|
||||
"baseline-dist", ["*"], "http://garage-s3.storage.svc:3900", {}
|
||||
)
|
||||
|
||||
self.assertIn("put-bucket-cors", captured["command"])
|
||||
self.assertEqual(["GET", "HEAD"], captured["config"]["CORSRules"][0]["AllowedMethods"])
|
||||
self.assertEqual(["*"], captured["config"]["CORSRules"][0]["AllowedOrigins"])
|
||||
|
||||
def test_empty_cors_policy_removes_stale_bucket_cors(self):
|
||||
with patch.object(deploy, "run") as request:
|
||||
deploy.configure_cors(
|
||||
"baseline-catalogue", [], "http://garage-s3.storage.svc:3900", {}
|
||||
)
|
||||
self.assertIn("delete-bucket-cors", request.call_args.args[0])
|
||||
|
||||
def test_apps_clone_never_places_token_in_argv_or_log(self):
|
||||
calls = []
|
||||
secret = "clone-secret-must-not-appear"
|
||||
@@ -437,15 +486,42 @@ class PublishingTests(unittest.TestCase):
|
||||
patch.object(deploy, "validate_artifact_output"), patch.object(
|
||||
deploy, "publish_route_immutables",
|
||||
side_effect=[None, RuntimeError("immutable failed")],
|
||||
) as immutable_publish, patch.object(deploy, "s3_sync") as mutable_sync, \
|
||||
) as immutable_publish, patch.object(
|
||||
deploy, "configure_artifact_cors"
|
||||
) as cors_configure, patch.object(deploy, "s3_sync") as mutable_sync, \
|
||||
self.assertRaisesRegex(
|
||||
RuntimeError, "immutable failed"
|
||||
):
|
||||
deploy.deploy_static("baseline", root, root, "token", cfg)
|
||||
|
||||
self.assertEqual(2, immutable_publish.call_count)
|
||||
cors_configure.assert_not_called()
|
||||
mutable_sync.assert_not_called()
|
||||
|
||||
def test_all_cors_policies_complete_before_mutable_publication(self):
|
||||
cfg = normalize_site_config(fixture("split-site.yaml"), "baseline.fritzlab.net")
|
||||
events = []
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp)
|
||||
apps = root / "apps"
|
||||
apps.mkdir()
|
||||
with patch.object(deploy, "validate_publication_environment"), patch.object(
|
||||
deploy, "validate_artifact_output"
|
||||
), patch.object(
|
||||
deploy, "publish_route_immutables", side_effect=lambda *_args: events.append("immutable")
|
||||
), patch.object(
|
||||
deploy, "configure_artifact_cors", side_effect=lambda *_args: events.append("cors")
|
||||
), patch.object(
|
||||
deploy, "s3_sync", side_effect=lambda *_args: events.append("mutable")
|
||||
), patch.object(deploy, "clone_apps", return_value=apps), patch.object(
|
||||
deploy, "render_site_manifests"
|
||||
), patch.object(deploy, "commit_and_push"):
|
||||
deploy.deploy_static("baseline", root, root, "token", cfg)
|
||||
|
||||
self.assertEqual(
|
||||
["immutable", "immutable", "cors", "cors", "mutable", "mutable"], events
|
||||
)
|
||||
|
||||
|
||||
def test_absent_artifact_is_detected_before_publish(self):
|
||||
cfg = normalize_site_config(fixture("split-site.yaml"), "baseline.fritzlab.net")
|
||||
|
||||
Reference in New Issue
Block a user