From 97f9a66a3dc13aa4d56eeb7131f0706e2a20a9dd Mon Sep 17 00:00:00 2001 From: RblSb Date: Fri, 3 Sep 2021 12:06:53 +0300 Subject: Detect null/ctrl chars closes #30 --- test/tests/TestServer.hx | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/tests/TestServer.hx (limited to 'test/tests') diff --git a/test/tests/TestServer.hx b/test/tests/TestServer.hx new file mode 100644 index 0000000..4fcbb2e --- /dev/null +++ b/test/tests/TestServer.hx @@ -0,0 +1,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)); + } +} -- cgit v1.2.3