Skip to content

Commit bfc7cff

Browse files
committed
test: add failing unit tests for registries with a CA
Expect image registries with no credentials but with a CA to still work.
1 parent d978243 commit bfc7cff

File tree

1 file changed

+38
-6
lines changed
  • pkg/handlers/generic/mutation/imageregistries/credentials

1 file changed

+38
-6
lines changed

pkg/handlers/generic/mutation/imageregistries/credentials/inject_test.go

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func Test_needImageRegistryCredentialsConfiguration(t *testing.T) {
4343
wantErr error
4444
}{
4545
{
46-
name: "ECR credentials",
46+
name: "ECR registry with no credentials",
4747
configs: []providerConfig{
4848
{URL: "https://123456789.dkr.ecr.us-east-1.amazonaws.com"},
4949
},
@@ -59,7 +59,7 @@ func Test_needImageRegistryCredentialsConfiguration(t *testing.T) {
5959
need: true,
6060
},
6161
{
62-
name: "ECR mirror",
62+
name: "ECR mirror with no credentials",
6363
configs: []providerConfig{
6464
{
6565
URL: "https://123456789.dkr.ecr.us-east-1.amazonaws.com",
@@ -71,7 +71,7 @@ func Test_needImageRegistryCredentialsConfiguration(t *testing.T) {
7171
{
7272
name: "mirror with static credentials",
7373
configs: []providerConfig{{
74-
URL: "https://myregistry.com",
74+
URL: "https://mymirror.com",
7575
Username: "myuser",
7676
Password: "mypassword",
7777
Mirror: true,
@@ -81,7 +81,7 @@ func Test_needImageRegistryCredentialsConfiguration(t *testing.T) {
8181
{
8282
name: "mirror with no credentials",
8383
configs: []providerConfig{{
84-
URL: "https://myregistry.com",
84+
URL: "https://mymirror.com",
8585
Mirror: true,
8686
}},
8787
need: false,
@@ -93,15 +93,30 @@ func Test_needImageRegistryCredentialsConfiguration(t *testing.T) {
9393
URL: "https://myregistry.com",
9494
Username: "myuser",
9595
Password: "mypassword",
96-
Mirror: true,
96+
Mirror: false,
9797
},
9898
{
99-
URL: "https://myregistry.com",
99+
URL: "https://mymirror.com",
100100
Mirror: true,
101101
},
102102
},
103103
need: true,
104104
},
105+
{
106+
name: "a registry with missing credentials and a mirror with no credentials",
107+
configs: []providerConfig{
108+
{
109+
URL: "https://myregistry.com",
110+
Mirror: false,
111+
},
112+
{
113+
URL: "https://mymirror.com",
114+
Mirror: true,
115+
},
116+
},
117+
need: false,
118+
wantErr: ErrCredentialsNotFound,
119+
},
105120
{
106121
name: "registry with missing credentials",
107122
configs: []providerConfig{{
@@ -110,6 +125,23 @@ func Test_needImageRegistryCredentialsConfiguration(t *testing.T) {
110125
need: false,
111126
wantErr: ErrCredentialsNotFound,
112127
},
128+
{
129+
name: "registry with missing credentials but with a CA",
130+
configs: []providerConfig{{
131+
URL: "https://myregistry.com",
132+
HasCACert: true,
133+
}},
134+
need: false,
135+
},
136+
{
137+
name: "mirror with missing credentials but with a CA",
138+
configs: []providerConfig{{
139+
URL: "https://mymirror.com",
140+
HasCACert: true,
141+
Mirror: true,
142+
}},
143+
need: false,
144+
},
113145
}
114146

115147
for idx := range testCases {

0 commit comments

Comments
 (0)