aboutsummaryrefslogtreecommitdiffstats
path: root/test/tests/TestServer.hx
blob: 4fcbb2ec81e0ae5b9ceb537c16e803854d05b3e3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package test.tests;

import js.node.Http;
import server.Main;
import utest.Assert;
import utest.Async;
import utest.Test;

@:access(server)
class TestServer extends Test {
	@:timeout(500)
	function testBadRequests(async:Async) {
		final server = new Main();
		server.onServerInited = () -> {
			final url = 'http://${server.localIp}:${server.port}';
			request('$url/你好,世界!@$^&*)_+-=', data -> {
				Assert.equals("File 你好,世界!@$^&*)_+-= not found.", data);
			});
			request('$url/Привет%00мир!', data -> {
				Assert.equals("File Приветмир! not found.", data);
			});
			request('$url/Ы%ы%00ы!', data -> {
				Assert.equals("File %D0%AB%%D1%8B%00%D1%8B! not found.", data);
			});
			request('$url/video/skins/default.php?dir_inc=/etc/passwd%00', data -> {
				Assert.equals("File video/skins/default.php?dir_inc=/etc/passwd not found.", data);
			});
			request('$url/%20', data -> {
				Assert.equals("File   not found.", data);
			});
			request('$url/build/../../server.js', data -> {
				Assert.equals("File server.js not found.", data);
				async.done();
			});
		}
	}

	function request(url:String, onComplete:(data:String) -> Void):Void {
		Http.get(url, r -> {
			r.setEncoding("utf8");
			final data = new StringBuf();
			r.on("data", chunk -> data.add(chunk));
			r.on("end", _ -> onComplete(data.toString()));
		}).on("error", e -> trace(e));
	}
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage