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 import 'dart:convert'; |
5 import 'dart:io'; | 6 import 'dart:io'; |
6 import 'dart:json' as json; | |
7 | 7 |
8 import 'package:scheduled_test/scheduled_test.dart'; | 8 import 'package:scheduled_test/scheduled_test.dart'; |
9 import 'package:scheduled_test/scheduled_server.dart'; | 9 import 'package:scheduled_test/scheduled_server.dart'; |
10 | 10 |
11 import '../descriptor.dart' as d; | 11 import '../descriptor.dart' as d; |
12 import '../test_pub.dart'; | 12 import '../test_pub.dart'; |
13 | 13 |
14 main() { | 14 main() { |
15 initConfig(); | 15 initConfig(); |
16 integration('with server-rejected credentials, authenticates again and saves ' | 16 integration('with server-rejected credentials, authenticates again and saves ' |
17 'credentials.json', () { | 17 'credentials.json', () { |
18 d.validPackage.create(); | 18 d.validPackage.create(); |
19 var server = new ScheduledServer(); | 19 var server = new ScheduledServer(); |
20 d.credentialsFile(server, 'access token').create(); | 20 d.credentialsFile(server, 'access token').create(); |
21 var pub = startPublish(server); | 21 var pub = startPublish(server); |
22 | 22 |
23 confirmPublish(pub); | 23 confirmPublish(pub); |
24 | 24 |
25 server.handle('GET', '/api/packages/versions/new', (request) { | 25 server.handle('GET', '/api/packages/versions/new', (request) { |
26 var response = request.response; | 26 var response = request.response; |
27 response.statusCode = 401; | 27 response.statusCode = 401; |
28 response.headers.set('www-authenticate', 'Bearer error="invalid_token",' | 28 response.headers.set('www-authenticate', 'Bearer error="invalid_token",' |
29 ' error_description="your token sucks"'); | 29 ' error_description="your token sucks"'); |
30 response.write(json.stringify({ | 30 response.write(JSON.encode({ |
31 'error': {'message': 'your token sucks'} | 31 'error': {'message': 'your token sucks'} |
32 })); | 32 })); |
33 response.close(); | 33 response.close(); |
34 }); | 34 }); |
35 | 35 |
36 expect(pub.nextErrLine(), completion(equals('OAuth2 authorization failed ' | 36 expect(pub.nextErrLine(), completion(equals('OAuth2 authorization failed ' |
37 '(your token sucks).'))); | 37 '(your token sucks).'))); |
38 // TODO(rnystrom): The confirm line is run together with this one because | 38 // TODO(rnystrom): The confirm line is run together with this one because |
39 // in normal usage, the user will have entered a newline on stdin which | 39 // in normal usage, the user will have entered a newline on stdin which |
40 // gets echoed to the terminal. Do something better here? | 40 // gets echoed to the terminal. Do something better here? |
41 expect(pub.nextLine(), completion(equals('Uploading...'))); | 41 expect(pub.nextLine(), completion(equals('Uploading...'))); |
42 pub.kill(); | 42 pub.kill(); |
43 }); | 43 }); |
44 } | 44 } |
OLD | NEW |