@@ -31,26 +31,80 @@ func TestPublishChecks(t *testing.T) {
3131 t .Run ("publish error environment" , func (t * testing.T ) {
3232 res := c .RunDockerComposeCmdNoCheck (t , "-f" , "./fixtures/publish/compose-environment.yml" ,
3333 "-p" , projectName , "alpha" , "publish" , "test/test" )
34- res .Assert (t , icmd.Expected {ExitCode : 1 , Err : `service "serviceA" has environment variable(s) declared. To avoid leaking sensitive data,` })
34+ res .Assert (t , icmd.Expected {ExitCode : 1 , Err : `service "serviceA" has environment variable(s) declared.
35+ To avoid leaking sensitive data,` })
3536 })
3637
3738 t .Run ("publish error env_file" , func (t * testing.T ) {
3839 res := c .RunDockerComposeCmdNoCheck (t , "-f" , "./fixtures/publish/compose-env-file.yml" ,
3940 "-p" , projectName , "alpha" , "publish" , "test/test" )
40- res .Assert (t , icmd.Expected {ExitCode : 1 , Err : `service "serviceA" has env_file declared. To avoid leaking sensitive data,` })
41+ res .Assert (t , icmd.Expected {ExitCode : 1 , Err : `service "serviceA" has env_file declared.
42+ service "serviceA" has environment variable(s) declared.
43+ To avoid leaking sensitive data,` })
44+ })
45+
46+ t .Run ("publish multiple errors env_file and environment" , func (t * testing.T ) {
47+ res := c .RunDockerComposeCmdNoCheck (t , "-f" , "./fixtures/publish/compose-multi-env-config.yml" ,
48+ "-p" , projectName , "alpha" , "publish" , "test/test" )
49+ // we don't in which order the services will be loaded, so we can't predict the order of the error messages
50+ assert .Assert (t , strings .Contains (res .Combined (), `service "serviceB" has env_file declared.` ), res .Combined ())
51+ assert .Assert (t , strings .Contains (res .Combined (), `service "serviceB" has environment variable(s) declared.` ), res .Combined ())
52+ assert .Assert (t , strings .Contains (res .Combined (), `service "serviceA" has environment variable(s) declared.` ), res .Combined ())
53+ assert .Assert (t , strings .Contains (res .Combined (), `To avoid leaking sensitive data, you must either explicitly allow the sending of environment variables by using the --with-env flag,
54+ or remove sensitive data from your Compose configuration
55+ ` ), res .Combined ())
4156 })
4257
4358 t .Run ("publish success environment" , func (t * testing.T ) {
4459 res := c .RunDockerComposeCmd (t , "-f" , "./fixtures/publish/compose-environment.yml" ,
45- "-p" , projectName , "alpha" , "publish" , "test/test" , "--with-env" , "--dry-run" )
60+ "-p" , projectName , "alpha" , "publish" , "test/test" , "--with-env" , "-y" , "- -dry-run" )
4661 assert .Assert (t , strings .Contains (res .Combined (), "test/test publishing" ), res .Combined ())
4762 assert .Assert (t , strings .Contains (res .Combined (), "test/test published" ), res .Combined ())
4863 })
4964
5065 t .Run ("publish success env_file" , func (t * testing.T ) {
5166 res := c .RunDockerComposeCmd (t , "-f" , "./fixtures/publish/compose-env-file.yml" ,
67+ "-p" , projectName , "alpha" , "publish" , "test/test" , "--with-env" , "-y" , "--dry-run" )
68+ assert .Assert (t , strings .Contains (res .Combined (), "test/test publishing" ), res .Combined ())
69+ assert .Assert (t , strings .Contains (res .Combined (), "test/test published" ), res .Combined ())
70+ })
71+
72+ t .Run ("publish approve validation message" , func (t * testing.T ) {
73+ cmd := c .NewDockerComposeCmd (t , "-f" , "./fixtures/publish/compose-env-file.yml" ,
5274 "-p" , projectName , "alpha" , "publish" , "test/test" , "--with-env" , "--dry-run" )
75+ cmd .Stdin = strings .NewReader ("y\n " )
76+ res := icmd .RunCmd (cmd )
77+ res .Assert (t , icmd.Expected {ExitCode : 0 })
78+ assert .Assert (t , strings .Contains (res .Combined (), "Are you ok to publish these environment variables? [y/N]:" ), res .Combined ())
5379 assert .Assert (t , strings .Contains (res .Combined (), "test/test publishing" ), res .Combined ())
5480 assert .Assert (t , strings .Contains (res .Combined (), "test/test published" ), res .Combined ())
5581 })
82+
83+ t .Run ("publish refuse validation message" , func (t * testing.T ) {
84+ cmd := c .NewDockerComposeCmd (t , "-f" , "./fixtures/publish/compose-env-file.yml" ,
85+ "-p" , projectName , "alpha" , "publish" , "test/test" , "--with-env" , "--dry-run" )
86+ cmd .Stdin = strings .NewReader ("n\n " )
87+ res := icmd .RunCmd (cmd )
88+ res .Assert (t , icmd.Expected {ExitCode : 0 })
89+ assert .Assert (t , strings .Contains (res .Combined (), "Are you ok to publish these environment variables? [y/N]:" ), res .Combined ())
90+ assert .Assert (t , ! strings .Contains (res .Combined (), "test/test publishing" ), res .Combined ())
91+ assert .Assert (t , ! strings .Contains (res .Combined (), "test/test published" ), res .Combined ())
92+ })
93+
94+ t .Run ("publish list env variables" , func (t * testing.T ) {
95+ cmd := c .NewDockerComposeCmd (t , "-f" , "./fixtures/publish/compose-multi-env-config.yml" ,
96+ "-p" , projectName , "alpha" , "publish" , "test/test" , "--with-env" , "--dry-run" )
97+ cmd .Stdin = strings .NewReader ("n\n " )
98+ res := icmd .RunCmd (cmd )
99+ res .Assert (t , icmd.Expected {ExitCode : 0 })
100+ assert .Assert (t , strings .Contains (res .Combined (), `you are about to publish environment variables within your OCI artifact.
101+ please double check that you are not leaking sensitive data` ), res .Combined ())
102+ assert .Assert (t , strings .Contains (res .Combined (), `Service/Config serviceA
103+ FOO=bar` ), res .Combined ())
104+ assert .Assert (t , strings .Contains (res .Combined (), `Service/Config serviceB` ), res .Combined ())
105+ // we don't know in which order the env variables will be loaded
106+ assert .Assert (t , strings .Contains (res .Combined (), `FOO=bar` ), res .Combined ())
107+ assert .Assert (t , strings .Contains (res .Combined (), `BAR=baz` ), res .Combined ())
108+ assert .Assert (t , strings .Contains (res .Combined (), `QUIX=` ), res .Combined ())
109+ })
56110}
0 commit comments