Skip to content

Commit 86ef8b2

Browse files
authored
Merge pull request #709 from devanshuVmware/skip-no-auth-merge
Skip merging docker config with no auth data
2 parents 56b1e44 + 7c63dda commit 86ef8b2

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

pkg/sharing/dockerconfigjson.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ func NewCombinedDockerConfigJSON(secrets []*corev1.Secret) (map[string][]byte, e
4343

4444
// TODO should we have more complex merging here?
4545
for server, auth := range auths.Auths {
46+
// Skip entries that have no auth data
47+
if auth.Username == "" && auth.Password == "" && auth.Auth == "" {
48+
continue
49+
}
4650
combined.Auths[server] = auth
4751
}
4852
}

pkg/sharing/dockerconfigjson_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,28 @@ func Test_NewCombinedDockerConfigJSON(t *testing.T) {
6363
assert.Equal(t, 1, len(result))
6464
assert.Equal(t, expected, result[corev1.DockerConfigJsonKey])
6565
})
66+
67+
t.Run("skips entries with no auth data", func(t *testing.T) {
68+
// Secret with 1 valid and 1 empty auths
69+
secrets := []*corev1.Secret{
70+
&corev1.Secret{
71+
Data: map[string][]byte{
72+
corev1.DockerConfigJsonKey: []byte(`{"auths":{"valid-server1":{"username":"user1","password":"pass1","auth":"auth1"},"empty-server1":{"username":"","password":"","auth":""}}}`),
73+
},
74+
},
75+
// Another Secret with 1 valid and 1 empty auths
76+
&corev1.Secret{
77+
Data: map[string][]byte{
78+
corev1.DockerConfigJsonKey: []byte(`{"auths":{"valid-server2":{"username":"user2","password":"pass2","auth":"auth2"},"empty-server2":{"username":"","password":"","auth":""}}}`),
79+
},
80+
},
81+
}
82+
result, err := NewCombinedDockerConfigJSON(secrets)
83+
require.NoError(t, err)
84+
85+
// Expected result should have only the valid auths
86+
expected := []byte(`{"auths":{"valid-server1":{"username":"user1","password":"pass1","auth":"auth1"},"valid-server2":{"username":"user2","password":"pass2","auth":"auth2"}}}`)
87+
assert.Equal(t, 1, len(result))
88+
assert.Equal(t, expected, result[corev1.DockerConfigJsonKey])
89+
})
6690
}

0 commit comments

Comments
 (0)