aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/data/request1
-rw-r--r--test/data/response1
-rw-r--r--test/test_pathoc.py5
-rw-r--r--test/test_pathod.py4
-rw-r--r--test/test_rparse.py33
5 files changed, 41 insertions, 3 deletions
diff --git a/test/data/request b/test/data/request
new file mode 100644
index 00000000..c4c90e76
--- /dev/null
+++ b/test/data/request
@@ -0,0 +1 @@
+get:/foo
diff --git a/test/data/response b/test/data/response
new file mode 100644
index 00000000..8f897c85
--- /dev/null
+++ b/test/data/response
@@ -0,0 +1 @@
+202
diff --git a/test/test_pathoc.py b/test/test_pathoc.py
index 310d75f6..784e2ee3 100644
--- a/test/test_pathoc.py
+++ b/test/test_pathoc.py
@@ -41,3 +41,8 @@ class TestDaemon:
def test_conn_err(self):
assert "Invalid server response" in self.tval(["get:'/p/200:d2'"])
+
+ def test_fileread(self):
+ d = tutils.test_data.path("data/request")
+ assert "foo" in self.tval(["+%s"%d])
+ assert "File" in self.tval(["+/nonexistent"])
diff --git a/test/test_pathod.py b/test/test_pathod.py
index 4a8d90d5..d917e25c 100644
--- a/test/test_pathod.py
+++ b/test/test_pathod.py
@@ -121,6 +121,10 @@ class _DaemonTests:
assert l["type"] == "error"
assert "Invalid" in l["msg"]
+ def test_access_denied(self):
+ rsp = self.get("=nonexistent")
+ assert rsp.status_code == 800
+
class TestDaemon(_DaemonTests):
SSL = False
diff --git a/test/test_rparse.py b/test/test_rparse.py
index 8d157a10..f3dc7367 100644
--- a/test/test_rparse.py
+++ b/test/test_rparse.py
@@ -229,6 +229,12 @@ class TestPauses:
class TestParseRequest:
+ def test_file(self):
+ p = tutils.test_data.path("data")
+ d = dict(staticdir=p)
+ r = rparse.parse_request(d, "+request")
+ assert r.path == "/foo"
+
def test_err(self):
tutils.raises(rparse.ParseException, rparse.parse_request, {}, 'GET')
@@ -266,9 +272,9 @@ class TestParseRequest:
GET
"/foo
-
-
-
+
+
+
bar"
ir,@1
@@ -394,6 +400,12 @@ class TestResponse:
def dummy_response(self):
return rparse.parse_response({}, "400'msg'")
+ def test_file(self):
+ p = tutils.test_data.path("data")
+ d = dict(staticdir=p)
+ r = rparse.parse_response(d, "+response")
+ assert r.code == 202
+
def test_response(self):
r = rparse.parse_response({}, "400'msg'")
assert r.code == 400
@@ -417,3 +429,18 @@ class TestResponse:
testlen(rparse.parse_response({}, "400'msg'"))
testlen(rparse.parse_response({}, "400'msg':h'foo'='bar'"))
testlen(rparse.parse_response({}, "400'msg':h'foo'='bar':b@100b"))
+
+
+
+def test_read_file():
+ tutils.raises(rparse.FileAccessDenied, rparse.read_file, {}, "=/foo")
+ p = tutils.test_data.path("data")
+ d = dict(staticdir=p)
+ assert rparse.read_file(d, "+./file").strip() == "testfile"
+ assert rparse.read_file(d, "+file").strip() == "testfile"
+ tutils.raises(rparse.FileAccessDenied, rparse.read_file, d, "+./nonexistent")
+ tutils.raises(rparse.FileAccessDenied, rparse.read_file, d, "+/nonexistent")
+
+ tutils.raises(rparse.FileAccessDenied, rparse.read_file, d, "+../test_rparse.py")
+ d["unconstrained_file_access"] = True
+ assert rparse.read_file(d, "+../test_rparse.py")