Skip to content

Commit

Permalink
fix: parse registry credentials when the auth property is blank (#859)
Browse files Browse the repository at this point in the history
Resolves: #855
Resolves: #857

Signed-off-by: Daniel Pacak <pacak.daniel@gmail.com>
  • Loading branch information
danielpacak committed Dec 17, 2021
1 parent 85723da commit 7687ef9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
10 changes: 9 additions & 1 deletion pkg/docker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,15 @@ func (c *Config) Read(contents []byte) error {
func decodeAuths(auths map[string]Auth) (map[string]Auth, error) {
decodedAuths := make(map[string]Auth)
for server, entry := range auths {
if (Auth{}) == entry {
if entry == (Auth{}) {
continue
}

if strings.TrimSpace(string(entry.Auth)) == "" {
decodedAuths[server] = Auth{
Username: entry.Username,
Password: entry.Password,
}
continue
}

Expand Down
41 changes: 33 additions & 8 deletions pkg/docker/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,53 @@ func TestConfig_Read(t *testing.T) {
expectedError: errors.New("unexpected end of JSON input"),
},
{
name: "Should return server credentials with encoded username and password",
name: "Should return server credentials stored as username and password encoded in the auth property",
givenJSON: `{
"auths": {
"https://index.docker.io/v1/": {
"auth": "ZG9ja2VyOmh1Yg=="
},
"harbor.domain": {
"auth": "YWRtaW46SGFyYm9yMTIzNDU="
"auths": {
"https://index.docker.io/v1/": {
"auth": "ZG9ja2VyOmh1Yg=="
},
"harbor.domain": {
"auth": "YWRtaW46SGFyYm9yMTIzNDU="
}
}
}
}`,
expectedAuth: map[string]docker.Auth{
"https://index.docker.io/v1/": {
Auth: "ZG9ja2VyOmh1Yg==",
Username: "docker",
Password: "hub",
},
"harbor.domain": {
Auth: "YWRtaW46SGFyYm9yMTIzNDU=",
Username: "admin",
Password: "Harbor12345",
},
},
},
{
name: "Should return server credentials stored in username and password properties",
givenJSON: `{
"auths": {
"https://index.docker.io/v1/": {
"auth": "ZG9ja2VyOmh1Yg=="
},
"harbor.domain": {
"username": "admin",
"password": "Harbor12345"
}
}
}`,
expectedAuth: map[string]docker.Auth{
"https://index.docker.io/v1/": {
Auth: "ZG9ja2VyOmh1Yg==",
Username: "docker",
Password: "hub",
},
"harbor.domain": {
Username: "admin",
Password: "Harbor12345",
},
},
},
{
Expand Down

0 comments on commit 7687ef9

Please sign in to comment.