Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(358)

Side by Side Diff: utils/tests/pub/pub_lish_test.dart

Issue 11464006: Stop working around issue 6984. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utils/tests/pub/oauth2_test.dart ('k') | utils/tests/pub/test_pub.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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';
11 import '../../../pkg/unittest/lib/unittest.dart'; 11 import '../../../pkg/unittest/lib/unittest.dart';
12 import '../../pub/io.dart'; 12 import '../../pub/io.dart';
13 13
14 void handleUploadForm(ScheduledServer server, [Map body]) { 14 void handleUploadForm(ScheduledServer server, [Map body]) {
15 server.handle('GET', '/packages/versions/new.json', (request, response) { 15 server.handle('GET', '/packages/versions/new.json', (request, response) {
16 return server.url.chain((url) { 16 return server.url.transform((url) {
17 expect(request.headers.value('authorization'), 17 expect(request.headers.value('authorization'),
18 equals('Bearer access token')); 18 equals('Bearer access token'));
19 19
20 if (body == null) { 20 if (body == null) {
21 body = { 21 body = {
22 'url': url.resolve('/upload').toString(), 22 'url': url.resolve('/upload').toString(),
23 'fields': { 23 'fields': {
24 'field1': 'value1', 24 'field1': 'value1',
25 'field2': 'value2' 25 'field2': 'value2'
26 } 26 }
27 }; 27 };
28 } 28 }
29 29
30 response.headers.contentType = new ContentType("application", "json"); 30 response.headers.contentType = new ContentType("application", "json");
31 response.outputStream.writeString(JSON.stringify(body)); 31 response.outputStream.writeString(JSON.stringify(body));
32 return closeHttpResponse(request, response); 32 response.outputStream.close();
33 }); 33 });
34 }); 34 });
35 } 35 }
36 36
37 void handleUpload(ScheduledServer server) { 37 void handleUpload(ScheduledServer server) {
38 server.handle('POST', '/upload', (request, response) { 38 server.handle('POST', '/upload', (request, response) {
39 // TODO(nweiz): Once a multipart/form-data parser in Dart exists, validate 39 // TODO(nweiz): Once a multipart/form-data parser in Dart exists, validate
40 // that the request body is correctly formatted. See issue 6952. 40 // that the request body is correctly formatted. See issue 6952.
41 return server.url.chain((url) { 41 return server.url.transform((url) {
42 response.statusCode = 302; 42 response.statusCode = 302;
43 response.headers.set('location', url.resolve('/create').toString()); 43 response.headers.set('location', url.resolve('/create').toString());
44 return closeHttpResponse(request, response); 44 response.outputStream.close();
45 }); 45 });
46 }); 46 });
47 } 47 }
48 48
49 main() { 49 main() {
50 setUp(() => dir(appPath, [libPubspec("test_pkg", "1.0.0")]).scheduleCreate()); 50 setUp(() => dir(appPath, [libPubspec("test_pkg", "1.0.0")]).scheduleCreate());
51 51
52 test('archives and uploads a package', () { 52 test('archives and uploads a package', () {
53 var server = new ScheduledServer(); 53 var server = new ScheduledServer();
54 credentialsFile(server, 'access token').scheduleCreate(); 54 credentialsFile(server, 'access token').scheduleCreate();
55 var pub = startPubLish(server); 55 var pub = startPubLish(server);
56 handleUploadForm(server); 56 handleUploadForm(server);
57 handleUpload(server); 57 handleUpload(server);
58 58
59 server.handle('GET', '/create', (request, response) { 59 server.handle('GET', '/create', (request, response) {
60 response.outputStream.writeString(JSON.stringify({ 60 response.outputStream.writeString(JSON.stringify({
61 'success': {'message': 'Package test_pkg 1.0.0 uploaded!'} 61 'success': {'message': 'Package test_pkg 1.0.0 uploaded!'}
62 })); 62 }));
63 return closeHttpResponse(request, response); 63 response.outputStream.close();
64 }); 64 });
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 test('credentials are invalid', () { 75 test('credentials are invalid', () {
76 var server = new ScheduledServer(); 76 var server = new ScheduledServer();
77 credentialsFile(server, 'access token').scheduleCreate(); 77 credentialsFile(server, 'access token').scheduleCreate();
78 var pub = startPubLish(server); 78 var pub = startPubLish(server);
79 79
80 server.handle('GET', '/packages/versions/new.json', (request, response) { 80 server.handle('GET', '/packages/versions/new.json', (request, response) {
81 response.statusCode = 401; 81 response.statusCode = 401;
82 response.headers.set('www-authenticate', 'Bearer error="invalid_token",' 82 response.headers.set('www-authenticate', 'Bearer error="invalid_token",'
83 ' error_description="your token sucks"'); 83 ' error_description="your token sucks"');
84 response.outputStream.writeString(JSON.stringify({ 84 response.outputStream.writeString(JSON.stringify({
85 'error': {'message': 'your token sucks'} 85 'error': {'message': 'your token sucks'}
86 })); 86 }));
87 return closeHttpResponse(request, response); 87 response.outputStream.close();
88 }); 88 });
89 89
90 expectLater(pub.nextErrLine(), equals('OAuth2 authorization failed (your ' 90 expectLater(pub.nextErrLine(), equals('OAuth2 authorization failed (your '
91 'token sucks).')); 91 'token sucks).'));
92 expectLater(pub.nextLine(), equals('Pub needs your authorization to upload ' 92 expectLater(pub.nextLine(), equals('Pub needs your authorization to upload '
93 'packages on your behalf.')); 93 'packages on your behalf.'));
94 pub.kill(); 94 pub.kill();
95 95
96 run(); 96 run();
97 }); 97 });
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 credentialsFile(server, 'access token').scheduleCreate(); 138 credentialsFile(server, 'access token').scheduleCreate();
139 var pub = startPubLish(server); 139 var pub = startPubLish(server);
140 pub.writeLine("y"); 140 pub.writeLine("y");
141 handleUploadForm(server); 141 handleUploadForm(server);
142 handleUpload(server); 142 handleUpload(server);
143 143
144 server.handle('GET', '/create', (request, response) { 144 server.handle('GET', '/create', (request, response) {
145 response.outputStream.writeString(JSON.stringify({ 145 response.outputStream.writeString(JSON.stringify({
146 'success': {'message': 'Package test_pkg 1.0.0 uploaded!'} 146 'success': {'message': 'Package test_pkg 1.0.0 uploaded!'}
147 })); 147 }));
148 return closeHttpResponse(request, response); 148 response.outputStream.close();
149 }); 149 });
150 150
151 pub.shouldExit(0); 151 pub.shouldExit(0);
152 expectLater(pub.remainingStdout(), 152 expectLater(pub.remainingStdout(),
153 contains('Package test_pkg 1.0.0 uploaded!')); 153 contains('Package test_pkg 1.0.0 uploaded!'));
154 154
155 run(); 155 run();
156 }); 156 });
157 157
158 test('upload form provides an error', () { 158 test('upload form provides an error', () {
159 var server = new ScheduledServer(); 159 var server = new ScheduledServer();
160 credentialsFile(server, 'access token').scheduleCreate(); 160 credentialsFile(server, 'access token').scheduleCreate();
161 var pub = startPubLish(server); 161 var pub = startPubLish(server);
162 162
163 server.handle('GET', '/packages/versions/new.json', (request, response) { 163 server.handle('GET', '/packages/versions/new.json', (request, response) {
164 response.statusCode = 400; 164 response.statusCode = 400;
165 response.outputStream.writeString(JSON.stringify({ 165 response.outputStream.writeString(JSON.stringify({
166 'error': {'message': 'your request sucked'} 166 'error': {'message': 'your request sucked'}
167 })); 167 }));
168 return closeHttpResponse(request, response); 168 response.outputStream.close();
169 }); 169 });
170 170
171 expectLater(pub.nextErrLine(), equals('your request sucked')); 171 expectLater(pub.nextErrLine(), equals('your request sucked'));
172 pub.shouldExit(1); 172 pub.shouldExit(1);
173 173
174 run(); 174 run();
175 }); 175 });
176 176
177 test('upload form provides invalid JSON', () { 177 test('upload form provides invalid JSON', () {
178 var server = new ScheduledServer(); 178 var server = new ScheduledServer();
179 credentialsFile(server, 'access token').scheduleCreate(); 179 credentialsFile(server, 'access token').scheduleCreate();
180 var pub = startPubLish(server); 180 var pub = startPubLish(server);
181 181
182 server.handle('GET', '/packages/versions/new.json', (request, response) { 182 server.handle('GET', '/packages/versions/new.json', (request, response) {
183 response.outputStream.writeString('{not json'); 183 response.outputStream.writeString('{not json');
184 return closeHttpResponse(request, response); 184 response.outputStream.close();
185 }); 185 });
186 186
187 expectLater(pub.nextErrLine(), equals('Invalid server response:')); 187 expectLater(pub.nextErrLine(), equals('Invalid server response:'));
188 expectLater(pub.nextErrLine(), equals('{not json')); 188 expectLater(pub.nextErrLine(), equals('{not json'));
189 pub.shouldExit(1); 189 pub.shouldExit(1);
190 190
191 run(); 191 run();
192 }); 192 });
193 193
194 test('upload form is missing url', () { 194 test('upload form is missing url', () {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 }); 307 });
308 308
309 test("cloud storage upload doesn't redirect", () { 309 test("cloud storage upload doesn't redirect", () {
310 var server = new ScheduledServer(); 310 var server = new ScheduledServer();
311 credentialsFile(server, 'access token').scheduleCreate(); 311 credentialsFile(server, 'access token').scheduleCreate();
312 var pub = startPubLish(server); 312 var pub = startPubLish(server);
313 handleUploadForm(server); 313 handleUploadForm(server);
314 314
315 server.handle('POST', '/upload', (request, response) { 315 server.handle('POST', '/upload', (request, response) {
316 // don't set the location header 316 // don't set the location header
317 return closeHttpResponse(request, response); 317 response.outputStream.close();
318 }); 318 });
319 319
320 expectLater(pub.nextErrLine(), equals('Failed to upload the package.')); 320 expectLater(pub.nextErrLine(), equals('Failed to upload the package.'));
321 pub.shouldExit(1); 321 pub.shouldExit(1);
322 322
323 run(); 323 run();
324 }); 324 });
325 325
326 test('package creation provides an error', () { 326 test('package creation provides an error', () {
327 var server = new ScheduledServer(); 327 var server = new ScheduledServer();
328 credentialsFile(server, 'access token').scheduleCreate(); 328 credentialsFile(server, 'access token').scheduleCreate();
329 var pub = startPubLish(server); 329 var pub = startPubLish(server);
330 handleUploadForm(server); 330 handleUploadForm(server);
331 handleUpload(server); 331 handleUpload(server);
332 332
333 server.handle('GET', '/create', (request, response) { 333 server.handle('GET', '/create', (request, response) {
334 response.statusCode = 400; 334 response.statusCode = 400;
335 response.outputStream.writeString(JSON.stringify({ 335 response.outputStream.writeString(JSON.stringify({
336 'error': {'message': 'Your package was too boring.'} 336 'error': {'message': 'Your package was too boring.'}
337 })); 337 }));
338 return closeHttpResponse(request, response); 338 response.outputStream.close();
339 }); 339 });
340 340
341 expectLater(pub.nextErrLine(), equals('Your package was too boring.')); 341 expectLater(pub.nextErrLine(), equals('Your package was too boring.'));
342 pub.shouldExit(1); 342 pub.shouldExit(1);
343 343
344 run(); 344 run();
345 }); 345 });
346 346
347 test('package creation provides invalid JSON', () { 347 test('package creation provides invalid JSON', () {
348 var server = new ScheduledServer(); 348 var server = new ScheduledServer();
349 credentialsFile(server, 'access token').scheduleCreate(); 349 credentialsFile(server, 'access token').scheduleCreate();
350 var pub = startPubLish(server); 350 var pub = startPubLish(server);
351 handleUploadForm(server); 351 handleUploadForm(server);
352 handleUpload(server); 352 handleUpload(server);
353 353
354 server.handle('GET', '/create', (request, response) { 354 server.handle('GET', '/create', (request, response) {
355 response.outputStream.writeString('{not json'); 355 response.outputStream.writeString('{not json');
356 return closeHttpResponse(request, response); 356 response.outputStream.close();
357 }); 357 });
358 358
359 expectLater(pub.nextErrLine(), equals('Invalid server response:')); 359 expectLater(pub.nextErrLine(), equals('Invalid server response:'));
360 expectLater(pub.nextErrLine(), equals('{not json')); 360 expectLater(pub.nextErrLine(), equals('{not json'));
361 pub.shouldExit(1); 361 pub.shouldExit(1);
362 362
363 run(); 363 run();
364 }); 364 });
365 365
366 test('package creation provides a malformed error', () { 366 test('package creation provides a malformed error', () {
367 var server = new ScheduledServer(); 367 var server = new ScheduledServer();
368 credentialsFile(server, 'access token').scheduleCreate(); 368 credentialsFile(server, 'access token').scheduleCreate();
369 var pub = startPubLish(server); 369 var pub = startPubLish(server);
370 handleUploadForm(server); 370 handleUploadForm(server);
371 handleUpload(server); 371 handleUpload(server);
372 372
373 var body = {'error': 'Your package was too boring.'}; 373 var body = {'error': 'Your package was too boring.'};
374 server.handle('GET', '/create', (request, response) { 374 server.handle('GET', '/create', (request, response) {
375 response.statusCode = 400; 375 response.statusCode = 400;
376 response.outputStream.writeString(JSON.stringify(body)); 376 response.outputStream.writeString(JSON.stringify(body));
377 return closeHttpResponse(request, response); 377 response.outputStream.close();
378 }); 378 });
379 379
380 expectLater(pub.nextErrLine(), equals('Invalid server response:')); 380 expectLater(pub.nextErrLine(), equals('Invalid server response:'));
381 expectLater(pub.nextErrLine(), equals(JSON.stringify(body))); 381 expectLater(pub.nextErrLine(), equals(JSON.stringify(body)));
382 pub.shouldExit(1); 382 pub.shouldExit(1);
383 383
384 run(); 384 run();
385 }); 385 });
386 386
387 test('package creation provides a malformed success', () { 387 test('package creation provides a malformed success', () {
388 var server = new ScheduledServer(); 388 var server = new ScheduledServer();
389 credentialsFile(server, 'access token').scheduleCreate(); 389 credentialsFile(server, 'access token').scheduleCreate();
390 var pub = startPubLish(server); 390 var pub = startPubLish(server);
391 handleUploadForm(server); 391 handleUploadForm(server);
392 handleUpload(server); 392 handleUpload(server);
393 393
394 var body = {'success': 'Your package was awesome.'}; 394 var body = {'success': 'Your package was awesome.'};
395 server.handle('GET', '/create', (request, response) { 395 server.handle('GET', '/create', (request, response) {
396 response.outputStream.writeString(JSON.stringify(body)); 396 response.outputStream.writeString(JSON.stringify(body));
397 return closeHttpResponse(request, response); 397 response.outputStream.close();
398 }); 398 });
399 399
400 expectLater(pub.nextErrLine(), equals('Invalid server response:')); 400 expectLater(pub.nextErrLine(), equals('Invalid server response:'));
401 expectLater(pub.nextErrLine(), equals(JSON.stringify(body))); 401 expectLater(pub.nextErrLine(), equals(JSON.stringify(body)));
402 pub.shouldExit(1); 402 pub.shouldExit(1);
403 403
404 run(); 404 run();
405 }); 405 });
406 } 406 }
OLDNEW
« no previous file with comments | « utils/tests/pub/oauth2_test.dart ('k') | utils/tests/pub/test_pub.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698