Support issue-linked demo source changes
This commit is contained in:
@@ -7,15 +7,28 @@ import sys
|
||||
import tarfile
|
||||
import zipfile
|
||||
|
||||
sys.dont_write_bytecode = True
|
||||
from source_provenance import BASELINE_SHA256, load_definition, strict_json, verify_packaged_provenance
|
||||
|
||||
folder = Path(sys.argv[1] if len(sys.argv) > 1 else 'build/demo/artifacts').resolve()
|
||||
actual_hashes = {}
|
||||
for line in (folder / 'SHA256SUMS').read_text().splitlines():
|
||||
expected, name = line.split(' ', 1)
|
||||
assert Path(name).name == name and re.fullmatch(r'[0-9a-f]{64}', expected)
|
||||
assert Path(name).name == name and name not in actual_hashes and re.fullmatch(r'[0-9a-f]{64}', expected)
|
||||
with (folder / name).open('rb') as stream:
|
||||
assert hashlib.file_digest(stream, 'sha256').hexdigest() == expected, name
|
||||
record = json.loads((folder / 'delivery-info.json').read_text())
|
||||
actual_hashes[name] = hashlib.file_digest(stream, 'sha256').hexdigest()
|
||||
assert actual_hashes[name] == expected, name
|
||||
record = strict_json((folder / 'delivery-info.json').read_bytes())
|
||||
if 'source_verification' in record:
|
||||
baseline, _, _, _ = load_definition(Path(__file__).resolve().parents[1])
|
||||
verify_packaged_provenance(record, baseline)
|
||||
else:
|
||||
print('Legacy artifact: transport/OCI verification only; no new source-change proof is claimed.')
|
||||
version = record['delivery_version']
|
||||
assert re.fullmatch(r'\d+\.\d+\.\d+', version)
|
||||
assert {'delivery-info.json', f'TikZRefinery-{version}-linux-image.tar.gz',
|
||||
f'TikZRefinery-{version}-architecture.zip'} <= set(actual_hashes)
|
||||
assert record['image_archive_sha256'] == actual_hashes[f'TikZRefinery-{version}-linux-image.tar.gz']
|
||||
with tarfile.open(folder / f'TikZRefinery-{version}-linux-image.tar.gz', 'r:gz') as archive:
|
||||
compatibility = json.load(archive.extractfile('manifest.json'))[0]
|
||||
assert record['application_image'] in compatibility['RepoTags']
|
||||
@@ -34,6 +47,25 @@ with tarfile.open(folder / f'TikZRefinery-{version}-linux-image.tar.gz', 'r:gz')
|
||||
assert members[name].isfile(), name
|
||||
with archive.extractfile(name) as stream:
|
||||
assert 'sha256:' + hashlib.file_digest(stream, 'sha256').hexdigest() == reference['digest'], name
|
||||
if 'source_verification' in record:
|
||||
# application.Dockerfile's final filesystem layer is the complete bundle COPY.
|
||||
# Check actual packaged metadata without extracting files onto the workstation.
|
||||
with tarfile.open(fileobj=archive.extractfile(blob_name(manifest['layers'][-1]['digest'])), mode='r:*') as bundle:
|
||||
def bundled_bytes(name):
|
||||
member = bundle.getmember('opt/tikzrefinery/' + name)
|
||||
assert member.isfile(), name
|
||||
return bundle.extractfile(member).read()
|
||||
assert hashlib.sha256(bundled_bytes('upstream-snapshot.json')).hexdigest() == BASELINE_SHA256
|
||||
packaged_record = strict_json(bundled_bytes('delivery-info.json'))
|
||||
assert packaged_record == {key: value for key, value in record.items()
|
||||
if key not in {'application_image', 'application_image_id', 'image_archive_sha256'}}
|
||||
proof = record['source_verification']
|
||||
if proof['source_change_record'] is not None:
|
||||
change_bytes = bundled_bytes('source-change.json')
|
||||
assert hashlib.sha256(change_bytes).hexdigest() == proof['source_change_sha256']
|
||||
assert strict_json(change_bytes) == proof['source_change_record']
|
||||
else:
|
||||
assert 'opt/tikzrefinery/source-change.json' not in bundle.getnames()
|
||||
with zipfile.ZipFile(folder / f'TikZRefinery-{version}-architecture.zip') as docs:
|
||||
assert 'html/index.html' in docs.namelist()
|
||||
print(f'PASS: version {version}, artifact checksums, OCI manifest/config/{len(manifest["layers"])} layers and architecture ZIP')
|
||||
|
||||
Reference in New Issue
Block a user