summaryrefslogtreecommitdiff
path: root/tests/test_grantip.py
diff options
context:
space:
mode:
authorianb <devnull@localhost>2006-01-18 21:50:29 +0000
committerianb <devnull@localhost>2006-01-18 21:50:29 +0000
commit47c5d974199a85af11bce55a5d2f1b7933a8ee0d (patch)
treed21af14b7ec7328e5fbee1b1f9beb2d4faeca937 /tests/test_grantip.py
parentbfcdad55bf7cd2e23889ebab7a2eb6caaa4d8313 (diff)
downloadpaste-47c5d974199a85af11bce55a5d2f1b7933a8ee0d.tar.gz
Added middleware for reading mod_auth_tkt-style signed cookies (paste.auth.auth_tkt). Added middleware to set user and group based on IP addresses (paste.auth.grantip). Added some modules for handling ranges of IP addresses, taken from some Python Cookbook recipes -- license is unclear on these, but I've requested clarification from the author (shouldn't be released until that is clarified).
Diffstat (limited to 'tests/test_grantip.py')
-rw-r--r--tests/test_grantip.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/test_grantip.py b/tests/test_grantip.py
new file mode 100644
index 0000000..ffb9cfb
--- /dev/null
+++ b/tests/test_grantip.py
@@ -0,0 +1,31 @@
+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')])
+ return [
+ str(environ.get('REMOTE_USER')),
+ ':',
+ str(environ.get('REMOTE_USER_TOKENS')),
+ ]
+ 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') == 'None:system'
+ assert doit('192.168.15.12') == 'None:worker'
+ assert doit('192.168.0.4') == 'None:worker'
+ assert doit('192.168.0.5') == 'bob:editor,worker'
+ assert doit('192.168.0.8') == 'None:editor'