Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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:async'; | 5 import 'dart:async'; |
| 6 import 'dart:io'; | 6 import 'dart:io'; |
| 7 | 7 |
| 8 import "package:unittest/unittest.dart"; | 8 import "package:unittest/unittest.dart"; |
| 9 import "package:http_server/http_server.dart"; | 9 import "package:http_server/http_server.dart"; |
| 10 | 10 |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 }); | 469 }); |
| 470 virDir.serve(server); | 470 virDir.serve(server); |
| 471 | 471 |
| 472 return getAsString(server.port, '/') | 472 return getAsString(server.port, '/') |
| 473 .whenComplete(() { | 473 .whenComplete(() { |
| 474 server.close(); | 474 server.close(); |
| 475 }); | 475 }); |
| 476 }), completion(equals('my-page 404'))); | 476 }), completion(equals('my-page 404'))); |
| 477 }); | 477 }); |
| 478 }); | 478 }); |
| 479 | |
| 480 group('escape-root', () { | |
| 481 test('escape1', () { | |
| 482 expect(HttpServer.bind('localhost', 0).then((server) { | |
| 483 var dir = new Directory('').createTempSync(); | |
| 484 var virDir = new VirtualDirectory(dir.path); | |
| 485 virDir.allowDirectoryListing = true; | |
| 486 | |
| 487 virDir.serve(server); | |
| 488 | |
| 489 return getStatusCode(server.port, '/../') | |
| 490 .whenComplete(() { | |
| 491 server.close(); | |
| 492 dir.deleteSync(); | |
| 493 }); | |
| 494 }), completion(equals(HttpStatus.NOT_FOUND))); | |
| 495 }); | |
| 496 | |
| 497 test('escape2', () { | |
| 498 expect(HttpServer.bind('localhost', 0).then((server) { | |
| 499 var dir = new Directory('').createTempSync(); | |
| 500 new Directory('${dir.path}/dir').createSync(); | |
| 501 var virDir = new VirtualDirectory(dir.path); | |
| 502 virDir.allowDirectoryListing = true; | |
| 503 | |
| 504 virDir.serve(server); | |
| 505 | |
| 506 return getStatusCode(server.port, '/dir/../../') | |
| 507 .whenComplete(() { | |
| 508 server.close(); | |
| 509 dir.deleteSync(recursive: true); | |
| 510 }); | |
| 511 }), completion(equals(HttpStatus.NOT_FOUND))); | |
| 512 }); | |
| 513 }); | |
| 514 | |
| 515 group('url-decode', () { | |
| 516 test('with-space', () { | |
| 517 expect(HttpServer.bind('localhost', 0).then((server) { | |
| 518 var dir = new Directory('').createTempSync(); | |
| 519 var file = new File('${dir.path}/my file')..createSync(); | |
| 520 var virDir = new VirtualDirectory(dir.path); | |
| 521 | |
| 522 virDir.serve(server); | |
| 523 | |
| 524 return getStatusCode(server.port, '/my file') | |
| 525 .whenComplete(() { | |
| 526 server.close(); | |
| 527 dir.deleteSync(recursive: true); | |
| 528 }); | |
| 529 }), completion(equals(HttpStatus.OK))); | |
| 530 }); | |
| 531 | |
| 532 test('encoded-space', () { | |
| 533 expect(HttpServer.bind('localhost', 0).then((server) { | |
| 534 var dir = new Directory('').createTempSync(); | |
| 535 var file = new File('${dir.path}/my file')..createSync(); | |
| 536 var virDir = new VirtualDirectory(dir.path); | |
| 537 | |
| 538 virDir.serve(server); | |
| 539 | |
| 540 return getStatusCode(server.port, '/my%20file') | |
| 541 .whenComplete(() { | |
| 542 server.close(); | |
| 543 dir.deleteSync(recursive: true); | |
| 544 }); | |
| 545 }), completion(equals(HttpStatus.NOT_FOUND))); | |
| 546 }); | |
| 547 | |
| 548 testEncoding(name, expected, [bool create = true]) { | |
| 549 test('encode-$name', () { | |
| 550 expect(HttpServer.bind('localhost', 0).then((server) { | |
| 551 var dir = new Directory('').createTempSync(); | |
| 552 if (create) new File('${dir.path}/$name').createSync(); | |
| 553 var virDir = new VirtualDirectory(dir.path); | |
| 554 virDir.allowDirectoryListing = true; | |
| 555 | |
| 556 virDir.serve(server); | |
| 557 | |
| 558 return getStatusCode(server.port, '/$name') | |
| 559 .whenComplete(() { | |
| 560 server.close(); | |
| 561 dir.deleteSync(recursive: true); | |
| 562 }); | |
| 563 }), completion(equals(expected))); | |
| 564 }); | |
| 565 } | |
| 566 testEncoding('..', HttpStatus.NOT_FOUND, false); | |
| 567 testEncoding('%2e%2e', HttpStatus.OK); | |
| 568 testEncoding('%252e%252e', HttpStatus.OK); | |
| 569 testEncoding('/', HttpStatus.OK, false); | |
| 570 testEncoding('%2f', HttpStatus.NOT_FOUND, false); | |
| 571 testEncoding('%2f', HttpStatus.OK, true); | |
|
Lasse Reichstein Nielsen
2013/07/02 07:31:14
So you are successfully creating a file called "%2
Anders Johnsen
2013/07/02 11:08:07
Done.
| |
| 572 }); | |
| 479 } | 573 } |
| 480 | 574 |
| OLD | NEW |