3 # Copyright (C) 2014 Simo Sorce <simo@redhat.com>
5 # see file 'COPYING' for use and warranty information
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 from helpers.common import IpsilonTestBase # pylint: disable=relative-import
22 from helpers.http import HttpSessions # pylint: disable=relative-import
26 from string import Template
29 idp_g = {'TEMPLATES': '${TESTDIR}/templates/install',
30 'CONFDIR': '${TESTDIR}/etc',
31 'DATADIR': '${TESTDIR}/lib',
32 'HTTPDCONFD': '${TESTDIR}/${NAME}/conf.d',
33 'STATICDIR': '${ROOTDIR}',
34 'BINDIR': '${ROOTDIR}/ipsilon',
35 'WSGI_SOCKET_PREFIX': '${TESTDIR}/${NAME}/logs/wsgi'}
38 idp_a = {'hostname': '${ADDRESS}:${PORT}',
39 'users_dburi': 'postgresql://@127.0.0.10:45432/users',
40 'database_url': 'postgresql://@127.0.0.10:45432/%(dbname)s',
41 'session_type': 'sql',
42 'session_dburi': 'postgresql://@127.0.0.10:45432/sessions',
43 'admin_user': '${TEST_USER}',
44 'system_user': '${TEST_USER}',
45 'instance': '${NAME}',
51 'server_debugging': 'True'}
54 sp_g = {'HTTPDCONFD': '${TESTDIR}/${NAME}/conf.d',
55 'SAML2_TEMPLATE': '${TESTDIR}/templates/install/saml2/sp.conf',
56 'SAML2_CONFFILE': '${TESTDIR}/${NAME}/conf.d/ipsilon-saml.conf',
57 'SAML2_HTTPDIR': '${TESTDIR}/${NAME}/saml2'}
60 sp_a = {'hostname': '${ADDRESS}:${PORT}',
61 'saml_idp_metadata': 'http://127.0.0.10:45080/idp1/saml2/metadata',
62 'saml_secure_setup': 'False',
64 'httpd_user': '${TEST_USER}'}
67 def fixup_sp_httpd(httpdir):
70 Alias /sp ${HTTPDIR}/sp
72 <Directory ${HTTPDIR}/sp>
78 t = Template(location)
79 text = t.substitute({'HTTPDIR': httpdir})
80 with open(httpdir + '/conf.d/ipsilon-saml.conf', 'a') as f:
83 os.mkdir(httpdir + '/sp')
84 with open(httpdir + '/sp/index.html', 'w') as f:
88 class IpsilonTest(IpsilonTestBase):
91 super(IpsilonTest, self).__init__('pgdb', __file__)
93 def setup_servers(self, env=None):
95 print "Installing IDP's database server"
96 datadir = os.path.join(self.testdir, 'pgdata')
98 log = os.path.join(self.testdir, 'log/pgdb.log')
101 self.setup_pgdb(datadir, env)
103 print "Starting IDP's database server"
104 self.start_pgdb_server(datadir, rundir, log, addr, port, env)
106 print "Installing IDP server"
110 idp = self.generate_profile(idp_g, idp_a, name, addr, port)
111 conf = self.setup_idp_server(idp, name, addr, port, env)
113 print "Starting IDP's httpd server"
114 self.start_http_server(conf, env)
116 print "Installing SP server"
120 sp = self.generate_profile(sp_g, sp_a, name, addr, port)
121 conf = self.setup_sp_server(sp, name, addr, port, env)
122 fixup_sp_httpd(os.path.dirname(conf))
124 print "Starting SP's httpd server"
125 self.start_http_server(conf, env)
128 if __name__ == '__main__':
132 user = pwd.getpwuid(os.getuid())[0]
134 sess = HttpSessions()
135 sess.add_server(idpname, 'http://127.0.0.10:45080', user, 'ipsilon')
136 sess.add_server(spname, 'http://127.0.0.11:45081')
138 print "test1: Authenticate to IDP ...",
140 sess.auth_to_idp(idpname)
141 except Exception, e: # pylint: disable=broad-except
142 print >> sys.stderr, " ERROR: %s" % repr(e)
146 print "test1: Add SP Metadata to IDP ...",
148 sess.add_sp_metadata(idpname, spname)
149 except Exception, e: # pylint: disable=broad-except
150 print >> sys.stderr, " ERROR: %s" % repr(e)
154 print "test1: Access SP Protected Area ...",
156 page = sess.fetch_page(idpname, 'http://127.0.0.11:45081/sp/')
157 page.expected_value('text()', 'WORKS!')
158 except ValueError, e:
159 print >> sys.stderr, " ERROR: %s" % repr(e)