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 oauth2_test; | 5 library oauth2_test; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 import 'dart:json'; | 8 import 'dart:json'; |
9 import 'dart:uri'; | 9 import 'dart:uri'; |
10 | 10 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 expiration: new Date.now().subtract(new Duration(hours: 1))) | 64 expiration: new Date.now().subtract(new Duration(hours: 1))) |
65 .scheduleCreate(); | 65 .scheduleCreate(); |
66 | 66 |
67 var pub = startPubLish(server); | 67 var pub = startPubLish(server); |
68 confirmPublish(pub); | 68 confirmPublish(pub); |
69 | 69 |
70 server.handle('POST', '/token', (request, response) { | 70 server.handle('POST', '/token', (request, response) { |
71 return consumeInputStream(request.inputStream).transform((bytes) { | 71 return consumeInputStream(request.inputStream).transform((bytes) { |
72 var body = new String.fromCharCodes(bytes); | 72 var body = new String.fromCharCodes(bytes); |
73 expect(body, matches( | 73 expect(body, matches( |
74 new RegExp(r'(^|&)refresh_token=refresh%20token(&|$)'))); | 74 new RegExp(r'(^|&)refresh_token=refresh\+token(&|$)'))); |
75 | 75 |
76 response.headers.contentType = new ContentType("application", "json"); | 76 response.headers.contentType = new ContentType("application", "json"); |
77 response.outputStream.writeString(JSON.stringify({ | 77 response.outputStream.writeString(JSON.stringify({ |
78 "access_token": "new access token", | 78 "access_token": "new access token", |
79 "token_type": "bearer" | 79 "token_type": "bearer" |
80 })); | 80 })); |
81 response.outputStream.close(); | 81 response.outputStream.close(); |
82 }); | 82 }); |
83 }); | 83 }); |
84 | 84 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 equals(['http://pub.dartlang.org/authorized'])); | 204 equals(['http://pub.dartlang.org/authorized'])); |
205 }), anything); | 205 }), anything); |
206 | 206 |
207 handleAccessTokenRequest(server, accessToken); | 207 handleAccessTokenRequest(server, accessToken); |
208 } | 208 } |
209 | 209 |
210 void handleAccessTokenRequest(ScheduledServer server, String accessToken) { | 210 void handleAccessTokenRequest(ScheduledServer server, String accessToken) { |
211 server.handle('POST', '/token', (request, response) { | 211 server.handle('POST', '/token', (request, response) { |
212 return consumeInputStream(request.inputStream).transform((bytes) { | 212 return consumeInputStream(request.inputStream).transform((bytes) { |
213 var body = new String.fromCharCodes(bytes); | 213 var body = new String.fromCharCodes(bytes); |
214 expect(body, matches(new RegExp(r'(^|&)code=access%20code(&|$)'))); | 214 expect(body, matches(new RegExp(r'(^|&)code=access\+code(&|$)'))); |
215 | 215 |
216 response.headers.contentType = new ContentType("application", "json"); | 216 response.headers.contentType = new ContentType("application", "json"); |
217 response.outputStream.writeString(JSON.stringify({ | 217 response.outputStream.writeString(JSON.stringify({ |
218 "access_token": accessToken, | 218 "access_token": accessToken, |
219 "token_type": "bearer" | 219 "token_type": "bearer" |
220 })); | 220 })); |
221 response.outputStream.close(); | 221 response.outputStream.close(); |
222 }); | 222 }); |
223 }); | 223 }); |
224 } | 224 } |
OLD | NEW |