| 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' as json; | 8 import 'dart:json' as json; |
| 9 import 'dart:uri'; | 9 import 'dart:uri'; |
| 10 | 10 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 var server = new ScheduledServer(); | 57 var server = new ScheduledServer(); |
| 58 credentialsFile(server, 'access token', | 58 credentialsFile(server, 'access token', |
| 59 refreshToken: 'refresh token', | 59 refreshToken: 'refresh token', |
| 60 expiration: new DateTime.now().subtract(new Duration(hours: 1))) | 60 expiration: new DateTime.now().subtract(new Duration(hours: 1))) |
| 61 .scheduleCreate(); | 61 .scheduleCreate(); |
| 62 | 62 |
| 63 var pub = startPubLish(server); | 63 var pub = startPubLish(server); |
| 64 confirmPublish(pub); | 64 confirmPublish(pub); |
| 65 | 65 |
| 66 server.handle('POST', '/token', (request, response) { | 66 server.handle('POST', '/token', (request, response) { |
| 67 return wrapInputStream(request.inputStream).toBytes().then((bytes) { | 67 return consumeInputStream(request.inputStream).then((bytes) { |
| 68 var body = new String.fromCharCodes(bytes); | 68 var body = new String.fromCharCodes(bytes); |
| 69 expect(body, matches( | 69 expect(body, matches( |
| 70 new RegExp(r'(^|&)refresh_token=refresh\+token(&|$)'))); | 70 new RegExp(r'(^|&)refresh_token=refresh\+token(&|$)'))); |
| 71 | 71 |
| 72 response.headers.contentType = new ContentType("application", "json"); | 72 response.headers.contentType = new ContentType("application", "json"); |
| 73 response.outputStream.writeString(json.stringify({ | 73 response.outputStream.writeString(json.stringify({ |
| 74 "access_token": "new access token", | 74 "access_token": "new access token", |
| 75 "token_type": "bearer" | 75 "token_type": "bearer" |
| 76 })); | 76 })); |
| 77 response.outputStream.close(); | 77 response.outputStream.close(); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 }).then((response) { | 191 }).then((response) { |
| 192 expect(response.headers['location'], | 192 expect(response.headers['location'], |
| 193 equals(['http://pub.dartlang.org/authorized'])); | 193 equals(['http://pub.dartlang.org/authorized'])); |
| 194 }), anything); | 194 }), anything); |
| 195 | 195 |
| 196 handleAccessTokenRequest(server, accessToken); | 196 handleAccessTokenRequest(server, accessToken); |
| 197 } | 197 } |
| 198 | 198 |
| 199 void handleAccessTokenRequest(ScheduledServer server, String accessToken) { | 199 void handleAccessTokenRequest(ScheduledServer server, String accessToken) { |
| 200 server.handle('POST', '/token', (request, response) { | 200 server.handle('POST', '/token', (request, response) { |
| 201 return wrapInputStream(request.inputStream).toBytes().then((bytes) { | 201 return consumeInputStream(request.inputStream).then((bytes) { |
| 202 var body = new String.fromCharCodes(bytes); | 202 var body = new String.fromCharCodes(bytes); |
| 203 expect(body, matches(new RegExp(r'(^|&)code=access\+code(&|$)'))); | 203 expect(body, matches(new RegExp(r'(^|&)code=access\+code(&|$)'))); |
| 204 | 204 |
| 205 response.headers.contentType = new ContentType("application", "json"); | 205 response.headers.contentType = new ContentType("application", "json"); |
| 206 response.outputStream.writeString(json.stringify({ | 206 response.outputStream.writeString(json.stringify({ |
| 207 "access_token": accessToken, | 207 "access_token": accessToken, |
| 208 "token_type": "bearer" | 208 "token_type": "bearer" |
| 209 })); | 209 })); |
| 210 response.outputStream.close(); | 210 response.outputStream.close(); |
| 211 }); | 211 }); |
| 212 }); | 212 }); |
| 213 } | 213 } |
| OLD | NEW |