Skip to content

Commit

Permalink
Merge pull request #1318 from mtrmac/normalize-tests
Browse files Browse the repository at this point in the history
Simplify credential normalization, fix tests
  • Loading branch information
vrothberg authored Jul 28, 2021
2 parents 91e9af4 + f429107 commit a4c7ee7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
11 changes: 4 additions & 7 deletions pkg/docker/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,14 +664,11 @@ func findAuthentication(ref reference.Named, registry, path string, legacyFormat
// those entries even in non-legacyFormat ~/.docker/config.json.
// The docker.io registry still uses the /v1/ key with a special host name,
// so account for that as well.
registry = normalizeAuthFileKey(registry, legacyFormat)
normalizedAuths := map[string]dockerAuthConfig{}
registry = normalizeRegistry(registry)
for k, v := range auths.AuthConfigs {
normalizedAuths[normalizeAuthFileKey(k, legacyFormat)] = v
}

if val, exists := normalizedAuths[registry]; exists {
return decodeDockerAuth(val)
if normalizeAuthFileKey(k, legacyFormat) == registry {
return decodeDockerAuth(v)
}
}

return types.DockerAuthConfig{}, nil
Expand Down
22 changes: 11 additions & 11 deletions pkg/docker/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,17 @@ func TestGetAuth(t *testing.T) {
},
{
name: "normalize registry",
hostname: "https://example.org/v1",
hostname: "normalize.example.org",
path: filepath.Join("testdata", "full.json"),
expected: types.DockerAuthConfig{
Username: "example",
Password: "org",
Username: "normalize",
Password: "example",
},
testPreviousAPI: true,
},
{
name: "match localhost",
hostname: "http://localhost",
hostname: "localhost",
path: filepath.Join("testdata", "full.json"),
expected: types.DockerAuthConfig{
Username: "local",
Expand All @@ -222,7 +222,7 @@ func TestGetAuth(t *testing.T) {
},
{
name: "match port",
hostname: "https://localhost:5000",
hostname: "localhost:5000",
path: filepath.Join("testdata", "abnormal.json"),
expected: types.DockerAuthConfig{
Username: "local",
Expand Down Expand Up @@ -387,16 +387,16 @@ func TestGetAuthFromLegacyFile(t *testing.T) {
expectedError error
}{
{
name: "normalize registry",
hostname: "https://docker.io/v1",
name: "ignore schema and path",
hostname: "localhost",
expected: types.DockerAuthConfig{
Username: "docker",
Password: "io-legacy",
Username: "local",
Password: "host-legacy",
},
},
{
name: "ignore schema and path",
hostname: "http://index.docker.io/v1",
name: "normalize registry",
hostname: "docker.io",
expected: types.DockerAuthConfig{
Username: "docker",
Password: "io-legacy",
Expand Down
3 changes: 3 additions & 0 deletions pkg/docker/config/testdata/full.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
},
"10.10.30.45:5000": {
"auth": "MTAuMTA6MzAuNDUtNTAwMA=="
},
"https://normalize.example.org/v1": {
"auth": "bm9ybWFsaXplOmV4YW1wbGU="
}
}
}
2 changes: 1 addition & 1 deletion pkg/docker/config/testdata/legacy.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"docker.io/v2": {
"http://index.docker.io/v1": {
"auth": "ZG9ja2VyOmlvLWxlZ2FjeQ=="
},
"https://localhost/v1": {
Expand Down

0 comments on commit a4c7ee7

Please sign in to comment.