Merge lp:~vds/usso/test_refactoring into lp:usso
- test_refactoring
- Merge into trunk
Proposed by
Vincenzo Di Somma
Status: | Superseded |
---|---|
Proposed branch: | lp:~vds/usso/test_refactoring |
Merge into: | lp:usso |
Diff against target: |
342 lines (+131/-43) 5 files modified
example/usso_example.go (+7/-2) oauth.go (+5/-3) oauth_test.go (+1/-1) usso.go (+39/-5) usso_test.go (+79/-32) |
To merge this branch: | bzr merge lp:~vds/usso/test_refactoring |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Andrew W. Deane (community) | Approve | ||
Review via email: mp+202711@code.launchpad.net |
This proposal has been superseded by a proposal from 2014-01-22.
Commit message
Refactoring usso tests.
Description of the change
Refactoring usso tests.
To post a comment you must log in.
Revision history for this message
Andrew W. Deane (andrew-w-deane) : | # |
review:
Approve
Unmerged revisions
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'example/usso_example.go' | |||
2 | --- example/usso_example.go 2013-10-31 17:33:39 +0000 | |||
3 | +++ example/usso_example.go 2014-01-22 16:59:02 +0000 | |||
4 | @@ -25,8 +25,8 @@ | |||
5 | 25 | inputParams() | 25 | inputParams() |
6 | 26 | // Fetch the tokens using usso.GetToken. | 26 | // Fetch the tokens using usso.GetToken. |
7 | 27 | fmt.Println("Fetching tokens from staging server...") | 27 | fmt.Println("Fetching tokens from staging server...") |
10 | 28 | server := usso.StagingUbuntuSSOServer | 28 | server := usso.ProductionUbuntuSSOServer |
11 | 29 | ssodata, err := server.GetToken(email, password, "usso") | 29 | ssodata, err := server.GetToken(email, password, "Ubuntu One @ test-duplicity") |
12 | 30 | if err != nil { | 30 | if err != nil { |
13 | 31 | panic(err) | 31 | panic(err) |
14 | 32 | } | 32 | } |
15 | @@ -66,4 +66,9 @@ | |||
16 | 66 | fmt.Printf("response: %+v\n", b.String()) | 66 | fmt.Printf("response: %+v\n", b.String()) |
17 | 67 | token_details, _ := server.GetTokenDetails(ssodata) | 67 | token_details, _ := server.GetTokenDetails(ssodata) |
18 | 68 | fmt.Printf("token details: %s\n", token_details) | 68 | fmt.Printf("token details: %s\n", token_details) |
19 | 69 | err = server.RegisterTokenToU1FileSync(ssodata) | ||
20 | 70 | if err != nil { | ||
21 | 71 | fmt.Printf("Error: %s\n", err) | ||
22 | 72 | } | ||
23 | 73 | fmt.Println("Token successfully registered to U1 File Sync Service.") | ||
24 | 69 | } | 74 | } |
25 | 70 | 75 | ||
26 | === modified file 'oauth.go' | |||
27 | --- oauth.go 2013-02-14 22:12:30 +0000 | |||
28 | +++ oauth.go 2014-01-22 16:59:02 +0000 | |||
29 | @@ -31,6 +31,7 @@ | |||
30 | 31 | type SSOData struct { | 31 | type SSOData struct { |
31 | 32 | ConsumerKey string `json:"consumer_key"` | 32 | ConsumerKey string `json:"consumer_key"` |
32 | 33 | ConsumerSecret string `json:"consumer_secret"` | 33 | ConsumerSecret string `json:"consumer_secret"` |
33 | 34 | Realm string `json:"realm"` | ||
34 | 34 | TokenKey string `json:"token_key"` | 35 | TokenKey string `json:"token_key"` |
35 | 35 | TokenName string `json:"token_name"` | 36 | TokenName string `json:"token_name"` |
36 | 36 | TokenSecret string `json:"token_secret"` | 37 | TokenSecret string `json:"token_secret"` |
37 | @@ -53,7 +54,7 @@ | |||
38 | 53 | 54 | ||
39 | 54 | type PLAINTEXT struct{} | 55 | type PLAINTEXT struct{} |
40 | 55 | 56 | ||
42 | 56 | // Return the name of the signature method, used to compose the | 57 | // Return the name of the signature method, used to compose the |
43 | 57 | // Authentication Header. | 58 | // Authentication Header. |
44 | 58 | func (PLAINTEXT) Name() string { return "PLAINTEXT" } | 59 | func (PLAINTEXT) Name() string { return "PLAINTEXT" } |
45 | 59 | 60 | ||
46 | @@ -68,7 +69,7 @@ | |||
47 | 68 | 69 | ||
48 | 69 | type HMACSHA1 struct{} | 70 | type HMACSHA1 struct{} |
49 | 70 | 71 | ||
51 | 71 | // Return the name of the signature method, used to compose the | 72 | // Return the name of the signature method, used to compose the |
52 | 72 | // Authentication Header. | 73 | // Authentication Header. |
53 | 73 | func (HMACSHA1) Name() string { return "HMAC-SHA1" } | 74 | func (HMACSHA1) Name() string { return "HMAC-SHA1" } |
54 | 74 | 75 | ||
55 | @@ -118,7 +119,7 @@ | |||
56 | 118 | return "", err | 119 | return "", err |
57 | 119 | } | 120 | } |
58 | 120 | auth := fmt.Sprintf( | 121 | auth := fmt.Sprintf( |
60 | 121 | `OAuth realm="API", `+ | 122 | `OAuth realm="%s", `+ |
61 | 122 | `oauth_consumer_key="%s", `+ | 123 | `oauth_consumer_key="%s", `+ |
62 | 123 | `oauth_token="%s", `+ | 124 | `oauth_token="%s", `+ |
63 | 124 | `oauth_signature_method="%s", `+ | 125 | `oauth_signature_method="%s", `+ |
64 | @@ -126,6 +127,7 @@ | |||
65 | 126 | `oauth_timestamp="%s", `+ | 127 | `oauth_timestamp="%s", `+ |
66 | 127 | `oauth_nonce="%s", `+ | 128 | `oauth_nonce="%s", `+ |
67 | 128 | `oauth_version="1.0"`, | 129 | `oauth_version="1.0"`, |
68 | 130 | url.QueryEscape(ssodata.Realm), | ||
69 | 129 | url.QueryEscape(ssodata.ConsumerKey), | 131 | url.QueryEscape(ssodata.ConsumerKey), |
70 | 130 | url.QueryEscape(ssodata.TokenKey), | 132 | url.QueryEscape(ssodata.TokenKey), |
71 | 131 | rp.SignatureMethod.Name(), | 133 | rp.SignatureMethod.Name(), |
72 | 132 | 134 | ||
73 | === modified file 'oauth_test.go' | |||
74 | --- oauth_test.go 2013-02-05 12:37:03 +0000 | |||
75 | +++ oauth_test.go 2014-01-22 16:59:02 +0000 | |||
76 | @@ -17,7 +17,7 @@ | |||
77 | 17 | func (suite *OAuthTestSuite) SetUpTest(c *C) { | 17 | func (suite *OAuthTestSuite) SetUpTest(c *C) { |
78 | 18 | baseUrl := "https://localhost" | 18 | baseUrl := "https://localhost" |
79 | 19 | suite.ssodata = SSOData{ConsumerKey: consumerKey, | 19 | suite.ssodata = SSOData{ConsumerKey: consumerKey, |
81 | 20 | ConsumerSecret: consumerSecret, TokenKey: tokenKey, | 20 | ConsumerSecret: consumerSecret, Realm: realm, TokenKey: tokenKey, |
82 | 21 | TokenName: tokenName, TokenSecret: tokenSecret} | 21 | TokenName: tokenName, TokenSecret: tokenSecret} |
83 | 22 | suite.rp = RequestParameters{BaseURL: baseUrl, HTTPMethod: "GET", | 22 | suite.rp = RequestParameters{BaseURL: baseUrl, HTTPMethod: "GET", |
84 | 23 | Nonce: "10888885", Timestamp: "1358853126"} | 23 | Nonce: "10888885", Timestamp: "1358853126"} |
85 | 24 | 24 | ||
86 | === modified file 'usso.go' | |||
87 | --- usso.go 2013-10-31 17:33:39 +0000 | |||
88 | +++ usso.go 2014-01-22 16:59:02 +0000 | |||
89 | @@ -12,7 +12,8 @@ | |||
90 | 12 | ) | 12 | ) |
91 | 13 | 13 | ||
92 | 14 | type UbuntuSSOServer struct { | 14 | type UbuntuSSOServer struct { |
94 | 15 | baseUrl string | 15 | baseUrl string |
95 | 16 | tokenRegistrationUrl string | ||
96 | 16 | } | 17 | } |
97 | 17 | 18 | ||
98 | 18 | // tokenURL returns the URL where the Ubuntu SSO tokens can be requested. | 19 | // tokenURL returns the URL where the Ubuntu SSO tokens can be requested. |
99 | @@ -34,16 +35,15 @@ | |||
100 | 34 | 35 | ||
101 | 35 | // ProductionUbuntuSSOServer represents the production Ubuntu SSO server | 36 | // ProductionUbuntuSSOServer represents the production Ubuntu SSO server |
102 | 36 | // located at https://login.ubuntu.com. | 37 | // located at https://login.ubuntu.com. |
104 | 37 | var ProductionUbuntuSSOServer = UbuntuSSOServer{"https://login.ubuntu.com"} | 38 | var ProductionUbuntuSSOServer = UbuntuSSOServer{"https://login.ubuntu.com", "https://one.ubuntu.com/oauth/sso-finished-so-get-tokens/"} |
105 | 38 | 39 | ||
106 | 39 | // StagingUbuntuSSOServer represents the staging Ubuntu SSO server located | 40 | // StagingUbuntuSSOServer represents the staging Ubuntu SSO server located |
107 | 40 | // at https://login.staging.ubuntu.com. Use it for testing. | 41 | // at https://login.staging.ubuntu.com. Use it for testing. |
109 | 41 | var StagingUbuntuSSOServer = UbuntuSSOServer{"https://login.staging.ubuntu.com"} | 42 | var StagingUbuntuSSOServer = UbuntuSSOServer{"https://login.staging.ubuntu.com", "https://one.staging.ubuntu.com/oauth/sso-finished-so-get-tokens/"} |
110 | 42 | 43 | ||
111 | 43 | // Giving user credentials and token name, retrieves oauth credentials | 44 | // Giving user credentials and token name, retrieves oauth credentials |
112 | 44 | // for the users, the oauth credentials can be used later to sign requests. | 45 | // for the users, the oauth credentials can be used later to sign requests. |
115 | 45 | func (server UbuntuSSOServer) GetToken( | 46 | func (server UbuntuSSOServer) GetToken(email string, password string, tokenName string) (*SSOData, error) { |
114 | 46 | email string, password string, tokenName string) (*SSOData, error) { | ||
116 | 47 | credentials := map[string]string{ | 47 | credentials := map[string]string{ |
117 | 48 | "email": email, | 48 | "email": email, |
118 | 49 | "password": password, | 49 | "password": password, |
119 | @@ -78,6 +78,7 @@ | |||
120 | 78 | log.Println(err) | 78 | log.Println(err) |
121 | 79 | return nil, err | 79 | return nil, err |
122 | 80 | } | 80 | } |
123 | 81 | ssodata.Realm = "API" | ||
124 | 81 | return &ssodata, nil | 82 | return &ssodata, nil |
125 | 82 | } | 83 | } |
126 | 83 | 84 | ||
127 | @@ -151,3 +152,36 @@ | |||
128 | 151 | b.Write(body) | 152 | b.Write(body) |
129 | 152 | return fmt.Sprint(b.String()), nil | 153 | return fmt.Sprint(b.String()), nil |
130 | 153 | } | 154 | } |
131 | 155 | |||
132 | 156 | // Register the toke to the U1 File Sync Service. | ||
133 | 157 | func (server UbuntuSSOServer) RegisterTokenToU1FileSync(ssodata *SSOData) (err error) { | ||
134 | 158 | rp := RequestParameters{ | ||
135 | 159 | BaseURL: server.tokenRegistrationUrl, | ||
136 | 160 | HTTPMethod: "GET", | ||
137 | 161 | SignatureMethod: HMACSHA1{}} | ||
138 | 162 | |||
139 | 163 | request, err := http.NewRequest(rp.HTTPMethod, rp.BaseURL, nil) | ||
140 | 164 | if err != nil { | ||
141 | 165 | return err | ||
142 | 166 | } | ||
143 | 167 | ssodata.Realm = "" | ||
144 | 168 | err = SignRequest(ssodata, &rp, request) | ||
145 | 169 | if err != nil { | ||
146 | 170 | return err | ||
147 | 171 | } | ||
148 | 172 | client := &http.Client{} | ||
149 | 173 | response, err := client.Do(request) | ||
150 | 174 | if err != nil { | ||
151 | 175 | fmt.Printf("Error: %s\n", err) | ||
152 | 176 | } | ||
153 | 177 | if response.StatusCode != 200 { | ||
154 | 178 | body, err := ioutil.ReadAll(response.Body) | ||
155 | 179 | if err != nil { | ||
156 | 180 | fmt.Println(err) | ||
157 | 181 | } | ||
158 | 182 | var b bytes.Buffer | ||
159 | 183 | b.Write(body) | ||
160 | 184 | errors.New(fmt.Sprint(b.String())) | ||
161 | 185 | } | ||
162 | 186 | return nil | ||
163 | 187 | } | ||
164 | 154 | 188 | ||
165 | === modified file 'usso_test.go' | |||
166 | --- usso_test.go 2013-10-31 17:33:39 +0000 | |||
167 | +++ usso_test.go 2014-01-22 16:59:02 +0000 | |||
168 | @@ -21,17 +21,13 @@ | |||
169 | 21 | tokenName = "foo" | 21 | tokenName = "foo" |
170 | 22 | tokenKey = "abcs" | 22 | tokenKey = "abcs" |
171 | 23 | tokenSecret = "mTBgLxtTRUdfqewqgrqsvxlijbMWkPBajgKcoZCrDwv" | 23 | tokenSecret = "mTBgLxtTRUdfqewqgrqsvxlijbMWkPBajgKcoZCrDwv" |
172 | 24 | realm = "API" | ||
173 | 24 | consumerKey = "rfyzhdQ" | 25 | consumerKey = "rfyzhdQ" |
174 | 25 | consumerSecret = "rwDkQkkdfdfdeAslkmmxAOjOAT" | 26 | consumerSecret = "rwDkQkkdfdfdeAslkmmxAOjOAT" |
175 | 26 | email = "foo@bar.com" | 27 | email = "foo@bar.com" |
176 | 27 | password = "foobarpwd" | 28 | password = "foobarpwd" |
177 | 28 | ) | 29 | ) |
178 | 29 | 30 | ||
179 | 30 | type SingleServingServer struct { | ||
180 | 31 | *httptest.Server | ||
181 | 32 | requestContent *string | ||
182 | 33 | } | ||
183 | 34 | |||
184 | 35 | // TestProductionUbuntuSSOServerURLs tests the URLs of the production server. | 31 | // TestProductionUbuntuSSOServerURLs tests the URLs of the production server. |
185 | 36 | func (suite *USSOTestSuite) TestProductionUbuntuSSOServerURLs(c *C) { | 32 | func (suite *USSOTestSuite) TestProductionUbuntuSSOServerURLs(c *C) { |
186 | 37 | tokenURL := ProductionUbuntuSSOServer.tokenURL() | 33 | tokenURL := ProductionUbuntuSSOServer.tokenURL() |
187 | @@ -44,31 +40,47 @@ | |||
188 | 44 | c.Assert(tokenURL, Equals, "https://login.staging.ubuntu.com/api/v2/tokens/oauth") | 40 | c.Assert(tokenURL, Equals, "https://login.staging.ubuntu.com/api/v2/tokens/oauth") |
189 | 45 | } | 41 | } |
190 | 46 | 42 | ||
195 | 47 | // newSingleServingServer create a single-serving test http server which will | 43 | type TestServer struct { |
196 | 48 | // return only one response as defined by the passed arguments. | 44 | *httptest.Server |
197 | 49 | func newSingleServingServer( | 45 | requestContent *string |
198 | 50 | uri string, response string, code int) *SingleServingServer { | 46 | } |
199 | 47 | |||
200 | 48 | // newTestServer http server to mock U1 SSO server. | ||
201 | 49 | func newTestServer(response, tokenDetails string, code int) *TestServer { | ||
202 | 51 | var requestContent string | 50 | var requestContent string |
203 | 52 | var requested bool | ||
204 | 53 | handler := func(w http.ResponseWriter, r *http.Request) { | 51 | handler := func(w http.ResponseWriter, r *http.Request) { |
205 | 54 | if requested { | ||
206 | 55 | http.Error(w, "Already requested", http.StatusServiceUnavailable) | ||
207 | 56 | } | ||
208 | 57 | res, err := ioutil.ReadAll(r.Body) | 52 | res, err := ioutil.ReadAll(r.Body) |
209 | 58 | if err != nil { | 53 | if err != nil { |
210 | 59 | panic(err) | 54 | panic(err) |
211 | 60 | } | 55 | } |
214 | 61 | requestContent = string(res) | 56 | if strings.Contains(string(res), "WRONG") { |
213 | 62 | if r.URL.String() != uri || strings.Contains(requestContent, "WRONG") { | ||
215 | 63 | http.Error(w, "404 page not found", http.StatusNotFound) | 57 | http.Error(w, "404 page not found", http.StatusNotFound) |
216 | 58 | } | ||
217 | 59 | if r.URL.String() == "/api/v2/tokens/oauth" { | ||
218 | 60 | requestContent = string(res) | ||
219 | 61 | fmt.Fprint(w, response) | ||
220 | 62 | return | ||
221 | 63 | } | ||
222 | 64 | if r.URL.String() == "/api/v2/tokens/oauth/abcs" { | ||
223 | 65 | fmt.Fprint(w, tokenDetails) | ||
224 | 66 | return | ||
225 | 67 | } | ||
226 | 68 | if r.URL.String() == "/oauth/sso-finished-so-get-tokens/" { | ||
227 | 69 | fmt.Fprint(w, "ok") | ||
228 | 70 | |||
229 | 71 | concat := "" | ||
230 | 72 | for _, v := range r.Header["Authorization"] { | ||
231 | 73 | concat += v | ||
232 | 74 | } | ||
233 | 75 | requestContent = concat | ||
234 | 76 | return | ||
235 | 64 | } else { | 77 | } else { |
238 | 65 | w.WriteHeader(code) | 78 | http.Error(w, "404 page not found", http.StatusNotFound) |
239 | 66 | fmt.Fprint(w, response) | 79 | return |
240 | 67 | } | 80 | } |
241 | 68 | requested = true | ||
242 | 69 | } | 81 | } |
243 | 70 | server := httptest.NewServer(http.HandlerFunc(handler)) | 82 | server := httptest.NewServer(http.HandlerFunc(handler)) |
245 | 71 | return &SingleServingServer{server, &requestContent} | 83 | return &TestServer{server, &requestContent} |
246 | 72 | } | 84 | } |
247 | 73 | 85 | ||
248 | 74 | func (suite *USSOTestSuite) TestGetTokenReturnsTokens(c *C) { | 86 | func (suite *USSOTestSuite) TestGetTokenReturnsTokens(c *C) { |
249 | @@ -87,16 +99,15 @@ | |||
250 | 87 | if err != nil { | 99 | if err != nil { |
251 | 88 | panic(err) | 100 | panic(err) |
252 | 89 | } | 101 | } |
256 | 90 | server := newSingleServingServer("/api/v2/tokens/oauth", | 102 | server := newTestServer(string(jsonServerResponseData), "{}", 200) |
257 | 91 | string(jsonServerResponseData), 200) | 103 | var testSSOServer = &UbuntuSSOServer{server.URL, ""} |
255 | 92 | var testSSOServer = &UbuntuSSOServer{server.URL} | ||
258 | 93 | defer server.Close() | 104 | defer server.Close() |
259 | 94 | 105 | ||
260 | 95 | // The returned information is correct. | 106 | // The returned information is correct. |
261 | 96 | ssodata, err := testSSOServer.GetToken(email, password, tokenName) | 107 | ssodata, err := testSSOServer.GetToken(email, password, tokenName) |
262 | 97 | c.Assert(err, IsNil) | 108 | c.Assert(err, IsNil) |
263 | 98 | expectedSSOData := &SSOData{ConsumerKey: consumerKey, | 109 | expectedSSOData := &SSOData{ConsumerKey: consumerKey, |
265 | 99 | ConsumerSecret: consumerSecret, TokenKey: tokenKey, | 110 | ConsumerSecret: consumerSecret, Realm: realm, TokenKey: tokenKey, |
266 | 100 | TokenSecret: tokenSecret, TokenName: tokenName} | 111 | TokenSecret: tokenSecret, TokenName: tokenName} |
267 | 101 | c.Assert(ssodata, DeepEquals, expectedSSOData) | 112 | c.Assert(ssodata, DeepEquals, expectedSSOData) |
268 | 102 | // The request that the fake Ubuntu SSO Server has the credentials. | 113 | // The request that the fake Ubuntu SSO Server has the credentials. |
269 | @@ -114,11 +125,10 @@ | |||
270 | 114 | 125 | ||
271 | 115 | // GetToken should return empty credentials and an error, if wrong account is provided. | 126 | // GetToken should return empty credentials and an error, if wrong account is provided. |
272 | 116 | func (suite *USSOTestSuite) TestGetTokenFails(c *C) { | 127 | func (suite *USSOTestSuite) TestGetTokenFails(c *C) { |
275 | 117 | server := newSingleServingServer("/api/v2/tokens/oauth", "{}", 200) | 128 | server := newTestServer("{}", "{}", 200) |
276 | 118 | var testSSOServer = &UbuntuSSOServer{server.URL} | 129 | var testSSOServer = &UbuntuSSOServer{server.URL, ""} |
277 | 119 | defer server.Close() | 130 | defer server.Close() |
278 | 120 | ssodata, err := testSSOServer.GetToken(email, "WRONG", tokenName) | 131 | ssodata, err := testSSOServer.GetToken(email, "WRONG", tokenName) |
279 | 121 | fmt.Println(ssodata, err) | ||
280 | 122 | c.Assert(err, NotNil) | 132 | c.Assert(err, NotNil) |
281 | 123 | c.Assert(ssodata, IsNil) | 133 | c.Assert(ssodata, IsNil) |
282 | 124 | } | 134 | } |
283 | @@ -137,16 +147,53 @@ | |||
284 | 137 | if err != nil { | 147 | if err != nil { |
285 | 138 | panic(err) | 148 | panic(err) |
286 | 139 | } | 149 | } |
290 | 140 | server := newSingleServingServer("/api/v2/tokens/oauth", | 150 | tokenDetails := map[string]string{ |
291 | 141 | string(jsonServerResponseData), 200) | 151 | "token_name": tokenName, |
292 | 142 | var testSSOServer = &UbuntuSSOServer{server.URL} | 152 | "date_updated": "2014-01-22T13:35:49.867", |
293 | 153 | "token_key": tokenKey, | ||
294 | 154 | "href": "/api/v2/tokens/oauth/JckChNpbXxPRmPkElLglSnqnjsnGseWJmNqTJCWfUtNBSsGtoG", | ||
295 | 155 | "date_created": "2014-01-17T20:03:24.993", | ||
296 | 156 | "consumer_key": consumerKey, | ||
297 | 157 | } | ||
298 | 158 | jsonTokenDetails, err := json.Marshal(tokenDetails) | ||
299 | 159 | if err != nil { | ||
300 | 160 | panic(err) | ||
301 | 161 | } | ||
302 | 162 | server := newTestServer(string(jsonServerResponseData), string(jsonTokenDetails), 200) | ||
303 | 163 | var testSSOServer = &UbuntuSSOServer{server.URL, ""} | ||
304 | 143 | defer server.Close() | 164 | defer server.Close() |
305 | 144 | ssodata, err := testSSOServer.GetToken(email, password, tokenName) | 165 | ssodata, err := testSSOServer.GetToken(email, password, tokenName) |
306 | 145 | |||
307 | 146 | // The returned information is correct. | 166 | // The returned information is correct. |
308 | 147 | token_details, err := testSSOServer.GetTokenDetails(ssodata) | 167 | token_details, err := testSSOServer.GetTokenDetails(ssodata) |
309 | 148 | c.Assert(err, IsNil) | 168 | c.Assert(err, IsNil) |
310 | 149 | |||
311 | 150 | //The request that the fake Ubuntu SSO Server has the token details. | 169 | //The request that the fake Ubuntu SSO Server has the token details. |
313 | 151 | fmt.Printf("%s\n", token_details) | 170 | c.Assert(token_details, Equals, string(jsonTokenDetails)) |
314 | 171 | } | ||
315 | 172 | |||
316 | 173 | func (suite *USSOTestSuite) TestRegisterToken(c *C) { | ||
317 | 174 | // Simulate a valid Ubuntu SSO Server response. | ||
318 | 175 | serverResponseData := map[string]string{ | ||
319 | 176 | "date_updated": "2013-01-16 14:03:36", | ||
320 | 177 | "date_created": "2013-01-16 14:03:36", | ||
321 | 178 | "href": "/api/v2/tokens/" + tokenKey, | ||
322 | 179 | "token_name": tokenName, | ||
323 | 180 | "token_key": tokenKey, | ||
324 | 181 | "consumer_key": consumerKey, | ||
325 | 182 | } | ||
326 | 183 | jsonServerResponseData, err := json.Marshal(serverResponseData) | ||
327 | 184 | if err != nil { | ||
328 | 185 | panic(err) | ||
329 | 186 | } | ||
330 | 187 | server := newTestServer(string(jsonServerResponseData), "{}", 200) | ||
331 | 188 | var testSSOServer = &UbuntuSSOServer{server.URL, server.URL + "/oauth/sso-finished-so-get-tokens/"} | ||
332 | 189 | defer server.Close() | ||
333 | 190 | ssodata, err := testSSOServer.GetToken(email, password, tokenName) | ||
334 | 191 | err = testSSOServer.RegisterTokenToU1FileSync(ssodata) | ||
335 | 192 | c.Assert(err, IsNil) | ||
336 | 193 | c.Assert(true, Equals, strings.Contains(*server.requestContent, "oauth_consumer_key=\"rfyzhdQ\"")) | ||
337 | 194 | c.Assert(true, Equals, strings.Contains(*server.requestContent, "oauth_token=\"abcs\"")) | ||
338 | 195 | c.Assert(true, Equals, strings.Contains(*server.requestContent, "oauth_signature_method=\"HMAC-SHA1\"")) | ||
339 | 196 | c.Assert(true, Equals, strings.Contains(*server.requestContent, "oauth_version=\"1.0\"")) | ||
340 | 197 | c.Assert(true, Equals, strings.Contains(*server.requestContent, "")) | ||
341 | 198 | |||
342 | 152 | } | 199 | } |