X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fipsilon.git;a=blobdiff_plain;f=tests%2Ftest1.py;h=69c5938a4a18c241259dc1c82cdc3e36287f68c0;hp=34b9c88cb8f57d6c27cf2d71fedd5a2fcef2a642;hb=effa209e386930ad705f255e61c24a5dfb057987;hpb=fca4035996c93f8f05ea3837133961e28a1248d6 diff --git a/tests/test1.py b/tests/test1.py index 34b9c88..69c5938 100755 --- a/tests/test1.py +++ b/tests/test1.py @@ -1,22 +1,6 @@ #!/usr/bin/python # -# Copyright (C) 2014 Simo Sorce -# -# see file 'COPYING' for use and warranty information -# -# 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 3 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, see . - +# Copyright (C) 2014 Ipsilon project Contributors, for license see COPYING from helpers.common import IpsilonTestBase # pylint: disable=relative-import from helpers.http import HttpSessions # pylint: disable=relative-import @@ -25,10 +9,10 @@ import pwd import sys from string import Template - idp_g = {'TEMPLATES': '${TESTDIR}/templates/install', 'CONFDIR': '${TESTDIR}/etc', 'DATADIR': '${TESTDIR}/lib', + 'CACHEDIR': '${TESTDIR}/cache', 'HTTPDCONFD': '${TESTDIR}/${NAME}/conf.d', 'STATICDIR': '${ROOTDIR}', 'BINDIR': '${ROOTDIR}/ipsilon', @@ -42,7 +26,7 @@ idp_a = {'hostname': '${ADDRESS}:${PORT}', 'secure': 'no', 'testauth': 'yes', 'pam': 'no', - 'krb': 'no', + 'gssapi': 'no', 'ipa': 'no', 'server_debugging': 'True'} @@ -59,6 +43,20 @@ sp_a = {'hostname': '${ADDRESS}:${PORT}', 'saml_auth': '/sp', 'httpd_user': '${TEST_USER}'} +sp2_g = {'HTTPDCONFD': '${TESTDIR}/${NAME}/conf.d', + 'SAML2_TEMPLATE': '${TESTDIR}/templates/install/saml2/sp.conf', + 'SAML2_CONFFILE': '${TESTDIR}/${NAME}/conf.d/ipsilon-saml.conf', + 'SAML2_HTTPDIR': '${TESTDIR}/${NAME}/saml2'} + +sp2_a = {'hostname': '${ADDRESS}:${PORT}', + 'saml_idp_url': 'http://127.0.0.10:45080/idp1', + 'admin_user': '${TEST_USER}', + 'admin_password': '${TESTDIR}/pw.txt', + 'saml_sp_name': 'sp2', + 'saml_secure_setup': 'False', + 'saml_auth': '/sp', + 'httpd_user': '${TEST_USER}'} + def fixup_sp_httpd(httpdir): location = """ @@ -97,7 +95,7 @@ class IpsilonTest(IpsilonTestBase): print "Starting IDP's httpd server" self.start_http_server(conf, env) - print "Installing SP server" + print "Installing first SP server" name = 'sp1' addr = '127.0.0.11' port = '45081' @@ -105,19 +103,35 @@ class IpsilonTest(IpsilonTestBase): conf = self.setup_sp_server(sp, name, addr, port, env) fixup_sp_httpd(os.path.dirname(conf)) - print "Starting SP's httpd server" + print "Starting first SP's httpd server" + self.start_http_server(conf, env) + + print "Installing second SP server" + name = 'sp2' + addr = '127.0.0.11' + port = '45082' + sp = self.generate_profile(sp2_g, sp2_a, name, addr, port) + with open(os.path.dirname(sp) + '/pw.txt', 'a') as f: + f.write('ipsilon') + conf = self.setup_sp_server(sp, name, addr, port, env) + os.remove(os.path.dirname(sp) + '/pw.txt') + fixup_sp_httpd(os.path.dirname(conf)) + + print "Starting second SP's httpd server" self.start_http_server(conf, env) if __name__ == '__main__': idpname = 'idp1' - spname = 'sp1' + sp1name = 'sp1' + sp2name = 'sp2' user = pwd.getpwuid(os.getuid())[0] sess = HttpSessions() sess.add_server(idpname, 'http://127.0.0.10:45080', user, 'ipsilon') - sess.add_server(spname, 'http://127.0.0.11:45081') + sess.add_server(sp1name, 'http://127.0.0.11:45081') + sess.add_server(sp2name, 'http://127.0.0.11:45082') print "test1: Authenticate to IDP ...", try: @@ -127,15 +141,15 @@ if __name__ == '__main__': sys.exit(1) print " SUCCESS" - print "test1: Add SP Metadata to IDP ...", + print "test1: Add first SP Metadata to IDP ...", try: - sess.add_sp_metadata(idpname, spname) + sess.add_sp_metadata(idpname, sp1name) except Exception, e: # pylint: disable=broad-except print >> sys.stderr, " ERROR: %s" % repr(e) sys.exit(1) print " SUCCESS" - print "test1: Access SP Protected Area ...", + print "test1: Access first SP Protected Area ...", try: page = sess.fetch_page(idpname, 'http://127.0.0.11:45081/sp/') page.expected_value('text()', 'WORKS!') @@ -143,3 +157,22 @@ if __name__ == '__main__': print >> sys.stderr, " ERROR: %s" % repr(e) sys.exit(1) print " SUCCESS" + + print "test1: Access second SP Protected Area ...", + try: + page = sess.fetch_page(idpname, 'http://127.0.0.11:45082/sp/') + page.expected_value('text()', 'WORKS!') + except ValueError, e: + print >> sys.stderr, " ERROR: %s" % repr(e) + sys.exit(1) + print " SUCCESS" + + print "test1: Try authentication failure ...", + newsess = HttpSessions() + newsess.add_server(idpname, 'http://127.0.0.10:45080', user, 'wrong') + try: + newsess.auth_to_idp(idpname) + print >> sys.stderr, " ERROR: Authentication should have failed" + sys.exit(1) + except Exception, e: # pylint: disable=broad-except + print " SUCCESS"