-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Normalize auth key before calling SetAuthentication
#11430
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package auth | ||
|
||
import ( | ||
"io/ioutil" | ||
"testing" | ||
|
||
"github.com/containers/image/v5/types" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAuthConfigsToAuthFile(t *testing.T) { | ||
for _, tc := range []struct { | ||
name string | ||
server string | ||
shouldErr bool | ||
expectedContains string | ||
}{ | ||
{ | ||
name: "empty auth configs", | ||
server: "", | ||
shouldErr: false, | ||
expectedContains: "{}", | ||
}, | ||
{ | ||
name: "registry with prefix", | ||
server: "my-registry.local/username", | ||
shouldErr: false, | ||
expectedContains: `"my-registry.local/username":`, | ||
}, | ||
{ | ||
name: "normalize https:// prefix", | ||
server: "http://my-registry.local/username", | ||
shouldErr: false, | ||
expectedContains: `"my-registry.local/username":`, | ||
}, | ||
{ | ||
name: "normalize docker registry with https prefix", | ||
server: "http://index.docker.io/v1/", | ||
shouldErr: false, | ||
expectedContains: `"index.docker.io":`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’d expect the key to be |
||
}, | ||
{ | ||
name: "normalize docker registry without https prefix", | ||
server: "docker.io/v2/", | ||
shouldErr: false, | ||
expectedContains: `"docker.io":`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be |
||
}, | ||
} { | ||
configs := map[string]types.DockerAuthConfig{} | ||
if tc.server != "" { | ||
configs[tc.server] = types.DockerAuthConfig{} | ||
} | ||
|
||
filePath, err := authConfigsToAuthFile(configs) | ||
|
||
if tc.shouldErr { | ||
assert.NotNil(t, err) | ||
assert.Empty(t, filePath) | ||
} else { | ||
assert.Nil(t, err) | ||
content, err := ioutil.ReadFile(filePath) | ||
assert.Nil(t, err) | ||
assert.Contains(t, string(content), tc.expectedContains) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is inconsistent with https://github.com/containers/image/blob/4fcb52359b759a276a760fb28c939c357b3aea48/pkg/docker/config/config_test.go#L938 .