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
27 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 'admin_user': '${TEST_USER}',
40 'system_user': '${TEST_USER}',
41 'instance': '${NAME}',
45 'openid_extensions': 'Attribute Exchange,Simple Registration,Teams',
49 'server_debugging': 'True'}
52 def fixup_sp_httpd(httpdir, testdir):
55 WSGIScriptAlias / ${TESTDIR}/blobs/openid_app.py
57 <Directory ${TESTDIR}/blobs>
61 t = Template(client_wsgi)
62 text = t.substitute({'TESTDIR': testdir})
63 with open(httpdir + '/conf.d/ipsilon-openid-client.conf', 'a') as f:
67 class IpsilonTest(IpsilonTestBase):
70 super(IpsilonTest, self).__init__('openid', __file__)
72 def setup_servers(self, env=None):
73 print "Installing IDP server"
77 idp = self.generate_profile(idp_g, idp_a, name, addr, port)
78 conf = self.setup_idp_server(idp, name, addr, port, env)
80 print "Starting IDP's httpd server"
81 self.start_http_server(conf, env)
83 print "Installing first SP server"
87 conf = self.setup_http(name, addr, port)
88 testdir = os.path.dirname(os.path.abspath(inspect.getfile(
89 inspect.currentframe())))
90 fixup_sp_httpd(os.path.dirname(conf), testdir)
92 print "Starting SP's httpd server"
93 self.start_http_server(conf, env)
96 if __name__ == '__main__':
100 user = pwd.getpwuid(os.getuid())[0]
102 sess = HttpSessions()
103 sess.add_server(idpname, 'http://127.0.0.10:45080', user, 'ipsilon')
104 sess.add_server(sp1name, 'http://127.0.0.11:45081')
106 print "openid: Authenticate to IDP ...",
108 sess.auth_to_idp(idpname)
109 except Exception as e: # pylint: disable=broad-except
110 print >> sys.stderr, " ERROR: %s" % repr(e)
114 print "openid: Run OpenID Protocol ...",
116 page = sess.fetch_page(idpname,
117 'http://127.0.0.11:45081/?extensions=NO')
118 page.expected_value('text()', 'SUCCESS, WITHOUT EXTENSIONS')
119 except ValueError as e:
120 print >> sys.stderr, " ERROR: %s" % repr(e)
124 print "openid: Run OpenID Protocol with extensions ...",
126 page = sess.fetch_page(idpname,
127 'http://127.0.0.11:45081/?extensions=YES')
128 page.expected_value('text()', 'SUCCESS, WITH EXTENSIONS')
129 except ValueError as e:
130 print >> sys.stderr, " ERROR: %s" % repr(e)