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 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
1=== modified file 'usso.go'
2--- usso.go 2013-02-14 22:12:30 +0000
3+++ usso.go 2013-02-22 12:49:20 +0000
4@@ -3,6 +3,7 @@
5 import (
6 "bytes"
7 "encoding/json"
8+ "errors"
9 "fmt"
10 "io/ioutil"
11 "log"
12@@ -54,6 +55,12 @@
13 if err != nil {
14 return nil, err
15 }
16+ if response.StatusCode == 404 {
17+ return nil, errors.New("Wrong credentials.")
18+ }
19+ if response.StatusCode != 200 {
20+ return nil, fmt.Errorf("SSO Error: %s\n", response.Status)
21+ }
22 body, err := ioutil.ReadAll(response.Body)
23 if err != nil {
24 log.Println(err)
25
26=== modified file 'usso_test.go'
27--- usso_test.go 2013-01-25 15:47:22 +0000
28+++ usso_test.go 2013-02-22 12:49:20 +0000
29@@ -7,6 +7,7 @@
30 . "launchpad.net/gocheck"
31 "net/http"
32 "net/http/httptest"
33+ "strings"
34 "testing"
35 )
36
37@@ -58,7 +59,7 @@
38 panic(err)
39 }
40 requestContent = string(res)
41- if r.URL.String() != uri {
42+ if r.URL.String() != uri || strings.Contains(requestContent, "WRONG") {
43 http.Error(w, "404 page not found", http.StatusNotFound)
44 } else {
45 w.WriteHeader(code)
46@@ -110,3 +111,14 @@
47 }
48 c.Assert(*server.requestContent, Equals, string(expectedRequestContent))
49 }
50+
51+// GetToken should return empty credentials and an error, if wrong account is provided.
52+func (suite *USSOTestSuite) TestGetTokenFails(c *C) {
53+ server := newSingleServingServer("/api/v2/tokens", "{}", 200)
54+ var testSSOServer = &UbuntuSSOServer{server.URL}
55+ defer server.Close()
56+ ssodata, err := testSSOServer.GetToken(email, "WRONG", tokenName)
57+ fmt.Println(ssodata, err)
58+ c.Assert(err, NotNil)
59+ c.Assert(ssodata, IsNil)
60+}

Subscribers

People subscribed via source and target branches

to all changes: