aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-07-23 17:53:17 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-07-23 17:53:17 +1200
commit763e1ff7862e8784170e7c23a015eceaa19e2f70 (patch)
tree622697715d8e0ef0f1d150d7673170bbb322a6b1
parent1d1098687cd397966cf810b52cbf9fe1bc8b1ec4 (diff)
downloadmitmproxy-763e1ff7862e8784170e7c23a015eceaa19e2f70.tar.gz
mitmproxy-763e1ff7862e8784170e7c23a015eceaa19e2f70.tar.bz2
mitmproxy-763e1ff7862e8784170e7c23a015eceaa19e2f70.zip
pathod.py unit tests++
-rw-r--r--libpathod/pathod.py2
-rw-r--r--libpathod/rparse.py12
-rw-r--r--test/test_pathod.py5
-rw-r--r--test/test_rparse.py2
4 files changed, 10 insertions, 11 deletions
diff --git a/libpathod/pathod.py b/libpathod/pathod.py
index f6b5e0f9..12719d13 100644
--- a/libpathod/pathod.py
+++ b/libpathod/pathod.py
@@ -129,7 +129,7 @@ class PathodHandler(tcp.BaseHandler):
try:
if not self.handle_request():
return
- except tcp.NetLibDisconnect:
+ except tcp.NetLibDisconnect: # pragma: no cover
self.info("Disconnect")
self.server.add_log(
dict(
diff --git a/libpathod/rparse.py b/libpathod/rparse.py
index bdce0dd7..e4b62822 100644
--- a/libpathod/rparse.py
+++ b/libpathod/rparse.py
@@ -22,8 +22,6 @@ class ParseException(Exception):
return "%s at offset %s of %s"%(self.msg, self.col, repr(self.s))
-class ServerError(Exception): pass
-
def actions_log(lst):
ret = []
@@ -250,15 +248,15 @@ class ValueFile:
uf = settings.get("unconstrained_file_access")
sd = settings.get("staticdir")
if not sd:
- raise ServerError("File access disabled.")
+ raise FileAccessDenied("File access disabled.")
sd = os.path.normpath(os.path.abspath(sd))
s = os.path.expanduser(self.path)
s = os.path.normpath(os.path.abspath(os.path.join(sd, s)))
if not uf and not s.startswith(sd):
- raise ServerError("File access outside of configured directory")
+ raise FileAccessDenied("File access outside of configured directory")
if not os.path.isfile(s):
- raise ServerError("File not readable")
+ raise FileAccessDenied("File not readable")
return FileGenerator(s)
def __str__(self):
@@ -707,10 +705,6 @@ class PathodErrorResponse(Response):
LiteralGenerator("Content-Type"),
LiteralGenerator("text/plain")
),
- (
- LiteralGenerator("Content-Length"),
- LiteralGenerator(str(len(self.body)))
- )
]
def serve(self, fp, check=None):
diff --git a/test/test_pathod.py b/test/test_pathod.py
index fae00ec2..0adba8e6 100644
--- a/test/test_pathod.py
+++ b/test/test_pathod.py
@@ -85,6 +85,11 @@ class CommonTests(tutils.DaemonTests):
rsp = self.get("=nonexistent")
assert rsp.status_code == 800
+ def test_source_access_denied(self):
+ rsp = self.get("200:b</foo")
+ assert rsp.status_code == 800
+ assert "Access Denied" in rsp.content
+
class TestDaemon(CommonTests):
SSL = False
diff --git a/test/test_rparse.py b/test/test_rparse.py
index 5856d86d..88c1b617 100644
--- a/test/test_rparse.py
+++ b/test/test_rparse.py
@@ -69,7 +69,7 @@ class TestMisc:
assert v.get_generator(dict(staticdir=t))
v = rparse.Value.parseString("<path2")[0]
- tutils.raises(rparse.ServerError, v.get_generator, dict(staticdir=t))
+ tutils.raises(rparse.FileAccessDenied, v.get_generator, dict(staticdir=t))
tutils.raises("access disabled", v.get_generator, dict())
v = rparse.Value.parseString("</outside")[0]