Merge lp:~vds/usso/wrong_credential_return_error into lp:usso

Proposed by Vincenzo Di Somma
Status: Merged
Merged at revision: 28
Proposed branch: lp:~vds/usso/wrong_credential_return_error
Merge into: lp:usso
Diff against target: 60 lines (+20/-1)
2 files modified
usso.go (+7/-0)
usso_test.go (+13/-1)
To merge this branch: bzr merge lp:~vds/usso/wrong_credential_return_error
Reviewer Review Type Date Requested Status
Andrew W. Deane (community) Approve
Domas Monkus (community) Approve
Graham Binns (community) code Approve
Review via email: mp+150029@code.launchpad.net

Commit message

USSO needs to return also a go error when wrong login or password are provided.

Description of the change

USSO needs to return also a go error when wrong login or password are provided.

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) wrote :

Hey Vincenzo,

Thanks for this branch. Just one tweak needed, then r=me

[1]

51 +func (suite *USSOTestSuite) TestGetTokenFails(c *C) {

This is lacking documentation. What's the expected behaviour that it tests?

review: Approve (code)
28. By Vincenzo Di Somma

Improving docs.

Revision history for this message
Domas Monkus (tasdomas) :
review: Approve
Revision history for this message
Andrew W. Deane (andrew-w-deane) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'usso.go'
--- usso.go 2013-02-14 22:12:30 +0000
+++ usso.go 2013-02-22 12:49:20 +0000
@@ -3,6 +3,7 @@
3import (3import (
4 "bytes"4 "bytes"
5 "encoding/json"5 "encoding/json"
6 "errors"
6 "fmt"7 "fmt"
7 "io/ioutil"8 "io/ioutil"
8 "log"9 "log"
@@ -54,6 +55,12 @@
54 if err != nil {55 if err != nil {
55 return nil, err56 return nil, err
56 }57 }
58 if response.StatusCode == 404 {
59 return nil, errors.New("Wrong credentials.")
60 }
61 if response.StatusCode != 200 {
62 return nil, fmt.Errorf("SSO Error: %s\n", response.Status)
63 }
57 body, err := ioutil.ReadAll(response.Body)64 body, err := ioutil.ReadAll(response.Body)
58 if err != nil {65 if err != nil {
59 log.Println(err)66 log.Println(err)
6067
=== modified file 'usso_test.go'
--- usso_test.go 2013-01-25 15:47:22 +0000
+++ usso_test.go 2013-02-22 12:49:20 +0000
@@ -7,6 +7,7 @@
7 . "launchpad.net/gocheck"7 . "launchpad.net/gocheck"
8 "net/http"8 "net/http"
9 "net/http/httptest"9 "net/http/httptest"
10 "strings"
10 "testing"11 "testing"
11)12)
1213
@@ -58,7 +59,7 @@
58 panic(err)59 panic(err)
59 }60 }
60 requestContent = string(res)61 requestContent = string(res)
61 if r.URL.String() != uri {62 if r.URL.String() != uri || strings.Contains(requestContent, "WRONG") {
62 http.Error(w, "404 page not found", http.StatusNotFound)63 http.Error(w, "404 page not found", http.StatusNotFound)
63 } else {64 } else {
64 w.WriteHeader(code)65 w.WriteHeader(code)
@@ -110,3 +111,14 @@
110 }111 }
111 c.Assert(*server.requestContent, Equals, string(expectedRequestContent))112 c.Assert(*server.requestContent, Equals, string(expectedRequestContent))
112}113}
114
115// GetToken should return empty credentials and an error, if wrong account is provided.
116func (suite *USSOTestSuite) TestGetTokenFails(c *C) {
117 server := newSingleServingServer("/api/v2/tokens", "{}", 200)
118 var testSSOServer = &UbuntuSSOServer{server.URL}
119 defer server.Close()
120 ssodata, err := testSSOServer.GetToken(email, "WRONG", tokenName)
121 fmt.Println(ssodata, err)
122 c.Assert(err, NotNil)
123 c.Assert(ssodata, IsNil)
124}

Subscribers

People subscribed via source and target branches

to all changes: