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

Side by Side Diff: pkg/http_server/test/virtual_directory_test.dart

Issue 18333003: Correctly url-decode the path segment in the http_server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Don't allow invalid characters in segment. Created 7 years, 5 months 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 | « pkg/http_server/test/utils.dart ('k') | no next file » | 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) 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
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 test('encoded-path-separator', () {
549 expect(HttpServer.bind('localhost', 0).then((server) {
550 var dir = new Directory('').createTempSync();
551 new Directory('${dir.path}/a').createSync();
552 new Directory('${dir.path}/a/b').createSync();
553 new Directory('${dir.path}/a/b/c').createSync();
554 var virDir = new VirtualDirectory(dir.path);
555 virDir.allowDirectoryListing = true;
556
557 virDir.serve(server);
558
559 return getStatusCode(server.port, '/a%2fb/c', rawPath: true)
560 .whenComplete(() {
561 server.close();
562 dir.deleteSync(recursive: true);
563 });
564 }), completion(equals(HttpStatus.NOT_FOUND)));
565 });
566
567 test('encoded-null', () {
568 expect(HttpServer.bind('localhost', 0).then((server) {
569 var dir = new Directory('').createTempSync();
570 var virDir = new VirtualDirectory(dir.path);
571 virDir.allowDirectoryListing = true;
572
573 virDir.serve(server);
574
575 return getStatusCode(server.port, '/%00', rawPath: true)
576 .whenComplete(() {
577 server.close();
578 dir.deleteSync(recursive: true);
579 });
580 }), completion(equals(HttpStatus.NOT_FOUND)));
581 });
582
583 testEncoding(name, expected, [bool create = true]) {
584 test('encode-$name', () {
585 expect(HttpServer.bind('localhost', 0).then((server) {
586 var dir = new Directory('').createTempSync();
587 if (create) new File('${dir.path}/$name').createSync();
588 var virDir = new VirtualDirectory(dir.path);
589 virDir.allowDirectoryListing = true;
590
591 virDir.serve(server);
592
593 return getStatusCode(server.port, '/$name')
594 .whenComplete(() {
595 server.close();
596 dir.deleteSync(recursive: true);
597 });
598 }), completion(equals(expected)));
599 });
600 }
601 testEncoding('..', HttpStatus.NOT_FOUND, false);
602 testEncoding('%2e%2e', HttpStatus.OK);
603 testEncoding('%252e%252e', HttpStatus.OK);
604 testEncoding('/', HttpStatus.OK, false);
605 testEncoding('%2f', HttpStatus.NOT_FOUND, false);
606 testEncoding('%2f', HttpStatus.OK, true);
607 });
479 } 608 }
480 609
OLDNEW
« no previous file with comments | « pkg/http_server/test/utils.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698