@@ -30,22 +30,22 @@ describe("mergeEnvVarsIntoCredentials", () => {
3030 ${ FLAG_USER } | ${ ENV_VAR_USER } | ${ FLAG_USER }
3131
3232 ` ( "should set username to $expectedUsername when flag is $usernameFlag and envvar is $usernameEnvVar" ,
33- ( {
34- usernameFlag,
35- usernameEnvVar,
36- expectedUsername,
37- } ) => {
38- if ( usernameEnvVar ) {
39- process . env . SNYK_REGISTRY_USERNAME = usernameEnvVar ;
40- }
41- const options = {
42- username : usernameFlag ,
43- } ;
44-
45- mergeEnvVarsIntoCredentials ( options ) ;
46-
47- expect ( options . username ) . toEqual ( expectedUsername ) ;
48- } ) ;
33+ ( {
34+ usernameFlag,
35+ usernameEnvVar,
36+ expectedUsername,
37+ } ) => {
38+ if ( usernameEnvVar ) {
39+ process . env . SNYK_REGISTRY_USERNAME = usernameEnvVar ;
40+ }
41+ const options = {
42+ username : usernameFlag ,
43+ } ;
44+
45+ mergeEnvVarsIntoCredentials ( options ) ;
46+
47+ expect ( options . username ) . toEqual ( expectedUsername ) ;
48+ } ) ;
4949
5050 // prettier-ignore
5151 it . each `
@@ -59,10 +59,10 @@ describe("mergeEnvVarsIntoCredentials", () => {
5959
6060 ` ( "should set password to $expectedPassword when flag is $passwordFlag and envvar is $passwordEnvVar" ,
6161 ( {
62- passwordFlag,
63- passwordEnvVar,
64- expectedPassword,
65- } ) => {
62+ passwordFlag,
63+ passwordEnvVar,
64+ expectedPassword,
65+ } ) => {
6666 if ( passwordEnvVar ) {
6767 process . env . SNYK_REGISTRY_PASSWORD = passwordEnvVar ;
6868 }
@@ -84,26 +84,66 @@ describe("appendLatestTagIfMissing", () => {
8484 ) ;
8585 } ) ;
8686
87- it ( "does not append latest to docker archive path" , ( ) => {
87+ it ( "does not append latest to oci archive path" , ( ) => {
8888 const ociArchivePath = "oci-archive:some/path/image.tar" ;
8989 expect ( appendLatestTagIfMissing ( ociArchivePath ) ) . toEqual ( ociArchivePath ) ;
9090 } ) ;
9191
92+ it ( "does not append latest to kaniko-archive path" , ( ) => {
93+ const path = "kaniko-archive:some/path/image.tar" ;
94+ expect ( appendLatestTagIfMissing ( path ) ) . toEqual ( path ) ;
95+ } ) ;
96+
97+ it ( "does not append latest to unspecified archive path (.tar)" , ( ) => {
98+ const path = "/tmp/nginx.tar" ;
99+ expect ( appendLatestTagIfMissing ( path ) ) . toEqual ( path ) ;
100+ } ) ;
101+
92102 it ( "does not append latest if tag exists" , ( ) => {
93103 const imageWithTag = "image:sometag" ;
94104 expect ( appendLatestTagIfMissing ( imageWithTag ) ) . toEqual ( imageWithTag ) ;
95105 } ) ;
96106
97- it ( "does not modify targetImage with sha" , ( ) => {
98- const imageWithSha =
99- "snyk container test nginx@sha256:56ea7092e72db3e9f84d58d583370d59b842de02ea9e1f836c3f3afc7ce408c1" ;
100- expect ( appendLatestTagIfMissing ( imageWithSha ) ) . toEqual ( imageWithSha ) ;
107+ it ( "does not append latest if digest exists (digest-only reference)" , ( ) => {
108+ const imageWithDigest =
109+ "nginx@sha256:56ea7092e72db3e9f84d58d583370d59b842de02ea9e1f836c3f3afc7ce408c1" ;
110+ expect ( appendLatestTagIfMissing ( imageWithDigest ) ) . toEqual (
111+ imageWithDigest ,
112+ ) ;
101113 } ) ;
102114
103- it ( "appends latest if no tag exists" , ( ) => {
104- const imageWithoutTag = "image" ;
105- expect ( appendLatestTagIfMissing ( imageWithoutTag ) ) . toEqual (
106- `${ imageWithoutTag } :latest` ,
115+ it ( "does not append latest if both tag and digest exist" , ( ) => {
116+ const imageWithTagAndDigest =
117+ "nginx:1.23@sha256:56ea7092e72db3e9f84d58d583370d59b842de02ea9e1f836c3f3afc7ce408c1" ;
118+ expect ( appendLatestTagIfMissing ( imageWithTagAndDigest ) ) . toEqual (
119+ imageWithTagAndDigest ,
107120 ) ;
108121 } ) ;
109- } ) ;
122+
123+ it ( "appends latest for repository-only reference" , ( ) => {
124+ expect ( appendLatestTagIfMissing ( "image" ) ) . toEqual ( "image:latest" ) ;
125+ } ) ;
126+
127+ it ( "appends latest for repository with namespace" , ( ) => {
128+ expect ( appendLatestTagIfMissing ( "library/nginx" ) ) . toEqual (
129+ "library/nginx:latest" ,
130+ ) ;
131+ } ) ;
132+
133+ it ( "appends latest for registry with port and no tag" , ( ) => {
134+ expect ( appendLatestTagIfMissing ( "localhost:5000/foo/bar" ) ) . toEqual (
135+ "localhost:5000/foo/bar:latest" ,
136+ ) ;
137+ } ) ;
138+
139+ it ( "appends latest for custom registry without tag" , ( ) => {
140+ expect ( appendLatestTagIfMissing ( "gcr.io/project/nginx" ) ) . toEqual (
141+ "gcr.io/project/nginx:latest" ,
142+ ) ;
143+ } ) ;
144+
145+ it ( "returns unchanged for invalid image reference" , ( ) => {
146+ const invalid = "/test:unknown" ;
147+ expect ( appendLatestTagIfMissing ( invalid ) ) . toEqual ( invalid ) ;
148+ } ) ;
149+ } ) ;
0 commit comments