@@ -51,6 +51,30 @@ class ProductionCD(unittest.TestCase):
|
||||
self.host.switch.assert_not_called()
|
||||
self.host.callback.assert_not_called()
|
||||
|
||||
def test_archive_binds_engine_descriptor_to_approved_config(self):
|
||||
import io
|
||||
import tarfile
|
||||
config = b'{"architecture":"amd64"}'
|
||||
digest = lambda raw: 'sha256:' + hashlib.sha256(raw).hexdigest()
|
||||
expected = digest(config)
|
||||
for target in (expected, 'sha256:' + '0' * 64):
|
||||
blob = json.dumps({'schemaVersion': 2, 'config': {'digest': target}}).encode()
|
||||
manifest_id = digest(blob)
|
||||
archive = self.root / 'identity.tar'
|
||||
files = {'manifest.json': json.dumps([{'Config': 'config.json'}]).encode(), 'config.json': config,
|
||||
'index.json': json.dumps({'manifests': [{'digest': manifest_id}]}).encode(),
|
||||
'blobs/sha256/' + manifest_id[7:]: blob}
|
||||
with tarfile.open(archive, 'w') as tar:
|
||||
for name, raw in files.items():
|
||||
entry = tarfile.TarInfo(name)
|
||||
entry.size = len(raw)
|
||||
tar.addfile(entry, io.BytesIO(raw))
|
||||
if target == expected:
|
||||
self.assertEqual(cd.verify_archive(archive, expected), manifest_id)
|
||||
else:
|
||||
with self.assertRaisesRegex(cd.CDError, 'config digest'):
|
||||
cd.verify_archive(archive, expected)
|
||||
|
||||
def test_no_confirmation_has_zero_side_effects(self):
|
||||
self.request['confirm'] = ''
|
||||
with self.assertRaisesRegex(cd.CDError, 'confirmation'):
|
||||
|
||||
Reference in New Issue
Block a user