3 # Copyright (C) 2014 Ipsilon project Contributors, for license see COPYING
5 from helpers.common import IpsilonTestBase # pylint: disable=relative-import
6 from helpers.http import HttpSessions # pylint: disable=relative-import
11 from string import Template
13 idp_g = {'TEMPLATES': '${TESTDIR}/templates/install',
14 'CONFDIR': '${TESTDIR}/etc',
15 'DATADIR': '${TESTDIR}/lib',
16 'CACHEDIR': '${TESTDIR}/cache',
17 'HTTPDCONFD': '${TESTDIR}/${NAME}/conf.d',
18 'STATICDIR': '${ROOTDIR}',
19 'BINDIR': '${ROOTDIR}/ipsilon',
20 'WSGI_SOCKET_PREFIX': '${TESTDIR}/${NAME}/logs/wsgi'}
23 idp_a = {'hostname': '${ADDRESS}:${PORT}',
24 'admin_user': '${TEST_USER}',
25 'system_user': '${TEST_USER}',
26 'instance': '${NAME}',
30 'openid_extensions': 'Attribute Exchange,Simple Registration,Teams',
34 'server_debugging': 'True'}
37 def fixup_sp_httpd(httpdir, testdir):
40 WSGIScriptAlias / ${TESTDIR}/blobs/openid_app.py
42 <Directory ${TESTDIR}/blobs>
46 t = Template(client_wsgi)
47 text = t.substitute({'TESTDIR': testdir})
48 with open(httpdir + '/conf.d/ipsilon-openid-client.conf', 'a') as f:
52 class IpsilonTest(IpsilonTestBase):
55 super(IpsilonTest, self).__init__('openid', __file__)
57 def setup_servers(self, env=None):
58 print "Installing IDP server"
62 idp = self.generate_profile(idp_g, idp_a, name, addr, port)
63 conf = self.setup_idp_server(idp, name, addr, port, env)
65 print "Starting IDP's httpd server"
66 self.start_http_server(conf, env)
68 print "Installing first SP server"
72 conf = self.setup_http(name, addr, port)
73 testdir = os.path.dirname(os.path.abspath(inspect.getfile(
74 inspect.currentframe())))
75 fixup_sp_httpd(os.path.dirname(conf), testdir)
77 print "Starting SP's httpd server"
78 self.start_http_server(conf, env)
81 if __name__ == '__main__':
85 user = pwd.getpwuid(os.getuid())[0]
88 sess.add_server(idpname, 'http://127.0.0.10:45080', user, 'ipsilon')
89 sess.add_server(sp1name, 'http://127.0.0.11:45081')
91 print "openid: Authenticate to IDP ...",
93 sess.auth_to_idp(idpname)
94 except Exception as e: # pylint: disable=broad-except
95 print >> sys.stderr, " ERROR: %s" % repr(e)
99 print "openid: Run OpenID Protocol ...",
101 page = sess.fetch_page(idpname,
102 'http://127.0.0.11:45081/?extensions=NO')
103 page.expected_value('text()', 'SUCCESS, WITHOUT EXTENSIONS')
104 except ValueError as e:
105 print >> sys.stderr, " ERROR: %s" % repr(e)
109 print "openid: Run OpenID Protocol with extensions ...",
111 page = sess.fetch_page(idpname,
112 'http://127.0.0.11:45081/?extensions=YES')
113 page.expected_value('text()', 'SUCCESS, WITH EXTENSIONS')
114 except ValueError as e:
115 print >> sys.stderr, " ERROR: %s" % repr(e)