@@ -15,15 +15,15 @@ tap.test('getUniqueImages()', async (t) => {
1515 imageName : 'redis:latest' ,
1616 imageId : 'docker.io/library/redis@sha256:8e9f8546050da8aae393a41d65ad37166b4f0d8131d627a520c0f0451742e9d6'
1717 } ,
18- // 3. Duplicate without tag
18+ // 3. With SHA instead of tag
1919 {
20- imageName : 'redis' ,
20+ imageName : 'redis@sha256:8e9f8546050da8aae393a41d65ad37166b4f0d8131d627a520c0f0451742e9d6 ' ,
2121 imageId : 'docker.io/library/redis@sha256:8e9f8546050da8aae393a41d65ad37166b4f0d8131d627a520c0f0451742e9d6'
2222 } ,
23- // 4. Duplicate with SHA instead of tag
23+ // 4. With SHA missing in imageId
2424 {
25- imageName : 'redis@sha256:8e9f8546050da8aae393a41d65ad37166b4f0d8131d627a520c0f0451742e9d6 ' ,
26- imageId : 'docker.io/library/redis@sha256:8e9f8546050da8aae393a41d65ad37166b4f0d8131d627a520c0f0451742e9d6'
25+ imageName : 'redis:prod ' ,
26+ imageId : 'docker.io/library/redis:eaa6f054e4a140bc3a1696cc7b1e84529e7e9567' ,
2727 } ,
2828 // 5. GCR
2929 {
@@ -35,21 +35,42 @@ tap.test('getUniqueImages()', async (t) => {
3535 imageName : '291964488713.dkr.ecr.us-east-2.amazonaws.com/snyk/redis:latest' ,
3636 imageId : 'sha256:8e9f8546050da8aae393a41d65ad37166b4f0d8131d627a520c0f0451742e9d6'
3737 } ,
38+ // 7. With docker-pullable as protocol in imageId
39+ {
40+ imageName : 'redis:some-tag' ,
41+ imageId : 'docker-pullable://name@sha256:8e9f8546050da8aae393a41d65ad37166b4f0d8131d627a520c0f0451742e9d6' ,
42+ } ,
43+ // 8. With docker as protocol in imageId
44+ {
45+ imageName : 'redis:another-tag' ,
46+ imageId : 'docker://name@sha256:8e9f8546050da8aae393a41d65ad37166b4f0d8131d627a520c0f0451742e9d6'
47+ }
3848 ] ;
3949
4050 const result = scanner . getUniqueImages ( workload as any ) ;
4151
42- t . strictEqual ( result . length , 3 , 'removed duplicate image' ) ;
43- result . map ( ( metaData ) => {
44- t . ok ( metaData . imageWithDigest . includes ( 'redis' ) , 'has name in imageWithDigest' ) ;
45- t . ok ( metaData . imageWithDigest . includes ( 'sha256:8e9f8546050da8aae393a41d65ad37166b4f0d8131d627a520c0f0451742e9d6' ) , 'has digest' ) ;
52+ t . strictEqual ( result . length , 7 , 'removed duplicate image' ) ;
53+ const resultWithDigest = result . filter ( ( { imageWithDigest} ) => imageWithDigest ) ;
54+ const resultWithoutDigest = result . filter ( ( { imageWithDigest} ) => ! imageWithDigest ) ;
55+
56+ t . strictEqual ( resultWithDigest . length , 6 , 'correct amount with digest' ) ;
57+ t . strictEqual ( resultWithoutDigest . length , 1 , 'correct amount without digest' ) ;
58+
59+ resultWithDigest . map ( ( metaData ) => {
60+ t . ok ( metaData . imageWithDigest ! . includes ( 'redis' ) , 'has name in imageWithDigest' ) ;
61+ t . ok ( metaData . imageWithDigest ! . includes ( 'sha256:8e9f8546050da8aae393a41d65ad37166b4f0d8131d627a520c0f0451742e9d6' ) , 'has digest' ) ;
4662
47- if ( metaData . imageWithDigest . includes ( 'gcr' ) ) {
48- t . ok ( metaData . imageWithDigest . includes ( '/' ) , 'contains / in GCR imageWithDigest' ) ;
63+ if ( metaData . imageWithDigest ! . includes ( 'gcr' ) ) {
64+ t . ok ( metaData . imageWithDigest ! . includes ( '/' ) , 'contains / in GCR imageWithDigest' ) ;
4965 }
5066
51- if ( metaData . imageWithDigest . includes ( 'ecr' ) ) {
52- t . ok ( metaData . imageWithDigest . includes ( '/' ) , 'contains / in ECR imageWithDigest' ) ;
67+ if ( metaData . imageWithDigest ! . includes ( 'ecr' ) ) {
68+ t . ok ( metaData . imageWithDigest ! . includes ( '/' ) , 'contains / in ECR imageWithDigest' ) ;
5369 }
5470 } ) ;
71+
72+ resultWithoutDigest . map ( ( metadata ) => {
73+ t . ok ( metadata . imageName . includes ( 'redis' ) ) ;
74+ t . notOk ( metadata . imageWithDigest ) ;
75+ } ) ;
5576} ) ;
0 commit comments