diff options
| author | Emmanuel Raviart <eraviart@entrouvert.com> | 2004-08-11 09:59:58 +0000 |
|---|---|---|
| committer | Emmanuel Raviart <eraviart@entrouvert.com> | 2004-08-11 09:59:58 +0000 |
| commit | 80a5b0009a69fd1e4d0451278dbbc5808563dc42 (patch) | |
| tree | 80aa70e18baf8e9b3e537d690061ee137b316319 /python/tests/web.py | |
| parent | 2d1f06f55b37d677f4c17e1fa1c60a0bf65778b3 (diff) | |
| download | lasso-80a5b0009a69fd1e4d0451278dbbc5808563dc42.tar.gz lasso-80a5b0009a69fd1e4d0451278dbbc5808563dc42.tar.xz lasso-80a5b0009a69fd1e4d0451278dbbc5808563dc42.zip | |
In python/tests, there are now a sample IDP (sample-idp.py) and a sample SP
(sample-sp.py). The two applications are real servers.
Diffstat (limited to 'python/tests/web.py')
| -rw-r--r-- | python/tests/web.py | 98 |
1 files changed, 94 insertions, 4 deletions
diff --git a/python/tests/web.py b/python/tests/web.py index 90d74a73..d2db8ed4 100644 --- a/python/tests/web.py +++ b/python/tests/web.py @@ -33,7 +33,84 @@ Features: """ +import urlparse + +from OpenSSL import SSL + import abstractweb +import http + + +class ReceivedHttpResponse(object): + body = None + headers = None + statusCode = None # 200 or... + statusMessage = None + + def __init__(self, statusCode = 200, statusMessage = None, headers = None, body = None): + if statusCode: + self.statusCode = statusCode + if statusMessage: + self.statusMessage = statusMessage + if headers: + self.headers = headers + if body: + self.body = body + + +class WebClient(abstractweb.WebClientMixin, object): + certificateAbsolutePath = None + privateKeyAbsolutePath = None + peerCaCertificateAbsolutePath = None + + def sendHttpRequest(self, method, url, headers = None, body = None): + parsedUrl = urlparse.urlparse(url) + addressingScheme, hostName, path = parsedUrl[:3] + if addressingScheme == 'https': + connection = http.HttpsConnection( + hostName, None, self.privateKeyAbsolutePath, self.certificateAbsolutePath, + self.peerCaCertificateAbsolutePath) + else: + connection = httplib.HTTPConnection(hostName) + if headers: + httpRequestHeaders = self.httpRequestHeaders.copy() + for name, value in headers.iteritems(): + httpRequestHeaders[name] = value + else: + httpRequestHeaders = self.httpRequestHeaders + failUnless('Content-Type' in httpRequestHeaders) + try: + connection.request('POST', path, body, httpRequestHeaders) + except SSL.Error, error: + if error.args and error.args[0] and error.args[0][0] \ + and error.args[0][0][0] == 'SSL routines': + logger.debug('SSL Error in sendHttpRequest. Error = %s' % repr(error)) + raise + response = connection.getresponse() + try: + body = response.read() + except SSL.SysCallError, error: + logger.debug('No SOAP answer in sendHttpRequest. Error = %s' % repr(error)) + raise + httpResponse = ReceivedHttpResponse(response.status, response.reason, response.msg, body) + return httpResponse + + +class WebSession(abstractweb.WebSessionMixin, object): + """Simulation of session of a web site""" + + expirationTime = None # A sample session variable + lassoLoginDump = None # Used only by some identity providers + lassoSessionDump = None + publishToken = False + + +class WebUser(abstractweb.WebUserMixin, object): + """Simulation of user of a web site""" + + lassoIdentityDump = None + language = 'fr' # A sample user variable + password = None class WebSite(abstractweb.WebSiteMixin, WebClient): @@ -42,14 +119,19 @@ class WebSite(abstractweb.WebSiteMixin, WebClient): WebSession = WebSession WebUser = WebUser - def __init__(self, internet, url): - WebClient.__init__(self, internet) + def __init__(self, url): + WebClient.__init__(self) abstractweb.WebSiteMixin.__init__(self) self.url = url - self.internet.addWebSite(self) def authenticate(self, handler, callback, *arguments, **keywordArguments): - FIXME: TODO. + user = handler.user + if user is None: + failUnless(handler.useHttpAuthentication) + return handler.outputErrorUnauthorized(handler.httpRequest.path) + else: + # The user is already authenticated using HTTP authentication. + userAuthenticated = True import lasso authenticationMethod = lasso.samlAuthenticationMethodPassword # FIXME @@ -57,6 +139,9 @@ class WebSite(abstractweb.WebSiteMixin, WebClient): session = handler.session if session is None: session = handler.createSession() + # No need to publish token, because we are using HTTP authentication. + if session.publishToken: + del session.publishToken user = handler.user if user is None: user = handler.createUser() @@ -64,3 +149,8 @@ class WebSite(abstractweb.WebSiteMixin, WebClient): user.sessionToken = session.token return callback(handler, userAuthenticated, authenticationMethod, *arguments, **keywordArguments) + + def authenticateLoginPasswordUser(self, login, password): + # We should check login & password and return the user if one matches or None otherwise. + # FIXME: Check password also. + return self.users.get(login) |
