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 pub_lish_test; | 5 library pub_lish_test; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 import 'dart:json'; | 8 import 'dart:json'; |
9 | 9 |
10 import 'test_pub.dart'; | 10 import 'test_pub.dart'; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 | 65 |
66 expectLater(pub.nextLine(), equals('Package test_pkg 1.0.0 uploaded!')); | 66 expectLater(pub.nextLine(), equals('Package test_pkg 1.0.0 uploaded!')); |
67 pub.shouldExit(0); | 67 pub.shouldExit(0); |
68 | 68 |
69 run(); | 69 run(); |
70 }); | 70 }); |
71 | 71 |
72 // TODO(nweiz): Once a multipart/form-data parser in Dart exists, we should | 72 // TODO(nweiz): Once a multipart/form-data parser in Dart exists, we should |
73 // test that "pub lish" chooses the correct files to publish. | 73 // test that "pub lish" chooses the correct files to publish. |
74 | 74 |
75 // TODO(nweiz): Once issue 6813 is fixed, test that OAuth2 authentication | 75 test('credentials are invalid', () { |
76 // errors cause the client to try re-authenticating. | 76 var server = new ScheduledServer(); |
77 credentialsFile(server, 'access token').scheduleCreate(); | |
78 var pub = startPubLish(server); | |
79 | |
80 server.handle('GET', '/packages/versions/new.json', (request, response) { | |
81 response.statusCode = 401; | |
82 response.headers.set('www-authenticate', 'Bearer error="invalid_token",' | |
83 ' error_description="your token sucks"'); | |
84 response.outputStream.writeString(JSON.stringify({ | |
85 'error': {'message': 'your token sucks'} | |
86 })); | |
87 return closeHttpResponse(request, response); | |
88 }); | |
89 | |
90 expectLater(pub.nextErrLine(), equals('OAuth2 authorization failed (your ' | |
Bob Nystrom
2012/12/05 17:39:46
The regular expect() function allows a literal in
nweiz
2012/12/05 19:33:55
That is supported. The "matcher" argument is passe
| |
91 'token sucks).')); | |
92 expectLater(pub.nextLine(), equals('Pub needs your authorization to upload ' | |
93 'packages on your behalf.')); | |
94 pub.kill(); | |
95 | |
96 run(); | |
97 }); | |
77 | 98 |
78 test('upload form provides an error', () { | 99 test('upload form provides an error', () { |
79 var server = new ScheduledServer(); | 100 var server = new ScheduledServer(); |
80 credentialsFile(server, 'access token').scheduleCreate(); | 101 credentialsFile(server, 'access token').scheduleCreate(); |
81 var pub = startPubLish(server); | 102 var pub = startPubLish(server); |
82 | 103 |
83 server.handle('GET', '/packages/versions/new.json', (request, response) { | 104 server.handle('GET', '/packages/versions/new.json', (request, response) { |
84 response.statusCode = 400; | 105 response.statusCode = 400; |
85 response.outputStream.writeString(JSON.stringify({ | 106 response.outputStream.writeString(JSON.stringify({ |
86 'error': {'message': 'your request sucked'} | 107 'error': {'message': 'your request sucked'} |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 return closeHttpResponse(request, response); | 338 return closeHttpResponse(request, response); |
318 }); | 339 }); |
319 | 340 |
320 expectLater(pub.nextErrLine(), equals('Invalid server response:')); | 341 expectLater(pub.nextErrLine(), equals('Invalid server response:')); |
321 expectLater(pub.nextErrLine(), equals(JSON.stringify(body))); | 342 expectLater(pub.nextErrLine(), equals(JSON.stringify(body))); |
322 pub.shouldExit(1); | 343 pub.shouldExit(1); |
323 | 344 |
324 run(); | 345 run(); |
325 }); | 346 }); |
326 } | 347 } |
OLD | NEW |