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
10 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}',
32 'server_debugging': 'True'}
35 sp_g = {'HTTPDCONFD': '${TESTDIR}/${NAME}/conf.d',
36 'SAML2_TEMPLATE': '${TESTDIR}/templates/install/saml2/sp.conf',
37 'SAML2_CONFFILE': '${TESTDIR}/${NAME}/conf.d/ipsilon-saml.conf',
38 'SAML2_HTTPDIR': '${TESTDIR}/${NAME}/saml2'}
41 sp_a = {'hostname': '${ADDRESS}:${PORT}',
42 'saml_idp_metadata': 'http://127.0.0.10:45080/idp1/saml2/metadata',
43 'saml_secure_setup': 'False',
45 'httpd_user': '${TEST_USER}'}
48 def fixup_sp_httpd(httpdir):
50 MellonSetEnv "FULLNAME" "fullname"
52 with open(httpdir + '/conf.d/ipsilon-saml.conf', 'r') as f:
54 conf = conf.replace('</Location>', merge, 1)
55 with open(httpdir + '/conf.d/ipsilon-saml.conf', 'w') as f:
60 Alias /sp ${HTTPDIR}/sp
62 <Directory ${HTTPDIR}/sp>
67 t = Template(location)
68 text = t.substitute({'HTTPDIR': httpdir})
69 with open(httpdir + '/conf.d/ipsilon-saml.conf', 'a') as f:
72 index = """<!--#echo var="MELLON_FULLNAME" -->"""
73 os.mkdir(httpdir + '/sp')
74 with open(httpdir + '/sp/index.shtml', 'w') as f:
78 class IpsilonTest(IpsilonTestBase):
81 super(IpsilonTest, self).__init__('attrs', __file__)
83 def setup_servers(self, env=None):
84 print "Installing IDP server"
88 idp = self.generate_profile(idp_g, idp_a, name, addr, port)
89 conf = self.setup_idp_server(idp, name, addr, port, env)
91 print "Starting IDP's httpd server"
92 self.start_http_server(conf, env)
94 print "Installing SP server"
98 sp = self.generate_profile(sp_g, sp_a, name, addr, port)
99 conf = self.setup_sp_server(sp, name, addr, port, env)
100 fixup_sp_httpd(os.path.dirname(conf))
102 print "Starting SP's httpd server"
103 self.start_http_server(conf, env)
106 if __name__ == '__main__':
110 user = pwd.getpwuid(os.getuid())[0]
112 sess = HttpSessions()
113 sess.add_server(idpname, 'http://127.0.0.10:45080', user, 'ipsilon')
114 sess.add_server(spname, 'http://127.0.0.11:45081')
116 print "attrs: Authenticate to IDP ...",
118 sess.auth_to_idp(idpname)
119 except Exception, e: # pylint: disable=broad-except
120 print >> sys.stderr, " ERROR: %s" % repr(e)
124 print "attrs: Add SP Metadata to IDP ...",
126 sess.add_sp_metadata(idpname, spname)
127 except Exception, e: # pylint: disable=broad-except
128 print >> sys.stderr, " ERROR: %s" % repr(e)
132 print "attrs: Access SP Protected Area Variables...",
134 page = sess.fetch_page(idpname,
135 'http://127.0.0.11:45081/sp/index.shtml')
136 page.expected_value('text()', 'Test User %s' % user)
137 except ValueError, e:
138 print >> sys.stderr, " ERROR: %s" % repr(e)