fix(cd): 核验容器引擎使用的镜像清单摘要
build / build (push) Successful in 1m53s

This commit is contained in:
姚章浩
2026-11-23 21:46:03 +08:00
parent 03e622e9c7
commit 868924d074
2 changed files with 60 additions and 8 deletions
+24
View File
@@ -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'):