diff --git a/test_inventory.py b/test_inventory.py index b0598a8..87773ae 100644 --- a/test_inventory.py +++ b/test_inventory.py @@ -6,8 +6,6 @@ import json import os from pathlib import Path -import subprocess -import sys import tarfile import tempfile import unittest @@ -314,7 +312,7 @@ def test_sbom_subject_components_spdx_and_malformed_types(self): self.assertEqual(2, code) self.assertFalse(json.loads(out)["complete"]) - def test_output_protection_no_clobber_and_standalone_copy(self): + def test_output_protection_and_no_clobber(self): with tempfile.TemporaryDirectory() as directory: root = Path(directory) source = root / "image.tar" @@ -329,10 +327,6 @@ def test_output_protection_no_clobber_and_standalone_copy(self): output.write_text("preserve", encoding="utf-8") self.assertEqual(2, self.cli("--archive", str(source), "--output", str(output))[0]) self.assertEqual("preserve", output.read_text(encoding="utf-8")) - checker = root / "checker.py" - checker.write_bytes(Path(c.__file__).read_bytes()) - result = subprocess.run([sys.executable, str(checker), "--archive", str(source)], capture_output=True, text=True, check=True) - self.assertTrue(json.loads(result.stdout)["complete"]) def test_interruptions_do_not_append_second_report_or_retry_publication(self): with tempfile.TemporaryDirectory() as directory: diff --git a/test_provenance.py b/test_provenance.py index 7f95b44..62aeaae 100644 --- a/test_provenance.py +++ b/test_provenance.py @@ -13,6 +13,7 @@ from unittest import mock import oci_runtime_inventory as c +from test_inventory import docker_archive, package, tar_bytes class ProvenanceTests(unittest.TestCase): @@ -90,7 +91,9 @@ def test_copied_and_symlinked_standalone_report_executed_bytes(self): copied = Path(directory) / "inventory.py" shutil.copyfile(c.__file__, copied) copied.write_bytes(copied.read_bytes() + b"\n# synthetic copy\n") - source = Path(__file__).parent / "examples/inventory.sbom.json" + archive = Path(directory) / "image.tar" + archive.write_bytes(docker_archive([tar_bytes([("app/package.json", package())])])) + sbom = Path(__file__).parent / "examples/inventory.sbom.json" paths = [copied] link = Path(directory) / "link.py" try: @@ -99,9 +102,15 @@ def test_copied_and_symlinked_standalone_report_executed_bytes(self): except OSError: pass for path in paths: - result = subprocess.run([sys.executable, str(path), "--sbom", str(source)], capture_output=True, text=True, encoding="utf-8", timeout=15) + command = [sys.executable, str(path), "--archive", str(archive), "--sbom", str(sbom)] + result = subprocess.run(command, capture_output=True, text=True, encoding="utf-8", timeout=15) self.assertEqual(0, result.returncode, result.stderr) report = json.loads(result.stdout) + self.assertTrue(report["complete"]) + names = [row["name"] for image in report["images"] for row in image["components"]] + self.assertEqual(["sharp"], names) + self.assertEqual("sha256:" + hashlib.sha256(sbom.read_bytes()).hexdigest(), + report["sboms"][0]["artifact_digest"]) self.assertEqual(hashlib.sha256(copied.read_bytes()).hexdigest(), report["tool"]["executable_sha256"]) def test_incomplete_inventory_receipt_links_exact_export(self):