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 'HTTPDCONFD': '${TESTDIR}/${NAME}/conf.d',
17 'STATICDIR': '${ROOTDIR}',
18 'BINDIR': '${ROOTDIR}/ipsilon',
19 'WSGI_SOCKET_PREFIX': '${TESTDIR}/${NAME}/logs/wsgi'}
22 idp_a = {'hostname': '${ADDRESS}:${PORT}',
23 'admin_user': '${TEST_USER}',
24 'system_user': '${TEST_USER}',
25 'instance': '${NAME}',
29 'openid_extensions': 'Attribute Exchange,Simple Registration,Teams',
33 'server_debugging': 'True'}
36 def fixup_sp_httpd(httpdir, testdir):
39 WSGIScriptAlias / ${TESTDIR}/blobs/openid_app.py
41 <Directory ${TESTDIR}/blobs>
45 t = Template(client_wsgi)
46 text = t.substitute({'TESTDIR': testdir})
47 with open(httpdir + '/conf.d/ipsilon-openid-client.conf', 'a') as f:
51 class IpsilonTest(IpsilonTestBase):
54 super(IpsilonTest, self).__init__('openid', __file__)
56 def setup_servers(self, env=None):
57 print "Installing IDP server"
61 idp = self.generate_profile(idp_g, idp_a, name, addr, port)
62 conf = self.setup_idp_server(idp, name, addr, port, env)
64 print "Starting IDP's httpd server"
65 self.start_http_server(conf, env)
67 print "Installing first SP server"
71 conf = self.setup_http(name, addr, port)
72 testdir = os.path.dirname(os.path.abspath(inspect.getfile(
73 inspect.currentframe())))
74 fixup_sp_httpd(os.path.dirname(conf), testdir)
76 print "Starting SP's httpd server"
77 self.start_http_server(conf, env)
80 if __name__ == '__main__':
84 user = pwd.getpwuid(os.getuid())[0]
87 sess.add_server(idpname, 'http://127.0.0.10:45080', user, 'ipsilon')
88 sess.add_server(sp1name, 'http://127.0.0.11:45081')
90 print "openid: Authenticate to IDP ...",
92 sess.auth_to_idp(idpname)
93 except Exception as e: # pylint: disable=broad-except
94 print >> sys.stderr, " ERROR: %s" % repr(e)
98 print "openid: Run OpenID Protocol ...",
100 page = sess.fetch_page(idpname,
101 'http://127.0.0.11:45081/?extensions=NO')
102 page.expected_value('text()', 'SUCCESS, WITHOUT EXTENSIONS')
103 except ValueError as e:
104 print >> sys.stderr, " ERROR: %s" % repr(e)
108 print "openid: Run OpenID Protocol with extensions ...",
110 page = sess.fetch_page(idpname,
111 'http://127.0.0.11:45081/?extensions=YES')
112 page.expected_value('text()', 'SUCCESS, WITH EXTENSIONS')
113 except ValueError as e:
114 print >> sys.stderr, " ERROR: %s" % repr(e)