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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 142 |
143 response.outputStream.close(); | 143 response.outputStream.close(); |
144 }); | 144 }); |
145 | 145 |
146 pub.kill(); | 146 pub.kill(); |
147 | 147 |
148 credentialsFile(server, 'new access token').scheduleValidate(); | 148 credentialsFile(server, 'new access token').scheduleValidate(); |
149 | 149 |
150 run(); | 150 run(); |
151 }); | 151 }); |
| 152 |
| 153 test('with server-rejected credentials, authenticates again and saves ' |
| 154 'credentials.json', () { |
| 155 var server = new ScheduledServer(); |
| 156 credentialsFile(server, 'access token').scheduleCreate(); |
| 157 var pub = startPubLish(server); |
| 158 |
| 159 confirmPublish(pub); |
| 160 |
| 161 server.handle('GET', '/packages/versions/new.json', (request, response) { |
| 162 response.statusCode = 401; |
| 163 response.headers.set('www-authenticate', 'Bearer error="invalid_token",' |
| 164 ' error_description="your token sucks"'); |
| 165 response.outputStream.writeString(JSON.stringify({ |
| 166 'error': {'message': 'your token sucks'} |
| 167 })); |
| 168 response.outputStream.close(); |
| 169 }); |
| 170 |
| 171 expectLater(pub.nextErrLine(), equals('OAuth2 authorization failed (your ' |
| 172 'token sucks).')); |
| 173 // TODO(rnystrom): The confirm line is run together with this one because |
| 174 // in normal usage, the user will have entered a newline on stdin which |
| 175 // gets echoed to the terminal. Do something better here? |
| 176 expectLater(pub.nextLine(), equals( |
| 177 'Looks great! Are you ready to upload your package (y/n)? ' |
| 178 'Pub needs your authorization to upload packages on your behalf.')); |
| 179 pub.kill(); |
| 180 run(); |
| 181 }); |
152 } | 182 } |
153 | 183 |
154 void authorizePub(ScheduledProcess pub, ScheduledServer server, | 184 void authorizePub(ScheduledProcess pub, ScheduledServer server, |
155 [String accessToken="access token"]) { | 185 [String accessToken="access token"]) { |
156 // 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 |
157 // 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 |
158 // gets echoed to the terminal. Do something better here? | 188 // gets echoed to the terminal. Do something better here? |
159 expectLater(pub.nextLine(), equals( | 189 expectLater(pub.nextLine(), equals( |
160 'Looks great! Are you ready to upload your package (y/n)? ' | 190 'Looks great! Are you ready to upload your package (y/n)? ' |
161 'Pub needs your authorization to upload packages on your behalf.')); | 191 'Pub needs your authorization to upload packages on your behalf.')); |
(...skipping 23 matching lines...) Expand all Loading... |
185 | 215 |
186 response.headers.contentType = new ContentType("application", "json"); | 216 response.headers.contentType = new ContentType("application", "json"); |
187 response.outputStream.writeString(JSON.stringify({ | 217 response.outputStream.writeString(JSON.stringify({ |
188 "access_token": accessToken, | 218 "access_token": accessToken, |
189 "token_type": "bearer" | 219 "token_type": "bearer" |
190 })); | 220 })); |
191 response.outputStream.close(); | 221 response.outputStream.close(); |
192 }); | 222 }); |
193 }); | 223 }); |
194 } | 224 } |
OLD | NEW |