Also make EncodeAuth and DecodeAuth private because they're only used by cliconfig.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
... | ... |
@@ -80,7 +80,7 @@ func (configFile *ConfigFile) LegacyLoadFromReader(configData io.Reader) error { |
80 | 80 |
if len(origAuth) != 2 { |
81 | 81 |
return fmt.Errorf("Invalid Auth config file") |
82 | 82 |
} |
83 |
- authConfig.Username, authConfig.Password, err = DecodeAuth(origAuth[1]) |
|
83 |
+ authConfig.Username, authConfig.Password, err = decodeAuth(origAuth[1]) |
|
84 | 84 |
if err != nil { |
85 | 85 |
return err |
86 | 86 |
} |
... | ... |
@@ -93,7 +93,7 @@ func (configFile *ConfigFile) LegacyLoadFromReader(configData io.Reader) error { |
93 | 93 |
configFile.AuthConfigs[defaultIndexserver] = authConfig |
94 | 94 |
} else { |
95 | 95 |
for k, authConfig := range configFile.AuthConfigs { |
96 |
- authConfig.Username, authConfig.Password, err = DecodeAuth(authConfig.Auth) |
|
96 |
+ authConfig.Username, authConfig.Password, err = decodeAuth(authConfig.Auth) |
|
97 | 97 |
if err != nil { |
98 | 98 |
return err |
99 | 99 |
} |
... | ... |
@@ -113,7 +113,7 @@ func (configFile *ConfigFile) LoadFromReader(configData io.Reader) error { |
113 | 113 |
} |
114 | 114 |
var err error |
115 | 115 |
for addr, ac := range configFile.AuthConfigs { |
116 |
- ac.Username, ac.Password, err = DecodeAuth(ac.Auth) |
|
116 |
+ ac.Username, ac.Password, err = decodeAuth(ac.Auth) |
|
117 | 117 |
if err != nil { |
118 | 118 |
return err |
119 | 119 |
} |
... | ... |
@@ -201,7 +201,7 @@ func (configFile *ConfigFile) SaveToWriter(writer io.Writer) error { |
201 | 201 |
for k, authConfig := range configFile.AuthConfigs { |
202 | 202 |
authCopy := authConfig |
203 | 203 |
// encode and save the authstring, while blanking out the original fields |
204 |
- authCopy.Auth = EncodeAuth(&authCopy) |
|
204 |
+ authCopy.Auth = encodeAuth(&authCopy) |
|
205 | 205 |
authCopy.Username = "" |
206 | 206 |
authCopy.Password = "" |
207 | 207 |
authCopy.ServerAddress = "" |
... | ... |
@@ -242,8 +242,8 @@ func (configFile *ConfigFile) Filename() string { |
242 | 242 |
return configFile.filename |
243 | 243 |
} |
244 | 244 |
|
245 |
-// EncodeAuth creates a base64 encoded string to containing authorization information |
|
246 |
-func EncodeAuth(authConfig *types.AuthConfig) string { |
|
245 |
+// encodeAuth creates a base64 encoded string to containing authorization information |
|
246 |
+func encodeAuth(authConfig *types.AuthConfig) string { |
|
247 | 247 |
authStr := authConfig.Username + ":" + authConfig.Password |
248 | 248 |
msg := []byte(authStr) |
249 | 249 |
encoded := make([]byte, base64.StdEncoding.EncodedLen(len(msg))) |
... | ... |
@@ -251,8 +251,8 @@ func EncodeAuth(authConfig *types.AuthConfig) string { |
251 | 251 |
return string(encoded) |
252 | 252 |
} |
253 | 253 |
|
254 |
-// DecodeAuth decodes a base64 encoded string and returns username and password |
|
255 |
-func DecodeAuth(authStr string) (string, string, error) { |
|
254 |
+// decodeAuth decodes a base64 encoded string and returns username and password |
|
255 |
+func decodeAuth(authStr string) (string, string, error) { |
|
256 | 256 |
decLen := base64.StdEncoding.DecodedLen(len(authStr)) |
257 | 257 |
decoded := make([]byte, decLen) |
258 | 258 |
authByte := []byte(authStr) |
... | ... |
@@ -7,6 +7,7 @@ import ( |
7 | 7 |
"strings" |
8 | 8 |
"testing" |
9 | 9 |
|
10 |
+ "github.com/docker/docker/api/types" |
|
10 | 11 |
"github.com/docker/docker/pkg/homedir" |
11 | 12 |
) |
12 | 13 |
|
... | ... |
@@ -427,8 +428,8 @@ func TestJsonSaveWithNoFile(t *testing.T) { |
427 | 427 |
!strings.Contains(string(buf), "user@example.com") { |
428 | 428 |
t.Fatalf("Should have save in new form: %s", string(buf)) |
429 | 429 |
} |
430 |
- |
|
431 | 430 |
} |
431 |
+ |
|
432 | 432 |
func TestLegacyJsonSaveWithNoFile(t *testing.T) { |
433 | 433 |
|
434 | 434 |
js := `{"https://index.docker.io/v1/":{"auth":"am9lam9lOmhlbGxv","email":"user@example.com"}}` |
... | ... |
@@ -456,3 +457,23 @@ func TestLegacyJsonSaveWithNoFile(t *testing.T) { |
456 | 456 |
t.Fatalf("Should have save in new form: %s", string(buf)) |
457 | 457 |
} |
458 | 458 |
} |
459 |
+ |
|
460 |
+func TestEncodeAuth(t *testing.T) { |
|
461 |
+ newAuthConfig := &types.AuthConfig{Username: "ken", Password: "test", Email: "test@example.com"} |
|
462 |
+ authStr := encodeAuth(newAuthConfig) |
|
463 |
+ decAuthConfig := &types.AuthConfig{} |
|
464 |
+ var err error |
|
465 |
+ decAuthConfig.Username, decAuthConfig.Password, err = decodeAuth(authStr) |
|
466 |
+ if err != nil { |
|
467 |
+ t.Fatal(err) |
|
468 |
+ } |
|
469 |
+ if newAuthConfig.Username != decAuthConfig.Username { |
|
470 |
+ t.Fatal("Encode Username doesn't match decoded Username") |
|
471 |
+ } |
|
472 |
+ if newAuthConfig.Password != decAuthConfig.Password { |
|
473 |
+ t.Fatal("Encode Password doesn't match decoded Password") |
|
474 |
+ } |
|
475 |
+ if authStr != "a2VuOnRlc3Q=" { |
|
476 |
+ t.Fatal("AuthString encoding isn't correct.") |
|
477 |
+ } |
|
478 |
+} |
... | ... |
@@ -5,29 +5,8 @@ import ( |
5 | 5 |
|
6 | 6 |
"github.com/docker/docker/api/types" |
7 | 7 |
registrytypes "github.com/docker/docker/api/types/registry" |
8 |
- "github.com/docker/docker/cliconfig" |
|
9 | 8 |
) |
10 | 9 |
|
11 |
-func TestEncodeAuth(t *testing.T) { |
|
12 |
- newAuthConfig := &types.AuthConfig{Username: "ken", Password: "test", Email: "test@example.com"} |
|
13 |
- authStr := cliconfig.EncodeAuth(newAuthConfig) |
|
14 |
- decAuthConfig := &types.AuthConfig{} |
|
15 |
- var err error |
|
16 |
- decAuthConfig.Username, decAuthConfig.Password, err = cliconfig.DecodeAuth(authStr) |
|
17 |
- if err != nil { |
|
18 |
- t.Fatal(err) |
|
19 |
- } |
|
20 |
- if newAuthConfig.Username != decAuthConfig.Username { |
|
21 |
- t.Fatal("Encode Username doesn't match decoded Username") |
|
22 |
- } |
|
23 |
- if newAuthConfig.Password != decAuthConfig.Password { |
|
24 |
- t.Fatal("Encode Password doesn't match decoded Password") |
|
25 |
- } |
|
26 |
- if authStr != "a2VuOnRlc3Q=" { |
|
27 |
- t.Fatal("AuthString encoding isn't correct.") |
|
28 |
- } |
|
29 |
-} |
|
30 |
- |
|
31 | 10 |
func buildAuthConfigs() map[string]types.AuthConfig { |
32 | 11 |
authConfigs := map[string]types.AuthConfig{} |
33 | 12 |
|