Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions test_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import json
import os
from pathlib import Path
import subprocess
import sys
import tarfile
import tempfile
import unittest
Expand Down Expand Up @@ -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"
Expand All @@ -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:
Expand Down
13 changes: 11 additions & 2 deletions test_provenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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):
Expand Down
Loading