mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #1990 from modcloth-labs/more-tests-for-auth-registry-resolution
Adding more tests around `auth.ResolveAuthConfig`
This commit is contained in:
commit
826aaa0e9b
1 changed files with 83 additions and 7 deletions
|
@ -75,20 +75,31 @@ func TestCreateAccount(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSameAuthDataPostSave(t *testing.T) {
|
func setupTempConfigFile() (*ConfigFile, error) {
|
||||||
root, err := ioutil.TempDir("", "docker-test")
|
root, err := ioutil.TempDir("", "docker-test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
return nil, err
|
||||||
}
|
}
|
||||||
configFile := &ConfigFile{
|
configFile := &ConfigFile{
|
||||||
rootPath: root,
|
rootPath: root,
|
||||||
Configs: make(map[string]AuthConfig, 1),
|
Configs: make(map[string]AuthConfig),
|
||||||
}
|
}
|
||||||
|
|
||||||
configFile.Configs["testIndex"] = AuthConfig{
|
for _, registry := range []string{"testIndex", IndexServerAddress()} {
|
||||||
Username: "docker-user",
|
configFile.Configs[registry] = AuthConfig{
|
||||||
Password: "docker-pass",
|
Username: "docker-user",
|
||||||
Email: "docker@docker.io",
|
Password: "docker-pass",
|
||||||
|
Email: "docker@docker.io",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return configFile, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSameAuthDataPostSave(t *testing.T) {
|
||||||
|
configFile, err := setupTempConfigFile()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = SaveConfig(configFile)
|
err = SaveConfig(configFile)
|
||||||
|
@ -110,3 +121,68 @@ func TestSameAuthDataPostSave(t *testing.T) {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestResolveAuthConfigIndexServer(t *testing.T) {
|
||||||
|
configFile, err := setupTempConfigFile()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, registry := range []string{"", IndexServerAddress()} {
|
||||||
|
resolved := configFile.ResolveAuthConfig(registry)
|
||||||
|
if resolved != configFile.Configs[IndexServerAddress()] {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestResolveAuthConfigFullURL(t *testing.T) {
|
||||||
|
configFile, err := setupTempConfigFile()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
registryAuth := AuthConfig{
|
||||||
|
Username: "foo-user",
|
||||||
|
Password: "foo-pass",
|
||||||
|
Email: "foo@example.com",
|
||||||
|
}
|
||||||
|
localAuth := AuthConfig{
|
||||||
|
Username: "bar-user",
|
||||||
|
Password: "bar-pass",
|
||||||
|
Email: "bar@example.com",
|
||||||
|
}
|
||||||
|
configFile.Configs["https://registry.example.com/v1/"] = registryAuth
|
||||||
|
configFile.Configs["http://localhost:8000/v1/"] = localAuth
|
||||||
|
|
||||||
|
validRegistries := map[string][]string{
|
||||||
|
"https://registry.example.com/v1/": {
|
||||||
|
"https://registry.example.com/v1/",
|
||||||
|
"http://registry.example.com/v1/",
|
||||||
|
"registry.example.com",
|
||||||
|
"registry.example.com/v1/",
|
||||||
|
},
|
||||||
|
"http://localhost:8000/v1/": {
|
||||||
|
"https://localhost:8000/v1/",
|
||||||
|
"http://localhost:8000/v1/",
|
||||||
|
"localhost:8000",
|
||||||
|
"localhost:8000/v1/",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for configKey, registries := range validRegistries {
|
||||||
|
for _, registry := range registries {
|
||||||
|
var (
|
||||||
|
configured AuthConfig
|
||||||
|
ok bool
|
||||||
|
)
|
||||||
|
resolved := configFile.ResolveAuthConfig(registry)
|
||||||
|
if configured, ok = configFile.Configs[configKey]; !ok {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
if resolved.Email != configured.Email {
|
||||||
|
t.Errorf("%s -> %q != %q\n", registry, resolved.Email, configured.Email)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue