summaryrefslogtreecommitdiffstats
path: root/python/tests/abstractweb.py
diff options
context:
space:
mode:
authorEmmanuel Raviart <eraviart@entrouvert.com>2004-08-11 23:02:55 +0000
committerEmmanuel Raviart <eraviart@entrouvert.com>2004-08-11 23:02:55 +0000
commit2c3b5a50c5c1e6d84ccc74eb55b355af13fd8aa8 (patch)
tree0ecaf6efca3920c6adde149b58ad53d64339132b /python/tests/abstractweb.py
parent02677987a48a67d99f5aacd915119a658dacd42a (diff)
downloadlasso-2c3b5a50c5c1e6d84ccc74eb55b355af13fd8aa8.tar.gz
lasso-2c3b5a50c5c1e6d84ccc74eb55b355af13fd8aa8.tar.xz
lasso-2c3b5a50c5c1e6d84ccc74eb55b355af13fd8aa8.zip
Create a new test Proxy server (a server between a SP and an IDP, which acts
as an IDP for the SP and as a SP for the IDP): login works.
Diffstat (limited to 'python/tests/abstractweb.py')
-rw-r--r--python/tests/abstractweb.py64
1 files changed, 57 insertions, 7 deletions
diff --git a/python/tests/abstractweb.py b/python/tests/abstractweb.py
index 2f189c94..94fb644d 100644
--- a/python/tests/abstractweb.py
+++ b/python/tests/abstractweb.py
@@ -30,11 +30,11 @@ class HttpRequestMixin:
body = None
headers = None
method = None # 'GET' or 'POST' or 'PUT' or...
- url = None
path = None
pathAndQuery = None
query = None
scheme = None # 'http' or 'https'
+ url = None
def getFormField(self, name, default = None):
raise NotImplementedError
@@ -66,6 +66,33 @@ class HttpRequestMixin:
return False
+class FunctionHttpRequest(HttpRequestMixin, object):
+ method = 'GET'
+ previousHttpRequest = None
+ queryFields = None
+
+ def __init__(self, previousHttpRequest, **queryFields):
+ self.previousHttpRequest = previousHttpRequest
+ self.queryFields = queryFields
+
+ def getFormField(self, name, default = None):
+ return default
+
+ def getHeaders(self):
+ return self.previousHttpRequest.headers
+
+ def getQueryField(self, name, default = None):
+ return self.queryFields.get(name, default)
+
+ def hasFormField(self, name):
+ return False
+
+ def hasQueryField(self, name):
+ return name in self.queryFields
+
+ headers = property(getHeaders)
+
+
class HttpResponseMixin:
body = None
defaultStatusMessages = {
@@ -200,10 +227,10 @@ class WebSessionMixin(WebClientMixin):
class WebSiteMixin:
+ FunctionHttpRequest = FunctionHttpRequest # Class
httpResponseHeaders = {
'Server': 'Lasso Simulator Web Server',
}
- instantAuthentication = False
lastSessionToken = 0
lastUserId = 0
users = None
@@ -215,11 +242,6 @@ class WebSiteMixin:
self.users = {}
self.sessions = {}
- def authenticate(self, handler, callback, *arguments, **keywordArguments):
- # The arguments & keywordArguments should be given back to callback only for
- # instant authentication.
- raise NotImplementedError
-
def authenticateX509User(self, clientCertificate):
# We should check certificate (for example clientCertificate.get_serial_number()
# and return the user if one matches, or None otherwise.
@@ -229,6 +251,15 @@ class WebSiteMixin:
# We should check login & password and return the user if one matches or None otherwise.
return None
+ def callHttpFunction(self, function, httpRequestHandler, **queryFields):
+ httpRequestHandler.httpRequest = self.FunctionHttpRequest(
+ httpRequestHandler.httpRequest, **queryFields)
+ try:
+ result = function(httpRequestHandler)
+ finally:
+ httpRequestHandler.httpRequest = httpRequestHandler.httpRequest.previousHttpRequest
+ return result
+
def handleHttpRequestHandler(self, httpRequestHandler):
methodName = httpRequestHandler.httpRequest.path.replace('/', '')
try:
@@ -238,6 +269,25 @@ class WebSiteMixin:
404, 'Path "%s" Not Found.' % httpRequestHandler.httpRequest.path)
return method(httpRequestHandler)
+ def login(self, handler):
+ # On most site (except Liberty service providers), authentication is done locally.
+ return self.callHttpFunction(self.login_local, handler)
+
+ def login_done(self, handler, userAuthenticated, authenticationMethod):
+ if not userAuthenticated:
+ return self.login_failed(handler)
+ return handler.respond(
+ 200, headers = {'Content-Type': 'text/plain'},
+ body = 'Login terminated:\n userAuthenticated = %s\n authenticationMethod = %s' % (
+ userAuthenticated, authenticationMethod))
+
+ def login_failed(self, handler):
+ return handler.respond(401, 'Access Unauthorized: User has no account.')
+
+ def login_local(self, handler):
+ # Note: Once local login is done, the HTTP function login_done must be called.
+ raise NotImplementedError
+
def newSession(self):
self.lastSessionToken += 1
sessionToken = str(self.lastSessionToken)