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

Unified Diff: pkg/http_server/test/virtual_directory_test.dart

Issue 31633003: Make setDirectoryHandler and setErrorPageHandler setters, and add a jailRoot property. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove debug print. Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/http_server/lib/src/virtual_directory.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/http_server/test/virtual_directory_test.dart
diff --git a/pkg/http_server/test/virtual_directory_test.dart b/pkg/http_server/test/virtual_directory_test.dart
index 9d38e6801ba2c176d7ef531b2631881dc918f2b1..a368c73ea4027fdfb3ee87bd1780f90f53ba85da 100644
--- a/pkg/http_server/test/virtual_directory_test.dart
+++ b/pkg/http_server/test/virtual_directory_test.dart
@@ -211,12 +211,12 @@ void main() {
var dir = Directory.systemTemp.createTempSync('http_server_virtual_');
var virDir = new VirtualDirectory(dir.path);
virDir.allowDirectoryListing = true;
- virDir.setDirectoryHandler((dir2, request) {
+ virDir.directoryHandler = (dir2, request) {
expect(dir2, isNotNull);
expect(FileSystemEntity.identicalSync(dir.path, dir2.path), isTrue);
request.response.write('My handler ${request.uri.path}');
request.response.close();
- });
+ };
virDir.serve(server);
@@ -278,7 +278,7 @@ void main() {
var dir =
Directory.systemTemp.createTempSync('http_server_virtual_');
var file = new File('${dir.path}/file')..createSync();
- var link = new Link('${dir.path}/dir3')
+ var link = new Link('${dir.path}/file2')
..createSync('${dir.path}/file');
var virDir = new VirtualDirectory(dir.path);
virDir.followLinks = true;
@@ -287,7 +287,7 @@ void main() {
return new HttpClient().get('localhost',
server.port,
- '/dir3/file')
+ '/file2')
.then((request) => request.close())
.then((response) => response.drain().then(
(_) => response.statusCode))
@@ -302,11 +302,11 @@ void main() {
expect(HttpServer.bind('localhost', 0).then((server) {
var dir =
Directory.systemTemp.createTempSync('http_server_virtual_');
- var name = basename(dir.path);
+ var dir2 = new Directory('${dir.path}/dir')..createSync();
var file = new File('${dir.path}/file')..createSync();
- var link = new Link('${dir.path}/dir3')
- ..createSync('../$name/file');
- var virDir = new VirtualDirectory(dir.path);
+ var link = new Link('${dir2.path}/file')
+ ..createSync('../file');
+ var virDir = new VirtualDirectory(dir2.path);
virDir.followLinks = true;
virDir.serve(server);
@@ -347,6 +347,63 @@ void main() {
}), completion(equals(HttpStatus.NOT_FOUND)));
});
});
+
+ group('follow-links', () {
+ test('no-root-jail', () {
+ test('absolute-link', () {
+ expect(HttpServer.bind('localhost', 0).then((server) {
+ var dir =
+ Directory.systemTemp.createTempSync('http_server_virtual_');
+ var file = new File('${dir.path}/file')..createSync();
+ var link = new Link('${dir.path}/file2')
+ ..createSync('${dir.path}/file');
+ var virDir = new VirtualDirectory(dir.path);
+ virDir.followLinks = true;
+ virDir.jailRoot = false;
+
+ virDir.serve(server);
+
+ return new HttpClient().get('localhost',
+ server.port,
+ '/file2')
+ .then((request) => request.close())
+ .then((response) => response.drain().then(
+ (_) => response.statusCode))
+ .whenComplete(() {
+ server.close();
+ dir.deleteSync(recursive: true);
+ });
+ }), completion(equals(HttpStatus.OK)));
+ });
+
+ test('relative-parent-link', () {
+ expect(HttpServer.bind('localhost', 0).then((server) {
+ var dir =
+ Directory.systemTemp.createTempSync('http_server_virtual_');
+ var dir2 = new Directory('${dir.path}/dir')..createSync();
+ var file = new File('${dir.path}/file')..createSync();
+ var link = new Link('${dir2.path}/file')
+ ..createSync('../file');
+ var virDir = new VirtualDirectory(dir2.path);
+ virDir.followLinks = true;
+ virDir.jailRoot = false;
+
+ virDir.serve(server);
+
+ return new HttpClient().get('localhost',
+ server.port,
+ '/file')
+ .then((request) => request.close())
+ .then((response) => response.drain().then(
+ (_) => response.statusCode))
+ .whenComplete(() {
+ server.close();
+ dir.deleteSync(recursive: true);
+ });
+ }), completion(equals(HttpStatus.OK)));
+ });
+ });
+ });
}
});
@@ -469,11 +526,11 @@ void main() {
var virDir = new VirtualDirectory(dir.path);
dir.deleteSync();
- virDir.setErrorPageHandler((request) {
+ virDir.errorPageHandler = (request) {
request.response.write('my-page ');
request.response.write(request.response.statusCode);
request.response.close();
- });
+ };
virDir.serve(server);
return getAsString(server.port, '/')
« no previous file with comments | « pkg/http_server/lib/src/virtual_directory.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698