mirror of https://github.com/docker/docs.git
Merge pull request #1283 from crosbymichael/username-not-set
Copy authConfigs on save so data is not modified
This commit is contained in:
commit
7df6c4b9ad
15
auth/auth.go
15
auth/auth.go
|
@ -116,14 +116,19 @@ func SaveConfig(configFile *ConfigFile) error {
|
||||||
os.Remove(confFile)
|
os.Remove(confFile)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
configs := make(map[string]AuthConfig, len(configFile.Configs))
|
||||||
for k, authConfig := range configFile.Configs {
|
for k, authConfig := range configFile.Configs {
|
||||||
authConfig.Auth = encodeAuth(&authConfig)
|
authCopy := authConfig
|
||||||
authConfig.Username = ""
|
|
||||||
authConfig.Password = ""
|
authCopy.Auth = encodeAuth(&authCopy)
|
||||||
configFile.Configs[k] = authConfig
|
authCopy.Username = ""
|
||||||
|
authCopy.Password = ""
|
||||||
|
|
||||||
|
configs[k] = authCopy
|
||||||
}
|
}
|
||||||
|
|
||||||
b, err := json.Marshal(configFile.Configs)
|
b, err := json.Marshal(configs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package auth
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -73,3 +74,39 @@ func TestCreateAccount(t *testing.T) {
|
||||||
t.Fatalf("Expected message \"%s\" but found \"%s\" instead", expectedError, err)
|
t.Fatalf("Expected message \"%s\" but found \"%s\" instead", expectedError, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSameAuthDataPostSave(t *testing.T) {
|
||||||
|
root, err := ioutil.TempDir("", "docker-test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
configFile := &ConfigFile{
|
||||||
|
rootPath: root,
|
||||||
|
Configs: make(map[string]AuthConfig, 1),
|
||||||
|
}
|
||||||
|
|
||||||
|
configFile.Configs["testIndex"] = AuthConfig{
|
||||||
|
Username: "docker-user",
|
||||||
|
Password: "docker-pass",
|
||||||
|
Email: "docker@docker.io",
|
||||||
|
}
|
||||||
|
|
||||||
|
err = SaveConfig(configFile)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
authConfig := configFile.Configs["testIndex"]
|
||||||
|
if authConfig.Username != "docker-user" {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
if authConfig.Password != "docker-pass" {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
if authConfig.Email != "docker@docker.io" {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
if authConfig.Auth != "" {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue