3 // TODO: Support Solaris
10 "github.com/docker/docker/api/types"
11 registrytypes "github.com/docker/docker/api/types/registry"
14 func buildAuthConfigs() map[string]types.AuthConfig {
15 authConfigs := map[string]types.AuthConfig{}
17 for _, registry := range []string{"testIndex", IndexServer} {
18 authConfigs[registry] = types.AuthConfig{
19 Username: "docker-user",
20 Password: "docker-pass",
27 func TestSameAuthDataPostSave(t *testing.T) {
28 authConfigs := buildAuthConfigs()
29 authConfig := authConfigs["testIndex"]
30 if authConfig.Username != "docker-user" {
33 if authConfig.Password != "docker-pass" {
36 if authConfig.Auth != "" {
41 func TestResolveAuthConfigIndexServer(t *testing.T) {
42 authConfigs := buildAuthConfigs()
43 indexConfig := authConfigs[IndexServer]
45 officialIndex := ®istrytypes.IndexInfo{
48 privateIndex := ®istrytypes.IndexInfo{
52 resolved := ResolveAuthConfig(authConfigs, officialIndex)
53 assertEqual(t, resolved, indexConfig, "Expected ResolveAuthConfig to return IndexServer")
55 resolved = ResolveAuthConfig(authConfigs, privateIndex)
56 assertNotEqual(t, resolved, indexConfig, "Expected ResolveAuthConfig to not return IndexServer")
59 func TestResolveAuthConfigFullURL(t *testing.T) {
60 authConfigs := buildAuthConfigs()
62 registryAuth := types.AuthConfig{
66 localAuth := types.AuthConfig{
70 officialAuth := types.AuthConfig{
74 authConfigs[IndexServer] = officialAuth
76 expectedAuths := map[string]types.AuthConfig{
77 "registry.example.com": registryAuth,
78 "localhost:8000": localAuth,
79 "registry.com": localAuth,
82 validRegistries := map[string][]string{
83 "registry.example.com": {
84 "https://registry.example.com/v1/",
85 "http://registry.example.com/v1/",
86 "registry.example.com",
87 "registry.example.com/v1/",
90 "https://localhost:8000/v1/",
91 "http://localhost:8000/v1/",
96 "https://registry.com/v1/",
97 "http://registry.com/v1/",
103 for configKey, registries := range validRegistries {
104 configured, ok := expectedAuths[configKey]
108 index := ®istrytypes.IndexInfo{
111 for _, registry := range registries {
112 authConfigs[registry] = configured
113 resolved := ResolveAuthConfig(authConfigs, index)
114 if resolved.Username != configured.Username || resolved.Password != configured.Password {
115 t.Errorf("%s -> %v != %v\n", registry, resolved, configured)
117 delete(authConfigs, registry)
118 resolved = ResolveAuthConfig(authConfigs, index)
119 if resolved.Username == configured.Username || resolved.Password == configured.Password {
120 t.Errorf("%s -> %v == %v\n", registry, resolved, configured)