Skip to content

Commit

Permalink
Apply the fix from #853 to ResolvedKeychain (#862)
Browse files Browse the repository at this point in the history
Signed-off-by: Natalie Arellano <narellano@vmware.com>
  • Loading branch information
natalieparellano authored May 27, 2022
1 parent 1a76076 commit f1d9458
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
3 changes: 3 additions & 0 deletions auth/keychain.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ func buildAuthConfigs(keychain authn.Keychain, images ...string) map[string]*aut
if err != nil {
continue
}
if *authConfig == (authn.AuthConfig{}) {
continue
}
registryAuths[reference.Context().Registry.Name()] = authConfig
}
return registryAuths
Expand Down
18 changes: 10 additions & 8 deletions auth/keychain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestEnvKeychain(t *testing.T) {
}

func testEnvKeychain(t *testing.T, when spec.G, it spec.S) {
when("NewEnvKeychain", func() {
when("#NewEnvKeychain", func() {
when("environment variable is set", func() {
when("valid", func() {
it.Before(func() {
Expand Down Expand Up @@ -164,7 +164,7 @@ func testEnvKeychain(t *testing.T, when spec.G, it spec.S) {
})
})

when("empty", func() {
when("auth header is empty", func() {
it.Before(func() {
envKeychain = auth.EnvKeychain{AuthHeaders: map[string]string{}}
})
Expand All @@ -185,7 +185,7 @@ func testEnvKeychain(t *testing.T, when spec.G, it spec.S) {
})
})

when("NewResolvedKeychain", func() {
when("#NewResolvedKeychain", func() {
it("returns a resolved keychain from the provided keychain", func() {
keychain := &FakeKeychain{
authMap: map[string]*authn.AuthConfig{
Expand All @@ -202,6 +202,7 @@ func testEnvKeychain(t *testing.T, when spec.G, it spec.S) {
"oauth.registry.io": {
IdentityToken: "hjkl=",
},
"empty-auth.registry.io": {},
},
}

Expand All @@ -213,6 +214,7 @@ func testEnvKeychain(t *testing.T, when spec.G, it spec.S) {
"other-registry.com/image",
"my/image", // index.docker.io
"oauth.registry.io/image",
"empty-auth.registry.io/image",
)

h.AssertEq(t, resolvedKeychain, &auth.ResolvedKeychain{
Expand Down Expand Up @@ -292,7 +294,7 @@ func testEnvKeychain(t *testing.T, when spec.G, it spec.S) {
}
})

when("auth header is found", func() {
when("auth config is found", func() {
it("loads the basic auth from memory", func() {
registry, err := name.NewRegistry("basic-registry.com", name.WeakValidation)
h.AssertNil(t, err)
Expand Down Expand Up @@ -348,7 +350,7 @@ func testEnvKeychain(t *testing.T, when spec.G, it spec.S) {
})
})

when("empty", func() {
when("keychain is empty", func() {
it.Before(func() {
resolvedKeychain = auth.ResolvedKeychain{AuthConfigs: map[string]*authn.AuthConfig{}}
})
Expand Down Expand Up @@ -385,7 +387,7 @@ func testEnvKeychain(t *testing.T, when spec.G, it spec.S) {
"index.docker.io": {
RegistryToken: "qwerty=",
},
"missing.auth.config": {},
"empty-auth.registry.io": {},
"oauth.registry.io": {
IdentityToken: "hjkl=",
},
Expand Down Expand Up @@ -422,9 +424,9 @@ func testEnvKeychain(t *testing.T, when spec.G, it spec.S) {
})
})

when("registry is missing auth config", func() {
when("auth config is empty", func() {
it("returns an empty result", func() {
envVar, err := auth.BuildEnvVar(keychain, "missing.auth.config/some/image")
envVar, err := auth.BuildEnvVar(keychain, "empty-auth.registry.io/some/image")
h.AssertNil(t, err)

h.AssertEq(t, envVar, "{}")
Expand Down

0 comments on commit f1d9458

Please sign in to comment.