| 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 183 |
| 184 void authorizePub(ScheduledProcess pub, ScheduledServer server, | 184 void authorizePub(ScheduledProcess pub, ScheduledServer server, |
| 185 [String accessToken="access token"]) { | 185 [String accessToken="access token"]) { |
| 186 // TODO(rnystrom): The confirm line is run together with this one because | 186 // TODO(rnystrom): The confirm line is run together with this one because |
| 187 // in normal usage, the user will have entered a newline on stdin which | 187 // in normal usage, the user will have entered a newline on stdin which |
| 188 // gets echoed to the terminal. Do something better here? | 188 // gets echoed to the terminal. Do something better here? |
| 189 expectLater(pub.nextLine(), equals( | 189 expectLater(pub.nextLine(), equals( |
| 190 'Looks great! Are you ready to upload your package (y/n)? ' | 190 'Looks great! Are you ready to upload your package (y/n)? ' |
| 191 'Pub needs your authorization to upload packages on your behalf.')); | 191 'Pub needs your authorization to upload packages on your behalf.')); |
| 192 | 192 |
| 193 expectLater(pub.nextLine().chain((line) { | 193 expectLater(pub.nextLine().then((line) { |
| 194 var match = new RegExp(r'[?&]redirect_uri=([0-9a-zA-Z%+-]+)[$&]') | 194 var match = new RegExp(r'[?&]redirect_uri=([0-9a-zA-Z%+-]+)[$&]') |
| 195 .firstMatch(line); | 195 .firstMatch(line); |
| 196 expect(match, isNotNull); | 196 expect(match, isNotNull); |
| 197 | 197 |
| 198 var redirectUrl = new Uri.fromString(decodeUriComponent(match.group(1))); | 198 var redirectUrl = new Uri.fromString(decodeUriComponent(match.group(1))); |
| 199 redirectUrl = addQueryParameters(redirectUrl, {'code': 'access code'}); | 199 redirectUrl = addQueryParameters(redirectUrl, {'code': 'access code'}); |
| 200 return (new http.Request('GET', redirectUrl)..followRedirects = false) | 200 return (new http.Request('GET', redirectUrl)..followRedirects = false) |
| 201 .send(); | 201 .send(); |
| 202 }).then((response) { | 202 }).then((response) { |
| 203 expect(response.headers['location'], | 203 expect(response.headers['location'], |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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 |