Author: grayrest
Date: 2005-03-22 13:41:28 -0700 (Tue, 22 Mar 2005)
New Revision: 2195
Added:
WSGIKit/trunk/wsgikit/tests/test_authentication.py
Modified:
WSGIKit/trunk/wsgikit/login.py
Log:
Bugfixes for login, initial draft of test_authentication
Modified: WSGIKit/trunk/wsgikit/login.py
===================================================================
--- WSGIKit/trunk/wsgikit/login.py 2005-03-22 20:18:39 UTC (rev 2194)
+++ WSGIKit/trunk/wsgikit/login.py 2005-03-22 20:41:28 UTC (rev 2195)
@@ -99,10 +99,10 @@
name, value = str(c).split(': ', 1)
headers.append((name, value))
del environ['login._dologin']
- status_int = int(status.split(None, 1).strip())
+ status_int = int(status.split(None, 1)[0].strip())
if status_int == 401 and http_login:
if (http_overwrite_realm
- or not wsgilib.has_header(headers, 'www-authenticate'))):
+ or not wsgilib.has_header(headers, 'www-authenticate')):
headers.append(('WWW-Authenticate', 'Basic realm="%s"' % http_realm))
elif status_int == 401:
status = '200 OK'
Added: WSGIKit/trunk/wsgikit/tests/test_authentication.py
===================================================================
--- WSGIKit/trunk/wsgikit/tests/test_authentication.py 2005-03-22 20:18:39 UTC (rev 2194)
+++ WSGIKit/trunk/wsgikit/tests/test_authentication.py 2005-03-22 20:41:28 UTC (rev 2195)
@@ -0,0 +1,34 @@
+from wsgikit import wsgilib
+from wsgikit import login
+
+def application(environ, start_response):
+ if environ.has_key('REMOTE_USER'):
+ start_response('200 OK', [('Content-type','text/html')])
+ return ['Logged in: ' + environ['REMOTE_USER']]
+ else:
+ print "starting resp"
+ start_response('401 Unauthorized', [('Content-type','text/html')])
+ print "done"
+ return ['Not logged in.']
+
+def run_unauth_application():
+ print wsgilib.interactive(application, '/')
+
+class TestAuth(login.Authenticator):
+ def check_auth (self, username, password):
+ print "testing", username, password
+ return username == password
+
+def run_application():
+ basic_auth = 1
+ if basic_auth:
+ kw = {'http_login' : True, 'authenticator' : TestAuth}
+ else:
+ kw = {'http_login' : False, 'login_page' : '/_login/loginform'}
+ return wsgilib.interactive(login.middleware(application, **kw), '/')
+
+def test_returns_unauthorized():
+ pass
+
+if __name__=='__main__':
+ run_application()
|