| ... | ... |
@@ -3,6 +3,7 @@ package auth |
| 3 | 3 |
import ( |
| 4 | 4 |
"crypto/rand" |
| 5 | 5 |
"encoding/hex" |
| 6 |
+ "io/ioutil" |
|
| 6 | 7 |
"os" |
| 7 | 8 |
"strings" |
| 8 | 9 |
"testing" |
| ... | ... |
@@ -51,7 +52,7 @@ func TestCreateAccount(t *testing.T) {
|
| 51 | 51 |
} |
| 52 | 52 |
token := hex.EncodeToString(tokenBuffer)[:12] |
| 53 | 53 |
username := "ut" + token |
| 54 |
- authConfig := &AuthConfig{Username: username, Password: "test42", Email: "docker-ut+"+token+"@example.com"}
|
|
| 54 |
+ authConfig := &AuthConfig{Username: username, Password: "test42", Email: "docker-ut+" + token + "@example.com"}
|
|
| 55 | 55 |
status, err := Login(authConfig) |
| 56 | 56 |
if err != nil {
|
| 57 | 57 |
t.Fatal(err) |
| ... | ... |
@@ -73,3 +74,39 @@ func TestCreateAccount(t *testing.T) {
|
| 73 | 73 |
t.Fatalf("Expected message \"%s\" but found \"%s\" instead", expectedError, err)
|
| 74 | 74 |
} |
| 75 | 75 |
} |
| 76 |
+ |
|
| 77 |
+func TestSameAuthDataPostSave(t *testing.T) {
|
|
| 78 |
+ root, err := ioutil.TempDir("", "docker-test")
|
|
| 79 |
+ if err != nil {
|
|
| 80 |
+ t.Fatal(err) |
|
| 81 |
+ } |
|
| 82 |
+ configFile := &ConfigFile{
|
|
| 83 |
+ rootPath: root, |
|
| 84 |
+ Configs: make(map[string]AuthConfig, 1), |
|
| 85 |
+ } |
|
| 86 |
+ |
|
| 87 |
+ configFile.Configs["testIndex"] = AuthConfig{
|
|
| 88 |
+ Username: "docker-user", |
|
| 89 |
+ Password: "docker-pass", |
|
| 90 |
+ Email: "docker@docker.io", |
|
| 91 |
+ } |
|
| 92 |
+ |
|
| 93 |
+ err = SaveConfig(configFile) |
|
| 94 |
+ if err != nil {
|
|
| 95 |
+ t.Fatal(err) |
|
| 96 |
+ } |
|
| 97 |
+ |
|
| 98 |
+ authConfig := configFile.Configs["testIndex"] |
|
| 99 |
+ if authConfig.Username != "docker-user" {
|
|
| 100 |
+ t.Fail() |
|
| 101 |
+ } |
|
| 102 |
+ if authConfig.Password != "docker-pass" {
|
|
| 103 |
+ t.Fail() |
|
| 104 |
+ } |
|
| 105 |
+ if authConfig.Email != "docker@docker.io" {
|
|
| 106 |
+ t.Fail() |
|
| 107 |
+ } |
|
| 108 |
+ if authConfig.Auth != "" {
|
|
| 109 |
+ t.Fail() |
|
| 110 |
+ } |
|
| 111 |
+} |