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 'CACHEDIR': '${TESTDIR}/cache',
18 'HTTPDCONFD': '${TESTDIR}/${NAME}/conf.d',
19 'STATICDIR': '${ROOTDIR}',
20 'BINDIR': '${ROOTDIR}/ipsilon',
21 'WSGI_SOCKET_PREFIX': '${TESTDIR}/${NAME}/logs/wsgi'}
24 idp_a = {'hostname': '${ADDRESS}:${PORT}',
25 'admin_user': 'tuser',
26 'system_user': '${TEST_USER}',
27 'instance': '${NAME}',
33 'ldap_server_url': 'ldap://${ADDRESS}:45389/',
34 'ldap_bind_dn_template':
35 'uid=%(username)s,ou=People,dc=example,dc=com',
36 'ldap_tls_level': 'NoTLS',
37 'server_debugging': 'True'}
40 sp_g = {'HTTPDCONFD': '${TESTDIR}/${NAME}/conf.d',
41 'SAML2_TEMPLATE': '${TESTDIR}/templates/install/saml2/sp.conf',
42 'SAML2_CONFFILE': '${TESTDIR}/${NAME}/conf.d/ipsilon-saml.conf',
43 'SAML2_HTTPDIR': '${TESTDIR}/${NAME}/saml2'}
46 sp_a = {'hostname': '${ADDRESS}:${PORT}',
47 'saml_idp_metadata': 'http://127.0.0.10:45080/idp1/saml2/metadata',
48 'saml_secure_setup': 'False',
50 'httpd_user': '${TEST_USER}'}
53 def fixup_sp_httpd(httpdir):
55 MellonSetEnv "GROUPS" "groups"
58 with open(httpdir + '/conf.d/ipsilon-saml.conf', 'r') as f:
60 conf = conf.replace('</Location>', merge, 1)
61 with open(httpdir + '/conf.d/ipsilon-saml.conf', 'w') as f:
66 Alias /sp ${HTTPDIR}/sp
68 <Directory ${HTTPDIR}/sp>
73 t = Template(location)
74 text = t.substitute({'HTTPDIR': httpdir})
75 with open(httpdir + '/conf.d/ipsilon-saml.conf', 'a') as f:
78 index = """<!--#echo var="MELLON_GROUPS" -->"""
79 os.mkdir(httpdir + '/sp')
80 with open(httpdir + '/sp/index.shtml', 'w') as f:
84 class IpsilonTest(IpsilonTestBase):
87 super(IpsilonTest, self).__init__('ldapdown', __file__)
89 def setup_servers(self, env=None):
91 print "Installing IDP's ldap server"
94 conf = self.setup_ldap(env)
96 print "Not starting IDP's ldap server"
98 print "Installing IDP server"
102 idp = self.generate_profile(idp_g, idp_a, name, addr, port)
103 conf = self.setup_idp_server(idp, name, addr, port, env)
105 print "Starting IDP's httpd server"
106 self.start_http_server(conf, env)
108 print "Installing SP server"
112 sp = self.generate_profile(sp_g, sp_a, name, addr, port)
113 conf = self.setup_sp_server(sp, name, addr, port, env)
114 fixup_sp_httpd(os.path.dirname(conf))
116 print "Starting SP's httpd server"
117 self.start_http_server(conf, env)
120 if __name__ == '__main__':
126 sess = HttpSessions()
127 sess.add_server(idpname, 'http://127.0.0.10:45080', user, 'tuser')
128 sess.add_server(spname, 'http://127.0.0.11:45081')
130 print "ldapdown: Authenticate to IDP with no LDAP backend...",
134 rule='//div[@class="alert alert-danger"]/p/text()',
135 expected="Internal system error"
137 except Exception, e: # pylint: disable=broad-except
138 print >> sys.stderr, " ERROR: %s" % repr(e)