mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #888 from dotcloud/fix-auth
* Auth: fix auth small issue in case you change your password on index.io
This commit is contained in:
commit
dc847001a5
5 changed files with 26 additions and 6 deletions
4
api.go
4
api.go
|
@ -53,6 +53,10 @@ func httpError(w http.ResponseWriter, err error) {
|
||||||
http.Error(w, err.Error(), http.StatusConflict)
|
http.Error(w, err.Error(), http.StatusConflict)
|
||||||
} else if strings.HasPrefix(err.Error(), "Impossible") {
|
} else if strings.HasPrefix(err.Error(), "Impossible") {
|
||||||
http.Error(w, err.Error(), http.StatusNotAcceptable)
|
http.Error(w, err.Error(), http.StatusNotAcceptable)
|
||||||
|
} else if strings.HasPrefix(err.Error(), "Wrong login/password") {
|
||||||
|
http.Error(w, err.Error(), http.StatusUnauthorized)
|
||||||
|
} else if strings.Contains(err.Error(), "hasn't been activated") {
|
||||||
|
http.Error(w, err.Error(), http.StatusForbidden)
|
||||||
} else {
|
} else {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,7 +146,7 @@ func Login(authConfig *AuthConfig, store bool) (string, error) {
|
||||||
|
|
||||||
if reqStatusCode == 201 {
|
if reqStatusCode == 201 {
|
||||||
status = "Account created. Please use the confirmation link we sent" +
|
status = "Account created. Please use the confirmation link we sent" +
|
||||||
" to your e-mail to activate it.\n"
|
" to your e-mail to activate it."
|
||||||
storeConfig = true
|
storeConfig = true
|
||||||
} else if reqStatusCode == 403 {
|
} else if reqStatusCode == 403 {
|
||||||
return "", fmt.Errorf("Login: Your account hasn't been activated. " +
|
return "", fmt.Errorf("Login: Your account hasn't been activated. " +
|
||||||
|
@ -165,10 +165,11 @@ func Login(authConfig *AuthConfig, store bool) (string, error) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
if resp.StatusCode == 200 {
|
if resp.StatusCode == 200 {
|
||||||
status = "Login Succeeded\n"
|
status = "Login Succeeded"
|
||||||
storeConfig = true
|
storeConfig = true
|
||||||
} else if resp.StatusCode == 401 {
|
} else if resp.StatusCode == 401 {
|
||||||
if store {
|
if store {
|
||||||
|
authConfig.Email = ""
|
||||||
if err := SaveConfig(authConfig); err != nil {
|
if err := SaveConfig(authConfig); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ func TestLogin(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if status != "Login Succeeded\n" {
|
if status != "Login Succeeded" {
|
||||||
t.Fatalf("Expected status \"Login Succeeded\", found \"%s\" instead", status)
|
t.Fatalf("Expected status \"Login Succeeded\", found \"%s\" instead", status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ func TestCreateAccount(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
expectedStatus := "Account created. Please use the confirmation link we sent" +
|
expectedStatus := "Account created. Please use the confirmation link we sent" +
|
||||||
" to your e-mail to activate it.\n"
|
" to your e-mail to activate it."
|
||||||
if status != expectedStatus {
|
if status != expectedStatus {
|
||||||
t.Fatalf("Expected status: \"%s\", found \"%s\" instead.", expectedStatus, status)
|
t.Fatalf("Expected status: \"%s\", found \"%s\" instead.", expectedStatus, status)
|
||||||
}
|
}
|
||||||
|
|
12
commands.go
12
commands.go
|
@ -316,6 +316,7 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
|
||||||
email = cli.authConfig.Email
|
email = cli.authConfig.Email
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
password = cli.authConfig.Password
|
||||||
email = cli.authConfig.Email
|
email = cli.authConfig.Email
|
||||||
}
|
}
|
||||||
term.RestoreTerminal(oldState)
|
term.RestoreTerminal(oldState)
|
||||||
|
@ -324,7 +325,14 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
|
||||||
cli.authConfig.Password = password
|
cli.authConfig.Password = password
|
||||||
cli.authConfig.Email = email
|
cli.authConfig.Email = email
|
||||||
|
|
||||||
body, _, err := cli.call("POST", "/auth", cli.authConfig)
|
body, statusCode, err := cli.call("POST", "/auth", cli.authConfig)
|
||||||
|
if statusCode == 401 {
|
||||||
|
cli.authConfig.Username = ""
|
||||||
|
cli.authConfig.Password = ""
|
||||||
|
cli.authConfig.Email = ""
|
||||||
|
auth.SaveConfig(cli.authConfig)
|
||||||
|
return err
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -337,7 +345,7 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
|
||||||
}
|
}
|
||||||
auth.SaveConfig(cli.authConfig)
|
auth.SaveConfig(cli.authConfig)
|
||||||
if out2.Status != "" {
|
if out2.Status != "" {
|
||||||
fmt.Print(out2.Status)
|
fmt.Println(out2.Status)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -895,9 +895,16 @@ Check auth configuration
|
||||||
.. sourcecode:: http
|
.. sourcecode:: http
|
||||||
|
|
||||||
HTTP/1.1 200 OK
|
HTTP/1.1 200 OK
|
||||||
|
Content-Type: application/json
|
||||||
|
|
||||||
|
{
|
||||||
|
"Status": "Login Succeeded"
|
||||||
|
}
|
||||||
|
|
||||||
:statuscode 200: no error
|
:statuscode 200: no error
|
||||||
:statuscode 204: no error
|
:statuscode 204: no error
|
||||||
|
:statuscode 401: unauthorized
|
||||||
|
:statuscode 403: forbidden
|
||||||
:statuscode 500: server error
|
:statuscode 500: server error
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue