summaryrefslogtreecommitdiffstats
path: root/python/tests/sample-lep.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/sample-lep.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/sample-lep.py')
-rwxr-xr-xpython/tests/sample-lep.py152
1 files changed, 152 insertions, 0 deletions
diff --git a/python/tests/sample-lep.py b/python/tests/sample-lep.py
new file mode 100755
index 00000000..308f3e7c
--- /dev/null
+++ b/python/tests/sample-lep.py
@@ -0,0 +1,152 @@
+#! /usr/bin/env python
+# -*- coding: UTF-8 -*-
+
+
+# Lasso Simulator
+# By: Emmanuel Raviart <eraviart@entrouvert.com>
+#
+# Copyright (C) 2004 Entr'ouvert
+# http://lasso.entrouvert.org
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+import logging
+from optparse import OptionParser
+import sys
+
+if not '..' in sys.path:
+ sys.path.insert(0, '..')
+if not '../.libs' in sys.path:
+ sys.path.insert(0, '../.libs')
+
+import lasso
+
+import assertions
+import builtins
+import http
+import liberty
+
+
+applicationCamelCaseName = 'LassoSimulator'
+applicationPublicName = 'Lasso Simulator'
+applicationVersion = '(Unreleased CVS Version)'
+logger = None
+
+
+class HttpRequestHandlerMixin:
+ realm = '%s Web Site' % applicationPublicName
+ server_version = '%s/%s' % (applicationCamelCaseName, applicationVersion)
+
+ def version_string(self):
+ return '%s %s' % (applicationPublicName, applicationVersion)
+
+
+class HttpRequestHandler(HttpRequestHandlerMixin, http.HttpRequestHandler):
+ pass
+
+
+class HttpsRequestHandler(HttpRequestHandlerMixin, http.HttpsRequestHandler):
+ pass
+
+
+def main():
+ # Parse command line options.
+ parser = OptionParser(version = '%%prog %s' % applicationVersion)
+ parser.add_option(
+ '-c', '--config', metavar = 'FILE', dest = 'configurationFilePath',
+ help = 'specify an alternate configuration file',
+ default = '/etc/lasso-simulator/config.xml')
+ parser.add_option(
+ '-d', '--daemon', dest = 'daemonMode', help = 'run main process in background',
+ action = 'store_true', default = False)
+ parser.add_option(
+ '-D', '--debug', dest = 'debugMode', help = 'enable program debugging',
+ action = 'store_true', default = False)
+ parser.add_option(
+ '-l', '--log', metavar = 'FILE', dest = 'logFilePath', help = 'specify log file',
+ default = '/dev/null')
+ parser.add_option(
+ '-L', '--log-level', metavar = 'LEVEL', dest = 'logLevel',
+ help = 'specify log level (debug, info, warning, error, critical)', default = 'info')
+ (options, args) = parser.parse_args()
+ if options.logLevel.upper() not in logging._levelNames:
+ raise Exception('Unknown log level: "%s"' % options.logLevel)
+
+ # Configure logger.
+ logger = logging.getLogger()
+ if options.debugMode and not options.daemonMode:
+ handler = logging.StreamHandler(sys.stderr)
+ else:
+ handler = logging.FileHandler(options.logFilePath)
+ formatter = logging.Formatter('%(asctime)s %(levelname)-9s %(message)s')
+ handler.setFormatter(formatter)
+ logger.addHandler(handler)
+ logger.setLevel(logging._levelNames[options.logLevel.upper()])
+ builtins.set('logger', logger)
+
+ site = liberty.LibertyEnabledProxy('https://liberty-enabled-proxy/')
+ site.providerId = 'https://liberty-enabled-proxy/metadata'
+ site.idpSite = liberty.IdentityProvider('https://identity-provider/')
+ site.idpSite.providerId = 'https://identity-provider/metadata'
+
+ lassoServer = lasso.Server.new(
+ '../../examples/data/lep-metadata.xml',
+ None, # '../../examples/data/idp-public-key.pem' is no more used.
+ '../../examples/data/idp-private-key.pem',
+ '../../examples/data/idp-crt.pem',
+ lasso.signatureMethodRsaSha1)
+ lassoServer.add_provider(
+ '../../examples/data/idp-metadata.xml',
+ '../../examples/data/idp-public-key.pem',
+ '../../examples/data/ca-crt.pem')
+ lassoServer.add_provider(
+ '../../examples/data/sp-lep-metadata.xml',
+ '../../examples/data/sp-public-key.pem',
+ '../../examples/data/ca-crt.pem')
+ site.lassoServerDump = lassoServer.dump()
+ failUnless(site.lassoServerDump)
+ lassoServer.destroy()
+
+ site.certificateAbsolutePath = '../../examples/data/idp-ssl-crt.pem'
+ site.privateKeyAbsolutePath = '../../examples/data/idp-ssl-private-key.pem'
+ site.peerCaCertificateAbsolutePath = '../../examples/data/ca-ssl-crt.pem'
+
+ site.newUser('rc')
+ site.newUser('nc')
+ # site.newUser('vf') Valery Febvre has no account on liberty-enabled proxy.
+ site.newUser('cn')
+ site.newUser('fp')
+
+ HttpRequestHandlerMixin.site = site # Directly a site, not a server => no virtual host.
+## httpServer = http.HttpServer(('127.0.0.4', 80), HttpRequestHandler)
+## logger.info('Serving HTTP on %s port %s...' % httpServer.socket.getsockname())
+ httpServer = http.HttpsServer(
+ ('127.0.0.4', 443),
+ HttpsRequestHandler,
+ '../../examples/data/idp-ssl-private-key.pem', # Server private key
+ '../../examples/data/idp-ssl-crt.pem', # Server certificate
+ '../../examples/data/ca-ssl-crt.pem', # Clients certification authority certificate
+ None, # sslCertificateChainFile see mod_ssl, ssl_engine_init.c, line 852
+ None, # sslVerifyClient http://www.modssl.org/docs/2.1/ssl_reference.html#ToC13
+ )
+ logger.info('Serving HTTPS on %s port %s...' % httpServer.socket.getsockname())
+ try:
+ httpServer.serve_forever()
+ except KeyboardInterrupt:
+ pass
+
+if __name__ == '__main__':
+ main()