summaryrefslogtreecommitdiff
path: root/tests/test_grantip.py
diff options
context:
space:
mode:
authorMarc Abramowitz <marc@marc-abramowitz.com>2016-03-07 14:05:52 -0800
committerMarc Abramowitz <marc@marc-abramowitz.com>2016-03-07 14:05:52 -0800
commit42b22881290e00e06b840dee1e42f0f5ef044d47 (patch)
treeb4fef928625acd3e8ee45ccaa8c7a6c9810b3601 /tests/test_grantip.py
downloadpaste-git-42b22881290e00e06b840dee1e42f0f5ef044d47.tar.gz
tox.ini: Add py35 to envlisttox_add_py35
Diffstat (limited to 'tests/test_grantip.py')
-rw-r--r--tests/test_grantip.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/test_grantip.py b/tests/test_grantip.py
new file mode 100644
index 0000000..2ddf7f1
--- /dev/null
+++ b/tests/test_grantip.py
@@ -0,0 +1,37 @@
+from paste.auth import grantip
+from paste.fixture import *
+
+def test_make_app():
+ def application(environ, start_response):
+ start_response('200 OK', [('content-type', 'text/plain')])
+ lines = [
+ str(environ.get('REMOTE_USER')),
+ ':',
+ str(environ.get('REMOTE_USER_TOKENS')),
+ ]
+ if six.PY3:
+ lines = [line.encode('utf8') for line in lines]
+ return lines
+ ip_map = {
+ '127.0.0.1': (None, 'system'),
+ '192.168.0.0/16': (None, 'worker'),
+ '192.168.0.5<->192.168.0.8': ('bob', 'editor'),
+ '192.168.0.8': ('__remove__', '-worker'),
+ }
+ app = grantip.GrantIPMiddleware(application, ip_map)
+ app = TestApp(app)
+ return app
+
+def test_req():
+ app = test_make_app()
+ def doit(remote_addr):
+ res = app.get('/', extra_environ={'REMOTE_ADDR': remote_addr})
+ return res.body
+ assert doit('127.0.0.1') == b'None:system'
+ assert doit('192.168.15.12') == b'None:worker'
+ assert doit('192.168.0.4') == b'None:worker'
+ result = doit('192.168.0.5')
+ assert result.startswith(b'bob:')
+ assert b'editor' in result and b'worker' in result
+ assert result.count(b',') == 1
+ assert doit('192.168.0.8') == b'None:editor'