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 '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}',
31 'server_debugging': 'True'}
34 sp_g = {'HTTPDCONFD': '${TESTDIR}/${NAME}/conf.d',
35 'SAML2_TEMPLATE': '${TESTDIR}/templates/install/saml2/sp.conf',
36 'SAML2_CONFFILE': '${TESTDIR}/${NAME}/conf.d/ipsilon-saml.conf',
37 'SAML2_HTTPDIR': '${TESTDIR}/${NAME}/saml2'}
40 sp_a = {'hostname': '${ADDRESS}:${PORT}',
41 'saml_idp_metadata': 'http://127.0.0.10:45080/idp1/saml2/metadata',
42 'saml_secure_setup': 'False',
44 'httpd_user': '${TEST_USER}'}
47 def fixup_sp_httpd(httpdir):
49 MellonSetEnv "FULLNAME" "fullname"
51 with open(httpdir + '/conf.d/ipsilon-saml.conf', 'r') as f:
53 conf = conf.replace('</Location>', merge, 1)
54 with open(httpdir + '/conf.d/ipsilon-saml.conf', 'w') as f:
59 Alias /sp ${HTTPDIR}/sp
61 <Directory ${HTTPDIR}/sp>
66 t = Template(location)
67 text = t.substitute({'HTTPDIR': httpdir})
68 with open(httpdir + '/conf.d/ipsilon-saml.conf', 'a') as f:
71 index = """<!--#echo var="MELLON_FULLNAME" -->"""
72 os.mkdir(httpdir + '/sp')
73 with open(httpdir + '/sp/index.shtml', 'w') as f:
77 class IpsilonTest(IpsilonTestBase):
80 super(IpsilonTest, self).__init__('attrs', __file__)
82 def setup_servers(self, env=None):
83 print "Installing IDP server"
87 idp = self.generate_profile(idp_g, idp_a, name, addr, port)
88 conf = self.setup_idp_server(idp, name, addr, port, env)
90 print "Starting IDP's httpd server"
91 self.start_http_server(conf, env)
93 print "Installing SP server"
97 sp = self.generate_profile(sp_g, sp_a, name, addr, port)
98 conf = self.setup_sp_server(sp, name, addr, port, env)
99 fixup_sp_httpd(os.path.dirname(conf))
101 print "Starting SP's httpd server"
102 self.start_http_server(conf, env)
105 if __name__ == '__main__':
109 user = pwd.getpwuid(os.getuid())[0]
111 sess = HttpSessions()
112 sess.add_server(idpname, 'http://127.0.0.10:45080', user, 'ipsilon')
113 sess.add_server(spname, 'http://127.0.0.11:45081')
115 print "attrs: Authenticate to IDP ...",
117 sess.auth_to_idp(idpname)
118 except Exception, e: # pylint: disable=broad-except
119 print >> sys.stderr, " ERROR: %s" % repr(e)
123 print "attrs: Add SP Metadata to IDP ...",
125 sess.add_sp_metadata(idpname, spname)
126 except Exception, e: # pylint: disable=broad-except
127 print >> sys.stderr, " ERROR: %s" % repr(e)
131 print "attrs: Access SP Protected Area Variables...",
133 page = sess.fetch_page(idpname,
134 'http://127.0.0.11:45081/sp/index.shtml')
135 page.expected_value('text()', 'Test User %s' % user)
136 except ValueError, e:
137 print >> sys.stderr, " ERROR: %s" % repr(e)