import unittest from reusable_support.image_identity import validate_image class IdentityTests(unittest.TestCase): def setUp(self): self.expected = {'config_digest': 'sha256:' + '1'*64, 'registry_digest': 'sha256:' + '2'*64, 'amd64_manifest_digest': 'sha256:' + '3'*64} def test_classic_config_identity(self): self.assertTrue(validate_image({'Id': self.expected['config_digest'], 'Os':'linux', 'Architecture':'amd64'}, self.expected)) def test_containerd_manifest_identity(self): info={'Id':self.expected['registry_digest'], 'Os':'linux', 'Architecture':'amd64', 'Descriptor':{'digest':self.expected['registry_digest'], 'annotations':{'config.digest':self.expected['config_digest']}}} self.assertTrue(validate_image(info,self.expected)) def test_wrong_config_annotation_rejected(self): info={'Id':self.expected['registry_digest'], 'Os':'linux', 'Architecture':'amd64', 'Descriptor':{'digest':self.expected['registry_digest'], 'annotations':{'config.digest':'sha256:'+'4'*64}}} with self.assertRaises(ValueError): validate_image(info,self.expected) def test_other_image_rejected(self): with self.assertRaises(ValueError): validate_image({'Id':'sha256:'+'4'*64,'Os':'linux','Architecture':'amd64'},self.expected) def test_wrong_platform_rejected(self): with self.assertRaises(ValueError): validate_image({'Id':self.expected['config_digest'],'Os':'linux','Architecture':'arm64'},self.expected) if __name__=='__main__':unittest.main()