aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libpathod/pathod.py16
-rw-r--r--libpathod/test.py10
-rwxr-xr-xpathod20
-rw-r--r--test/test_pathod.py18
-rw-r--r--test/tutils.py13
5 files changed, 52 insertions, 25 deletions
diff --git a/libpathod/pathod.py b/libpathod/pathod.py
index 12719d13..c95a8ed0 100644
--- a/libpathod/pathod.py
+++ b/libpathod/pathod.py
@@ -92,7 +92,13 @@ class PathodHandler(tcp.BaseHandler):
)
)
if response_log["disconnect"]:
- return
+ return False
+ return True
+
+ if self.server.noweb:
+ crafted = rparse.PathodErrorResponse("Access Denied")
+ crafted.serve(self.wfile, self.server.check_size)
+ return False
else:
cc = wsgi.ClientConn(self.client_address)
req = wsgi.Request(cc, "http", method, path, headers, content)
@@ -105,7 +111,7 @@ class PathodHandler(tcp.BaseHandler):
)
app.serve(req, self.wfile)
self.debug("%s %s"%(method, path))
- return True
+ return True
def handle(self):
if self.server.ssloptions:
@@ -142,7 +148,10 @@ class PathodHandler(tcp.BaseHandler):
class Pathod(tcp.TCPServer):
LOGBUF = 500
- def __init__(self, addr, ssloptions=None, prefix="/p/", staticdir=None, anchors=None, sizelimit=None):
+ def __init__( self,
+ addr, ssloptions=None, prefix="/p/", staticdir=None, anchors=None,
+ sizelimit=None, noweb=False
+ ):
"""
addr: (address, port) tuple. If port is 0, a free port will be
automatically chosen.
@@ -158,6 +167,7 @@ class Pathod(tcp.TCPServer):
self.prefix = prefix
self.sizelimit = sizelimit
self.app = app.app
+ self.noweb = noweb
self.app.config["pathod"] = self
self.log = []
self.logid = 0
diff --git a/libpathod/test.py b/libpathod/test.py
index ff5dac30..e8ca536a 100644
--- a/libpathod/test.py
+++ b/libpathod/test.py
@@ -5,9 +5,9 @@ import pathod, utils
IFACE = "127.0.0.1"
class Daemon:
- def __init__(self, staticdir=None, anchors=(), ssl=None, sizelimit=None):
+ def __init__(self, staticdir=None, anchors=(), ssl=None, sizelimit=None, noweb=False):
self.q = Queue.Queue()
- self.thread = PaThread(self.q, staticdir, anchors, ssl, sizelimit)
+ self.thread = PaThread(self.q, staticdir, anchors, ssl, sizelimit, noweb)
self.thread.start()
self.port = self.q.get(True, 5)
self.urlbase = "%s://%s:%s"%("https" if ssl else "http", IFACE, self.port)
@@ -42,9 +42,10 @@ class Daemon:
class PaThread(threading.Thread):
- def __init__(self, q, staticdir, anchors, ssl, sizelimit):
+ def __init__(self, q, staticdir, anchors, ssl, sizelimit, noweb):
threading.Thread.__init__(self)
self.q, self.staticdir, self.anchors, self.ssl, self.sizelimit = q, staticdir, anchors, ssl, sizelimit
+ self.noweb = noweb
def run(self):
if self.ssl is True:
@@ -59,7 +60,8 @@ class PaThread(threading.Thread):
ssloptions = ssloptions,
anchors = self.anchors,
staticdir = self.staticdir,
- sizelimit = self.sizelimit
+ sizelimit = self.sizelimit,
+ noweb = self.noweb
)
self.q.put(self.server.port)
self.server.serve_forever()
diff --git a/pathod b/pathod
index 052b94bb..d2635ff5 100755
--- a/pathod
+++ b/pathod
@@ -15,28 +15,27 @@ if __name__ == "__main__":
help='Directory for static files.'
)
parser.add_argument(
- "--debug", dest='debug', default=False,
- action="store_true",
+ "--debug", dest='debug', default=False, action="store_true",
help='Enable debug output.'
)
parser.add_argument(
- "-s", dest='ssl', default=False,
- action="store_true",
+ "-s", dest='ssl', default=False, action="store_true",
help='Serve with SSL.'
)
parser.add_argument(
- "--limit-size", dest='sizelimit', default=None,
- type=str,
+ "--limit-size", dest='sizelimit', default=None, type=str,
help='Size limit of served responses. Understands size suffixes, i.e. 100k.'
)
parser.add_argument(
- "--keyfile", dest='ssl_keyfile', default=None,
- type=str,
+ "--noweb", dest='noweb', default=False, action="store_true",
+ help='Disable web interface and API.'
+ )
+ parser.add_argument(
+ "--keyfile", dest='ssl_keyfile', default=None, type=str,
help='SSL key file. If not specified, a default key is used.'
)
parser.add_argument(
- "--certfile", dest='ssl_certfile', default=None,
- type=str,
+ "--certfile", dest='ssl_certfile', default=None, type=str,
help='SSL cert file. If not specified, a default cert is used.'
)
args = parser.parse_args()
@@ -86,6 +85,7 @@ if __name__ == "__main__":
staticdir = args.staticdir,
anchors = alst,
sizelimit = sizelimit,
+ noweb = args.noweb
)
except pathod.PathodError, v:
parser.error(str(v))
diff --git a/test/test_pathod.py b/test/test_pathod.py
index 0adba8e6..58477620 100644
--- a/test/test_pathod.py
+++ b/test/test_pathod.py
@@ -1,5 +1,6 @@
from libpathod import pathod, version
from netlib import tcp, http
+import requests
import tutils
class TestPathod:
@@ -26,6 +27,17 @@ class TestPathod:
assert len(p.get_log()) <= p.LOGBUF
+class TestNoWeb(tutils.DaemonTests):
+ noweb = True
+ def setUp(self):
+ # Over ride log clearing
+ pass
+
+ def test_noweb(self):
+ assert self.get("200").status_code == 200
+ assert self.getpath("/").status_code == 800
+
+
class CommonTests(tutils.DaemonTests):
def test_sizelimit(self):
r = self.get("200:b@1g")
@@ -67,7 +79,7 @@ class CommonTests(tutils.DaemonTests):
def test_invalid_first_line(self):
c = tcp.TCPClient("localhost", self.d.port)
c.connect()
- if self.SSL:
+ if self.ssl:
c.convert_to_ssl()
c.wfile.write("foo\n\n\n")
c.wfile.flush()
@@ -92,11 +104,11 @@ class CommonTests(tutils.DaemonTests):
class TestDaemon(CommonTests):
- SSL = False
+ ssl = False
class TestDaemonSSL(CommonTests):
- SSL = True
+ ssl = True
def test_ssl_conn_failure(self):
c = tcp.TCPClient("localhost", self.d.port)
c.rbufsize = 0
diff --git a/test/tutils.py b/test/tutils.py
index 3b430825..b1e277e7 100644
--- a/test/tutils.py
+++ b/test/tutils.py
@@ -4,13 +4,16 @@ from libpathod import utils, test, pathoc
import requests
class DaemonTests:
+ noweb = False
+ ssl = False
@classmethod
def setUpAll(self):
self.d = test.Daemon(
staticdir=test_data.path("data"),
anchors=[("/anchor/.*", "202")],
- ssl = self.SSL,
- sizelimit=1*1024*1024
+ ssl = self.ssl,
+ sizelimit=1*1024*1024,
+ noweb = self.noweb
)
@classmethod
@@ -21,19 +24,19 @@ class DaemonTests:
self.d.clear_log()
def getpath(self, path, params=None):
- scheme = "https" if self.SSL else "http"
+ scheme = "https" if self.ssl else "http"
return requests.get(
"%s://localhost:%s/%s"%(scheme, self.d.port, path), verify=False, params=params
)
def get(self, spec):
- scheme = "https" if self.SSL else "http"
+ scheme = "https" if self.ssl else "http"
return requests.get("%s://localhost:%s/p/%s"%(scheme, self.d.port, spec), verify=False)
def pathoc(self, spec, timeout=None):
c = pathoc.Pathoc("localhost", self.d.port)
c.connect()
- if self.SSL:
+ if self.ssl:
c.convert_to_ssl()
if timeout:
c.settimeout(timeout)