fix: verify full prebuilt images before offline production deployment
This commit is contained in:
@@ -92,3 +92,53 @@ def test_release_rejects_wrong_storage_uuid(release_tool, monkeypatch):
|
||||
monkeypatch.setattr(release_tool, "run", lambda *args: "different-storage-uuid")
|
||||
with pytest.raises(AssertionError):
|
||||
release_tool.main()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("invalid", [None, "id", "commit", "version", "content"])
|
||||
def test_prebuilt_image_is_bound_to_source_before_deployment(
|
||||
release_tool, monkeypatch, invalid
|
||||
):
|
||||
import json
|
||||
import subprocess
|
||||
|
||||
digest = "sha256:" + "a" * 64
|
||||
monkeypatch.setenv("FRAME_FLOW_PREBUILT_IMAGE_ID", digest)
|
||||
metadata = {
|
||||
"Id": digest,
|
||||
"Config": {
|
||||
"Labels": {
|
||||
"org.opencontainers.image.revision": "fixture-commit",
|
||||
"org.opencontainers.image.version": "0.1.22",
|
||||
}
|
||||
},
|
||||
}
|
||||
if invalid == "id":
|
||||
metadata["Id"] = "sha256:" + "b" * 64
|
||||
if invalid == "commit":
|
||||
metadata["Config"]["Labels"]["org.opencontainers.image.revision"] = "wrong"
|
||||
if invalid == "version":
|
||||
metadata["Config"]["Labels"]["org.opencontainers.image.version"] = "wrong"
|
||||
monkeypatch.setattr(release_tool, "run", lambda *args: json.dumps([metadata]))
|
||||
calls = []
|
||||
|
||||
def isolated(command, **kwargs):
|
||||
calls.append(command)
|
||||
assert "--network=none" in command and "--read-only" in command
|
||||
assert "--cap-drop=ALL" in command and "--user=10333:10333" in command
|
||||
assert "-v" not in command and "--mount" not in command
|
||||
assert json.loads(kwargs["input"]) == {"LICENSE": "fixture-hash"}
|
||||
if invalid == "content":
|
||||
raise subprocess.CalledProcessError(1, command)
|
||||
|
||||
monkeypatch.setattr(release_tool.subprocess, "run", isolated)
|
||||
if invalid:
|
||||
with pytest.raises((AssertionError, subprocess.CalledProcessError)):
|
||||
release_tool.verify_prebuilt_image(
|
||||
"fixture-image", "fixture-commit", "0.1.22", {"LICENSE": "fixture-hash"}
|
||||
)
|
||||
else:
|
||||
assert release_tool.verify_prebuilt_image(
|
||||
"fixture-image", "fixture-commit", "0.1.22", {"LICENSE": "fixture-hash"}
|
||||
)
|
||||
if invalid in ("id", "commit", "version"):
|
||||
assert not calls
|
||||
|
||||
Reference in New Issue
Block a user