File size: 1,605 Bytes
0e239c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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()