OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library authorization_code_grant_test; | 5 library authorization_code_grant_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:json' as JSON; | 8 import 'dart:convert'; |
9 | 9 |
10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
11 import 'package:http/http.dart' as http; | 11 import 'package:http/http.dart' as http; |
12 import 'package:oauth2/oauth2.dart' as oauth2; | 12 import 'package:oauth2/oauth2.dart' as oauth2; |
13 | 13 |
14 import 'utils.dart'; | 14 import 'utils.dart'; |
15 | 15 |
16 final redirectUrl = Uri.parse('http://example.com/redirect'); | 16 final redirectUrl = Uri.parse('http://example.com/redirect'); |
17 | 17 |
18 ExpectClient client; | 18 ExpectClient client; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 expect(request.method, equals('POST')); | 144 expect(request.method, equals('POST')); |
145 expect(request.url.toString(), equals(grant.tokenEndpoint.toString())); | 145 expect(request.url.toString(), equals(grant.tokenEndpoint.toString())); |
146 expect(request.bodyFields, equals({ | 146 expect(request.bodyFields, equals({ |
147 'grant_type': 'authorization_code', | 147 'grant_type': 'authorization_code', |
148 'code': 'auth code', | 148 'code': 'auth code', |
149 'redirect_uri': redirectUrl.toString(), | 149 'redirect_uri': redirectUrl.toString(), |
150 'client_id': 'identifier', | 150 'client_id': 'identifier', |
151 'client_secret': 'secret' | 151 'client_secret': 'secret' |
152 })); | 152 })); |
153 | 153 |
154 return new Future.value(new http.Response(JSON.stringify({ | 154 return new Future.value(new http.Response(JSON.encode({ |
155 'access_token': 'access token', | 155 'access_token': 'access token', |
156 'token_type': 'bearer', | 156 'token_type': 'bearer', |
157 }), 200, headers: {'content-type': 'application/json'})); | 157 }), 200, headers: {'content-type': 'application/json'})); |
158 }); | 158 }); |
159 | 159 |
160 grant.handleAuthorizationResponse({'code': 'auth code'}) | 160 grant.handleAuthorizationResponse({'code': 'auth code'}) |
161 .then(expectAsync1((client) { | 161 .then(expectAsync1((client) { |
162 expect(client.credentials.accessToken, equals('access token')); | 162 expect(client.credentials.accessToken, equals('access token')); |
163 })); | 163 })); |
164 }); | 164 }); |
(...skipping 23 matching lines...) Expand all Loading... |
188 expect(request.method, equals('POST')); | 188 expect(request.method, equals('POST')); |
189 expect(request.url.toString(), equals(grant.tokenEndpoint.toString())); | 189 expect(request.url.toString(), equals(grant.tokenEndpoint.toString())); |
190 expect(request.bodyFields, equals({ | 190 expect(request.bodyFields, equals({ |
191 'grant_type': 'authorization_code', | 191 'grant_type': 'authorization_code', |
192 'code': 'auth code', | 192 'code': 'auth code', |
193 'redirect_uri': redirectUrl.toString(), | 193 'redirect_uri': redirectUrl.toString(), |
194 'client_id': 'identifier', | 194 'client_id': 'identifier', |
195 'client_secret': 'secret' | 195 'client_secret': 'secret' |
196 })); | 196 })); |
197 | 197 |
198 return new Future.value(new http.Response(JSON.stringify({ | 198 return new Future.value(new http.Response(JSON.encode({ |
199 'access_token': 'access token', | 199 'access_token': 'access token', |
200 'token_type': 'bearer', | 200 'token_type': 'bearer', |
201 }), 200, headers: {'content-type': 'application/json'})); | 201 }), 200, headers: {'content-type': 'application/json'})); |
202 }); | 202 }); |
203 | 203 |
204 expect(grant.handleAuthorizationCode('auth code'), | 204 expect(grant.handleAuthorizationCode('auth code'), |
205 completion(predicate((client) { | 205 completion(predicate((client) { |
206 expect(client.credentials.accessToken, equals('access token')); | 206 expect(client.credentials.accessToken, equals('access token')); |
207 return true; | 207 return true; |
208 }))); | 208 }))); |
209 }); | 209 }); |
210 }); | 210 }); |
211 } | 211 } |
OLD | NEW |