3 # Copyright (C) 2015 Ipsilon project Contributors, for license see COPYING
5 # Test that we get a reasonable error back when the LDAP backend is down
7 from helpers.common import IpsilonTestBase # pylint: disable=relative-import
8 from helpers.http import HttpSessions # pylint: disable=relative-import
11 from string import Template
14 idp_g = {'TEMPLATES': '${TESTDIR}/templates/install',
15 'CONFDIR': '${TESTDIR}/etc',
16 'DATADIR': '${TESTDIR}/lib',
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': 'tuser',
25 'system_user': '${TEST_USER}',
26 'instance': '${NAME}',
32 'ldap_server_url': 'ldap://${ADDRESS}:45389/',
33 'ldap_bind_dn_template':
34 'uid=%(username)s,ou=People,dc=example,dc=com',
35 'ldap_tls_level': 'NoTLS',
36 'server_debugging': 'True'}
39 sp_g = {'HTTPDCONFD': '${TESTDIR}/${NAME}/conf.d',
40 'SAML2_TEMPLATE': '${TESTDIR}/templates/install/saml2/sp.conf',
41 'SAML2_CONFFILE': '${TESTDIR}/${NAME}/conf.d/ipsilon-saml.conf',
42 'SAML2_HTTPDIR': '${TESTDIR}/${NAME}/saml2'}
45 sp_a = {'hostname': '${ADDRESS}:${PORT}',
46 'saml_idp_metadata': 'http://127.0.0.10:45080/idp1/saml2/metadata',
47 'saml_secure_setup': 'False',
49 'httpd_user': '${TEST_USER}'}
52 def fixup_sp_httpd(httpdir):
54 MellonSetEnv "GROUPS" "groups"
57 with open(httpdir + '/conf.d/ipsilon-saml.conf', 'r') as f:
59 conf = conf.replace('</Location>', merge, 1)
60 with open(httpdir + '/conf.d/ipsilon-saml.conf', 'w') as f:
65 Alias /sp ${HTTPDIR}/sp
67 <Directory ${HTTPDIR}/sp>
72 t = Template(location)
73 text = t.substitute({'HTTPDIR': httpdir})
74 with open(httpdir + '/conf.d/ipsilon-saml.conf', 'a') as f:
77 index = """<!--#echo var="MELLON_GROUPS" -->"""
78 os.mkdir(httpdir + '/sp')
79 with open(httpdir + '/sp/index.shtml', 'w') as f:
83 class IpsilonTest(IpsilonTestBase):
86 super(IpsilonTest, self).__init__('ldapdown', __file__)
88 def setup_servers(self, env=None):
90 print "Installing IDP's ldap server"
93 conf = self.setup_ldap(env)
95 print "Not starting IDP's ldap server"
97 print "Installing IDP server"
101 idp = self.generate_profile(idp_g, idp_a, name, addr, port)
102 conf = self.setup_idp_server(idp, name, addr, port, env)
104 print "Starting IDP's httpd server"
105 self.start_http_server(conf, env)
107 print "Installing SP server"
111 sp = self.generate_profile(sp_g, sp_a, name, addr, port)
112 conf = self.setup_sp_server(sp, name, addr, port, env)
113 fixup_sp_httpd(os.path.dirname(conf))
115 print "Starting SP's httpd server"
116 self.start_http_server(conf, env)
119 if __name__ == '__main__':
125 sess = HttpSessions()
126 sess.add_server(idpname, 'http://127.0.0.10:45080', user, 'tuser')
127 sess.add_server(spname, 'http://127.0.0.11:45081')
129 print "ldapdown: Authenticate to IDP with no LDAP backend...",
133 rule='//div[@class="alert alert-danger"]/p/text()',
134 expected="Internal system error"
136 except Exception, e: # pylint: disable=broad-except
137 print >> sys.stderr, " ERROR: %s" % repr(e)