3 # Copyright (C) 2014 Simo Sorce <simo@redhat.com>
5 # see file 'COPYING' for use and warranty information
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 from helpers.common import IpsilonTestBase # pylint: disable=relative-import
22 from helpers.http import HttpSessions # pylint: disable=relative-import
27 from string import Template
31 idpaddr = '127.0.0.10'
38 idp_g = {'TEMPLATES': '${TESTDIR}/templates/install',
39 'CONFDIR': '${TESTDIR}/etc',
40 'DATADIR': '${TESTDIR}/lib',
41 'HTTPDCONFD': '${TESTDIR}/${NAME}/conf.d',
42 'STATICDIR': '${ROOTDIR}',
43 'BINDIR': '${ROOTDIR}/ipsilon',
44 'WSGI_SOCKET_PREFIX': '${TESTDIR}/${NAME}/logs/wsgi'}
47 idp_a = {'hostname': '${ADDRESS}:${PORT}',
48 'admin_user': '${TEST_USER}',
49 'system_user': '${TEST_USER}',
50 'instance': '${NAME}',
56 'server_debugging': 'True'}
60 global enabled = testauth
62 global enabled = openid,saml2
63 openid endpoint url = ${IDPURI}/openid/
64 openid identity_url_template = ${IDPURI}/openid/id/%(username)s
65 saml2 idp key file = ${TESTDIR}/lib/${NAME}/saml2/idp.key
66 saml2 idp storage path = ${TESTDIR}/lib/${NAME}/saml2
67 saml2 idp metadata file = metadata.xml
68 saml2 idp certificate file = ${TESTDIR}/lib/${NAME}/saml2/idp.pem
70 811d0231-9362-46c9-a105-a01a64818904 id = http://${SPADDR}:${SPPORT}/saml2
71 811d0231-9362-46c9-a105-a01a64818904 type = SP
72 811d0231-9362-46c9-a105-a01a64818904 name = ${SPNAME}
73 811d0231-9362-46c9-a105-a01a64818904 metadata = ${SPMETA}
76 sp_g = {'HTTPDCONFD': '${TESTDIR}/${NAME}/conf.d',
77 'SAML2_TEMPLATE': '${TESTDIR}/templates/install/saml2/sp.conf',
78 'SAML2_CONFFILE': '${TESTDIR}/${NAME}/conf.d/ipsilon-saml.conf',
79 'SAML2_HTTPDIR': '${TESTDIR}/${NAME}/saml2'}
82 sp_a = {'hostname': '${ADDRESS}:${PORT}',
83 'saml_idp_metadata': '${TESTDIR}/lib/idp1/saml2/metadata.xml',
84 'saml_secure_setup': 'False',
86 'httpd_user': '${TEST_USER}'}
89 def fixup_sp_httpd(httpdir):
92 Alias /sp ${HTTPDIR}/sp
94 <Directory ${HTTPDIR}/sp>
100 t = Template(location)
101 text = t.substitute({'HTTPDIR': httpdir})
102 with open(httpdir + '/conf.d/ipsilon-saml.conf', 'a') as f:
105 os.mkdir(httpdir + '/sp')
106 with open(httpdir + '/sp/index.html', 'w') as f:
110 def fixup_idp_conf(testdir):
112 with open(os.path.join(testdir, spname, 'saml2',
113 '%s:%s' % (spaddr, spport), 'metadata.xml')) as f:
115 spmeta = spmeta.replace("\n", "")
117 idpuri = "http://%s:%s/%s" % (idpaddr, idpport, idpname)
119 t = Template(idp_file_conf)
120 text = t.substitute({'NAME': idpname, 'IDPURI': idpuri,
121 'SPNAME': spname, 'SPADDR': spaddr, 'SPPORT': spport,
122 'SPMETA': spmeta, 'TESTDIR': testdir})
124 adminconf = os.path.join(testdir, 'etc/admin.conf')
125 with open(adminconf, 'w+') as f:
128 ipsilonconf = os.path.join(testdir, 'etc', idpname, 'ipsilon.conf')
129 newconf = ConfigParser.ConfigParser()
130 with open(ipsilonconf, 'r') as f:
132 with open(ipsilonconf, 'w+') as f:
133 newconf.set('global', 'admin.config.db',
134 '"configfile://%s"' % adminconf)
137 os.remove(os.path.join(testdir, 'lib', idpname, 'adminconfig.sqlite'))
140 class IpsilonTest(IpsilonTestBase):
143 super(IpsilonTest, self).__init__('fconf', __file__)
145 def setup_servers(self, env=None):
146 print "Installing IDP server"
147 idp = self.generate_profile(idp_g, idp_a, idpname, idpaddr, idpport)
148 idpconf = self.setup_idp_server(idp, idpname, idpaddr, idpport, env)
150 print "Installing SP server"
151 sp = self.generate_profile(sp_g, sp_a, spname, spaddr, spport)
152 spconf = self.setup_sp_server(sp, spname, spaddr, spport, env)
153 fixup_sp_httpd(os.path.dirname(spconf))
155 fixup_idp_conf(self.testdir)
157 print "Starting IDP's httpd server"
158 self.start_http_server(idpconf, env)
160 print "Starting SP's httpd server"
161 self.start_http_server(spconf, env)
164 if __name__ == '__main__':
166 user = pwd.getpwuid(os.getuid())[0]
168 sess = HttpSessions()
169 sess.add_server(idpname, 'http://127.0.0.10:45080', user, 'ipsilon')
170 sess.add_server(spname, 'http://127.0.0.11:45081')
172 print "test1: Access SP Protected Area ...",
174 page = sess.fetch_page(idpname, 'http://127.0.0.11:45081/sp/')
175 page.expected_value('text()', 'WORKS!')
176 except ValueError, e:
177 print >> sys.stderr, " ERROR: %s" % repr(e)