@@ -56,29 +56,39 @@ tap.test('constructStaticAnalysisOptions() tests', async (t) => {
5656 t . deepEqual ( options , expectedResult , 'returned options match expectations' ) ;
5757} ) ;
5858
59- tap . test ( 'getImageTag() tests' , async ( t ) => {
60- t . plan ( 4 ) ;
59+ tap . test ( 'extracted image tag tests' , async ( t ) => {
60+ t . plan ( 6 ) ;
6161
6262 const imageWithSha = 'nginx@sha256:1234567890abcdef' ;
63- const imageWithShaResult = scannerImages . getImageTag ( imageWithSha ) ;
64- t . same ( imageWithShaResult , '1234567890abcdef' , 'image sha is returned' ) ;
63+ const imageWithShaResult = scannerImages . getImageParts ( imageWithSha ) ;
64+ t . same ( imageWithShaResult . imageTag , '1234567890abcdef' , 'image sha is returned' ) ;
6565
6666 const imageWithTag = 'nginx:latest' ;
67- const imageWithTagResult = scannerImages . getImageTag ( imageWithTag ) ;
68- t . same ( imageWithTagResult , 'latest' , 'image tag is returned' ) ;
67+ const imageWithTagResult = scannerImages . getImageParts ( imageWithTag ) ;
68+ t . same ( imageWithTagResult . imageTag , 'latest' , 'image tag is returned' ) ;
69+
70+ const imageWithFullRepository = 'kind-registry:5000/nginx:latest' ;
71+ const imageWithFullRepositoryResult = scannerImages . getImageParts ( imageWithFullRepository ) ;
72+ t . same ( imageWithFullRepositoryResult . imageTag , 'latest' , 'image tag is returned when full repo specified' ) ;
6973
7074 const imageWithoutTag = 'nginx' ;
71- const imageWithoutTagResult = scannerImages . getImageTag ( imageWithoutTag ) ;
72- t . same ( imageWithoutTagResult , '' , 'empty tag returned when no tag is specified' ) ;
75+ const imageWithoutTagResult = scannerImages . getImageParts ( imageWithoutTag ) ;
76+ t . same ( imageWithoutTagResult . imageTag , '' , 'empty tag returned when no tag is specified' ) ;
7377
7478 const imageWithManySeparators = 'nginx@abc:tag@bad:reallybad' ;
75- const imageWithManySeparatorsResult = scannerImages . getImageTag ( imageWithManySeparators ) ;
76- t . same ( imageWithManySeparatorsResult , '' , 'empty tag is returned on malformed image name and tag' ) ;
79+ const imageWithManySeparatorsResult = scannerImages . getImageParts ( imageWithManySeparators ) ;
80+ t . same ( imageWithManySeparatorsResult . imageTag , '' , 'empty tag is returned on malformed image name and tag' ) ;
81+
82+ const imageWithFullRepoAndManySeparators = 'kind-registry:5000/nginx@abc:tag@bad:reallybad' ;
83+ const imageWithFullRepoAndManySeparatorsResult = scannerImages . getImageParts ( imageWithFullRepoAndManySeparators ) ;
84+ t . same ( imageWithFullRepoAndManySeparatorsResult . imageTag , '' , 'empty tag is returned on malformed image name and tag with full repo' ) ;
7785} ) ;
7886
79- tap . test ( 'removeTagFromImage() tests' , async ( t ) => {
80- t . plan ( 2 ) ;
87+ tap . test ( 'extracted image name tests' , async ( t ) => {
88+ t . plan ( 4 ) ;
8189
82- t . same ( scannerImages . removeTagFromImage ( 'nginx:latest' ) , 'nginx' , 'removed image:tag' ) ;
83- t . same ( scannerImages . removeTagFromImage ( 'nginx:@sha256:1234567890abcdef' ) , 'nginx' , 'removed image@sha:hex' ) ;
90+ t . same ( scannerImages . getImageParts ( 'nginx:latest' ) . imageName , 'nginx' , 'removed image:tag' ) ;
91+ t . same ( scannerImages . getImageParts ( 'nginx:@sha256:1234567890abcdef' ) . imageName , 'nginx' , 'removed malformed image:@sha:hex' ) ;
92+ t . same ( scannerImages . getImageParts ( 'node@sha256:215a9fbef4df2c1ceb7c79481d3cfd94ad8f1f0105bade39f3be907bf386c5e1' ) . imageName , 'node' , 'removed image@sha:hex' ) ;
93+ t . same ( scannerImages . getImageParts ( 'kind-registry:5000/python:rc-buster' ) . imageName , 'kind-registry:5000/python' , 'removed repository/image:tag' ) ;
8494} ) ;
0 commit comments