summaryrefslogtreecommitdiffstats
path: root/bindings
diff options
context:
space:
mode:
authorFrederic Peters <fpeters@entrouvert.com>2008-04-29 12:05:38 +0000
committerFrederic Peters <fpeters@entrouvert.com>2008-04-29 12:05:38 +0000
commitb413aa153384e789a3ed42c1ebbee97fad892345 (patch)
tree0815015d6e03c322bac41acfae65d42b5a1b8072 /bindings
parenta305a587f82f6a174db607519ab61ed815156079 (diff)
downloadlasso-b413aa153384e789a3ed42c1ebbee97fad892345.tar.gz
lasso-b413aa153384e789a3ed42c1ebbee97fad892345.tar.xz
lasso-b413aa153384e789a3ed42c1ebbee97fad892345.zip
[project @ fpeters@0d.be-20071113192919-3g05qazwjjhivlsh]
ported old test cases to the new binding Original author: Frederic Peters <fpeters@0d.be> Date: 2007-11-13 20:29:19.859000+01:00
Diffstat (limited to 'bindings')
-rw-r--r--bindings/python/Makefile.am2
-rw-r--r--bindings/python/tests/Makefile.am4
-rwxr-xr-xbindings/python/tests/binding_tests.py258
-rwxr-xr-xbindings/python/tests/profiles_tests.py358
4 files changed, 622 insertions, 0 deletions
diff --git a/bindings/python/Makefile.am b/bindings/python/Makefile.am
index a1d1928d..b2a1e99d 100644
--- a/bindings/python/Makefile.am
+++ b/bindings/python/Makefile.am
@@ -1,3 +1,5 @@
+SUBDIRS = tests
+
if PYTHON_ENABLED
INCLUDES = -I$(top_srcdir) \
-I$(top_builddir) \
diff --git a/bindings/python/tests/Makefile.am b/bindings/python/tests/Makefile.am
new file mode 100644
index 00000000..332ef1b2
--- /dev/null
+++ b/bindings/python/tests/Makefile.am
@@ -0,0 +1,4 @@
+if PYTHON_ENABLED
+TESTS = profiles_tests.py binding_tests.py
+endif
+
diff --git a/bindings/python/tests/binding_tests.py b/bindings/python/tests/binding_tests.py
new file mode 100755
index 00000000..67d2601e
--- /dev/null
+++ b/bindings/python/tests/binding_tests.py
@@ -0,0 +1,258 @@
+#! /usr/bin/env python
+# -*- coding: UTF-8 -*-
+#
+# $Id: binding_tests.py 3283 2007-06-11 09:10:18Z dlaniel $
+#
+# Python unit tests for Lasso library
+#
+# Copyright (C) 2004-2007 Entr'ouvert
+# http://lasso.entrouvert.org
+#
+# Authors: See AUTHORS file in top-level directory.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+import unittest
+import sys
+import os
+
+if not '..' in sys.path:
+ sys.path.insert(0, '..')
+if not '../.libs' in sys.path:
+ sys.path.insert(0, '../.libs')
+
+import lasso
+
+try:
+ dataDir
+except NameError:
+ dataDir = '../../../tests/data'
+
+
+class BindingTestCase(unittest.TestCase):
+ def test01(self):
+ """Create and delete nodes."""
+
+ authnRequest = lasso.LibAuthnRequest()
+ del authnRequest
+
+ def test02(self):
+ """Get & set simple attributes of nodes."""
+
+ authnRequest = lasso.LibAuthnRequest()
+
+ # Test a string attribute.
+ self.failUnlessEqual(authnRequest.consent, None)
+ authnRequest.consent = lasso.LIB_CONSENT_OBTAINED
+ self.failUnlessEqual(authnRequest.consent, lasso.LIB_CONSENT_OBTAINED)
+ authnRequest.consent = None
+ self.failUnlessEqual(authnRequest.consent, None)
+
+ # Test a renamed string attribute.
+ self.failUnlessEqual(authnRequest.relayState, None)
+ authnRequest.relayState = 'Hello World!'
+ self.failUnlessEqual(authnRequest.relayState, 'Hello World!')
+ authnRequest.relayState = None
+ self.failUnlessEqual(authnRequest.relayState, None)
+
+ # Test an integer attribute.
+ self.failUnlessEqual(authnRequest.majorVersion, 0)
+ authnRequest.majorVersion = 314
+ self.failUnlessEqual(authnRequest.majorVersion, 314)
+
+ del authnRequest
+
+ def test03(self):
+ """Get & set attributes of nodes of type string list."""
+
+ authnRequest = lasso.LibAuthnRequest()
+
+ self.failUnlessEqual(authnRequest.respondWith, None)
+
+ respondWith = []
+ self.failUnlessEqual(len(respondWith), 0)
+ respondWith.append('first string')
+ self.failUnlessEqual(len(respondWith), 1)
+ self.failUnlessEqual(respondWith[0], 'first string')
+ respondWith.append('second string')
+ self.failUnlessEqual(len(respondWith), 2)
+ self.failUnlessEqual(respondWith[0], 'first string')
+ self.failUnlessEqual(respondWith[1], 'second string')
+ respondWith.append('third string')
+ self.failUnlessEqual(len(respondWith), 3)
+ self.failUnlessEqual(respondWith[0], 'first string')
+ self.failUnlessEqual(respondWith[1], 'second string')
+ self.failUnlessEqual(respondWith[2], 'third string')
+ authnRequest.respondWith = tuple(respondWith)
+ self.failUnlessEqual(authnRequest.respondWith[0], 'first string')
+ self.failUnlessEqual(authnRequest.respondWith[1], 'second string')
+ self.failUnlessEqual(authnRequest.respondWith[2], 'third string')
+ self.failUnlessEqual(respondWith[0], 'first string')
+ self.failUnlessEqual(respondWith[1], 'second string')
+ self.failUnlessEqual(respondWith[2], 'third string')
+ del respondWith
+ self.failUnlessEqual(authnRequest.respondWith[0], 'first string')
+ self.failUnlessEqual(authnRequest.respondWith[1], 'second string')
+ self.failUnlessEqual(authnRequest.respondWith[2], 'third string')
+ respondWith = authnRequest.respondWith
+ self.failUnlessEqual(respondWith[0], 'first string')
+ self.failUnlessEqual(respondWith[1], 'second string')
+ self.failUnlessEqual(respondWith[2], 'third string')
+ del respondWith
+ self.failUnlessEqual(authnRequest.respondWith[0], 'first string')
+ self.failUnlessEqual(authnRequest.respondWith[1], 'second string')
+ self.failUnlessEqual(authnRequest.respondWith[2], 'third string')
+ authnRequest.respondWith = None
+ self.failUnlessEqual(authnRequest.respondWith, None)
+
+ del authnRequest
+
+ def test04(self):
+ """Get & set attributes of nodes of type node list."""
+
+ response = lasso.SamlpResponse()
+
+ self.failUnlessEqual(response.assertion, None)
+
+ assertions = []
+ self.failUnlessEqual(len(assertions), 0)
+ assertion1 = lasso.SamlAssertion()
+ assertion1.assertionId = 'assertion 1'
+ assertions.append(assertion1)
+ self.failUnlessEqual(len(assertions), 1)
+ self.failUnlessEqual(assertions[0].assertionId, 'assertion 1')
+ self.failUnlessEqual(assertions[0].assertionId, 'assertion 1')
+ assertion2 = lasso.SamlAssertion()
+ assertion2.assertionId = 'assertion 2'
+ assertions.append(assertion2)
+ self.failUnlessEqual(len(assertions), 2)
+ self.failUnlessEqual(assertions[0].assertionId, 'assertion 1')
+ self.failUnlessEqual(assertions[1].assertionId, 'assertion 2')
+ assertion3 = lasso.SamlAssertion()
+ assertion3.assertionId = 'assertion 3'
+ assertions.append(assertion3)
+ self.failUnlessEqual(len(assertions), 3)
+ self.failUnlessEqual(assertions[0].assertionId, 'assertion 1')
+ self.failUnlessEqual(assertions[1].assertionId, 'assertion 2')
+ self.failUnlessEqual(assertions[2].assertionId, 'assertion 3')
+ response.assertion = tuple(assertions)
+ self.failUnlessEqual(response.assertion[0].assertionId, 'assertion 1')
+ self.failUnlessEqual(response.assertion[1].assertionId, 'assertion 2')
+ self.failUnlessEqual(response.assertion[2].assertionId, 'assertion 3')
+ self.failUnlessEqual(assertions[0].assertionId, 'assertion 1')
+ self.failUnlessEqual(assertions[1].assertionId, 'assertion 2')
+ self.failUnlessEqual(assertions[2].assertionId, 'assertion 3')
+ del assertions
+ self.failUnlessEqual(response.assertion[0].assertionId, 'assertion 1')
+ self.failUnlessEqual(response.assertion[1].assertionId, 'assertion 2')
+ self.failUnlessEqual(response.assertion[2].assertionId, 'assertion 3')
+ assertions = response.assertion
+ self.failUnlessEqual(assertions[0].assertionId, 'assertion 1')
+ self.failUnlessEqual(assertions[1].assertionId, 'assertion 2')
+ self.failUnlessEqual(assertions[2].assertionId, 'assertion 3')
+ del assertions
+ self.failUnlessEqual(response.assertion[0].assertionId, 'assertion 1')
+ self.failUnlessEqual(response.assertion[1].assertionId, 'assertion 2')
+ self.failUnlessEqual(response.assertion[2].assertionId, 'assertion 3')
+ response.assertion = None
+ self.failUnlessEqual(response.assertion, None)
+
+ del response
+
+ def test05(self):
+ """Get & set attributes of nodes of type XML list."""
+
+ authnRequest = lasso.LibAuthnRequest()
+
+ self.failUnlessEqual(authnRequest.extension, None)
+
+ actionString1 = """\
+<lib:Extension xmlns:lib="urn:liberty:iff:2003-08">
+ <action>do 1</action>
+</lib:Extension>"""
+ actionString2 = """\
+<lib:Extension xmlns:lib="urn:liberty:iff:2003-08">
+ <action>do 2</action>
+</lib:Extension>"""
+ actionString3 = """\
+<lib:Extension xmlns:lib="urn:liberty:iff:2003-08">
+ <action>do 3</action>
+</lib:Extension>"""
+ extension = []
+ self.failUnlessEqual(len(extension), 0)
+ extension.append(actionString1)
+ self.failUnlessEqual(len(extension), 1)
+ self.failUnlessEqual(extension[0], actionString1)
+ self.failUnlessEqual(extension[0], actionString1)
+ extension.append(actionString2)
+ self.failUnlessEqual(len(extension), 2)
+ self.failUnlessEqual(extension[0], actionString1)
+ self.failUnlessEqual(extension[1], actionString2)
+ extension.append(actionString3)
+ self.failUnlessEqual(len(extension), 3)
+ self.failUnlessEqual(extension[0], actionString1)
+ self.failUnlessEqual(extension[1], actionString2)
+ self.failUnlessEqual(extension[2], actionString3)
+ authnRequest.extension = tuple(extension)
+ self.failUnlessEqual(authnRequest.extension[0], actionString1)
+ self.failUnlessEqual(authnRequest.extension[1], actionString2)
+ self.failUnlessEqual(authnRequest.extension[2], actionString3)
+ self.failUnlessEqual(extension[0], actionString1)
+ self.failUnlessEqual(extension[1], actionString2)
+ self.failUnlessEqual(extension[2], actionString3)
+ del extension
+ self.failUnlessEqual(authnRequest.extension[0], actionString1)
+ self.failUnlessEqual(authnRequest.extension[1], actionString2)
+ self.failUnlessEqual(authnRequest.extension[2], actionString3)
+ extension = authnRequest.extension
+ self.failUnlessEqual(extension[0], actionString1)
+ self.failUnlessEqual(extension[1], actionString2)
+ self.failUnlessEqual(extension[2], actionString3)
+ del extension
+ self.failUnlessEqual(authnRequest.extension[0], actionString1)
+ self.failUnlessEqual(authnRequest.extension[1], actionString2)
+ self.failUnlessEqual(authnRequest.extension[2], actionString3)
+ authnRequest.extension = None
+ self.failUnlessEqual(authnRequest.extension, None)
+
+ del authnRequest
+
+ def test06(self):
+ """Get & set attributes of nodes of type node."""
+
+ login = lasso.Login(lasso.Server(
+ os.path.join(dataDir, 'sp1-la/metadata.xml'),
+ os.path.join(dataDir, 'sp1-la/private-key-raw.pem'),
+ None,
+ os.path.join(dataDir, 'sp1-la/certificate.pem')))
+
+ self.failUnlessEqual(login.request, None)
+ login.request = lasso.LibAuthnRequest()
+ login.request.consent = lasso.LIB_CONSENT_OBTAINED
+ self.failUnlessEqual(login.request.consent, lasso.LIB_CONSENT_OBTAINED)
+ login.request = None
+ self.failUnlessEqual(login.request, None)
+
+ del login
+
+
+bindingSuite = unittest.makeSuite(BindingTestCase, 'test')
+
+allTests = unittest.TestSuite((bindingSuite, ))
+
+if __name__ == '__main__':
+ sys.exit(not unittest.TextTestRunner(verbosity = 2).run(allTests).wasSuccessful())
+
diff --git a/bindings/python/tests/profiles_tests.py b/bindings/python/tests/profiles_tests.py
new file mode 100755
index 00000000..40b917d2
--- /dev/null
+++ b/bindings/python/tests/profiles_tests.py
@@ -0,0 +1,358 @@
+#! /usr/bin/env python
+# -*- coding: UTF-8 -*-
+#
+# $Id: profiles_tests.py 3254 2007-06-05 21:23:57Z fpeters $
+#
+# Python unit tests for Lasso library
+#
+# Copyright (C) 2004-2007 Entr'ouvert
+# http://lasso.entrouvert.org
+#
+# Authors: See AUTHORS file in top-level directory.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+import os
+import unittest
+import sys
+
+if not '..' in sys.path:
+ sys.path.insert(0, '..')
+if not '../.libs' in sys.path:
+ sys.path.insert(0, '../.libs')
+
+import lasso
+
+
+try:
+ dataDir
+except NameError:
+ dataDir = '../../../tests/data'
+
+
+class ServerTestCase(unittest.TestCase):
+ def test01(self):
+ """Server construction, dump & newFromDump."""
+
+ lassoServer = lasso.Server(
+ os.path.join(dataDir, 'sp1-la/metadata.xml'),
+ os.path.join(dataDir, 'sp1-la/private-key-raw.pem'),
+ None,
+ os.path.join(dataDir, 'sp1-la/certificate.pem'))
+ lassoServer.addProvider(
+ lasso.PROVIDER_ROLE_IDP,
+ os.path.join(dataDir, 'idp1-la/metadata.xml'),
+ os.path.join(dataDir, 'idp1-la/public-key.pem'),
+ os.path.join(dataDir, 'idp1-la/certificate.pem'))
+ dump = lassoServer.dump()
+ lassoServer2 = lassoServer.newFromDump(dump)
+ dump2 = lassoServer2.dump()
+ self.failUnlessEqual(dump, dump2)
+
+ def test02(self):
+ """Server construction without argument, dump & newFromDump."""
+
+ lassoServer = lasso.Server(
+ os.path.join(dataDir, 'sp1-la/metadata.xml'))
+ lassoServer.addProvider(
+ lasso.PROVIDER_ROLE_IDP,
+ os.path.join(dataDir, 'idp1-la/metadata.xml'),
+ os.path.join(dataDir, 'idp1-la/public-key.pem'))
+ dump = lassoServer.dump()
+ lassoServer2 = lassoServer.newFromDump(dump)
+ dump2 = lassoServer2.dump()
+ self.failUnlessEqual(dump, dump2)
+
+
+class LoginTestCase(unittest.TestCase):
+ def test01(self):
+ """SP login; testing access to authentication request."""
+
+ lassoServer = lasso.Server(
+ os.path.join(dataDir, 'sp1-la/metadata.xml'),
+ os.path.join(dataDir, 'sp1-la/private-key-raw.pem'),
+ None,
+ os.path.join(dataDir, 'sp1-la/certificate.pem'))
+ lassoServer.addProvider(
+ lasso.PROVIDER_ROLE_IDP,
+ os.path.join(dataDir, 'idp1-la/metadata.xml'),
+ os.path.join(dataDir, 'idp1-la/public-key.pem'),
+ os.path.join(dataDir, 'idp1-la/certificate.pem'))
+ login = lasso.Login(lassoServer)
+ login.initAuthnRequest()
+ login.request
+ login.request.protocolProfile = lasso.LIB_PROTOCOL_PROFILE_BRWS_ART
+ self.failUnlessEqual(login.request.protocolProfile, lasso.LIB_PROTOCOL_PROFILE_BRWS_ART)
+
+ def test02(self):
+ """SP login; testing processing of an empty Response."""
+
+ lassoServer = lasso.Server(
+ os.path.join(dataDir, 'sp1-la/metadata.xml'),
+ os.path.join(dataDir, 'sp1-la/private-key-raw.pem'),
+ None,
+ os.path.join(dataDir, 'sp1-la/certificate.pem'))
+ lassoServer.addProvider(
+ lasso.PROVIDER_ROLE_IDP,
+ os.path.join(dataDir, 'idp1-la/metadata.xml'),
+ os.path.join(dataDir, 'idp1-la/public-key.pem'),
+ os.path.join(dataDir, 'idp1-la/certificate.pem'))
+ login = lasso.Login(lassoServer)
+ try:
+ login.processResponseMsg('')
+ except lasso.Error, error:
+ if error[0] != lasso.PROFILE_ERROR_INVALID_MSG:
+ raise
+
+ def test03(self):
+ """Conversion of a lib:AuthnRequest with an AuthnContext into a query and back."""
+
+ sp = lasso.Server(
+ os.path.join(dataDir, 'sp1-la/metadata.xml'),
+ os.path.join(dataDir, 'sp1-la/private-key-raw.pem'),
+ None,
+ os.path.join(dataDir, 'sp1-la/certificate.pem'))
+ sp.addProvider(
+ lasso.PROVIDER_ROLE_IDP,
+ os.path.join(dataDir, 'idp1-la/metadata.xml'),
+ os.path.join(dataDir, 'idp1-la/public-key.pem'),
+ os.path.join(dataDir, 'idp1-la/certificate.pem'))
+ spLogin = lasso.Login(sp)
+ spLogin.initAuthnRequest()
+ requestAuthnContext = lasso.LibRequestAuthnContext()
+ authnContextClassRefsList = []
+ authnContextClassRefsList.append(
+ lasso.LIB_AUTHN_CONTEXT_CLASS_REF_PASSWORD)
+ requestAuthnContext.authnContextClassRef = tuple(authnContextClassRefsList)
+ spLogin.request.requestAuthnContext = requestAuthnContext
+ spLogin.request.protocolProfile = lasso.LIB_PROTOCOL_PROFILE_BRWS_ART
+ spLogin.buildAuthnRequestMsg()
+ authnRequestUrl = spLogin.msgUrl
+ authnRequestQuery = spLogin.msgUrl[spLogin.msgUrl.index('?') + 1:]
+ idp = lasso.Server(
+ os.path.join(dataDir, 'idp1-la/metadata.xml'),
+ os.path.join(dataDir, 'idp1-la/private-key-raw.pem'),
+ None,
+ os.path.join(dataDir, 'idp1-la/certificate.pem'))
+ idp.addProvider(
+ lasso.PROVIDER_ROLE_SP,
+ os.path.join(dataDir, 'sp1-la/metadata.xml'),
+ os.path.join(dataDir, 'sp1-la/public-key.pem'),
+ os.path.join(dataDir, 'sp1-la/certificate.pem'))
+ idpLogin = lasso.Login(idp)
+ idpLogin.processAuthnRequestMsg(authnRequestQuery)
+ self.failUnless(idpLogin.request.requestAuthnContext)
+ authnContextClassRefsList = idpLogin.request.requestAuthnContext.authnContextClassRef
+ self.failUnlessEqual(len(authnContextClassRefsList), 1)
+ self.failUnlessEqual(authnContextClassRefsList[0],
+ lasso.LIB_AUTHN_CONTEXT_CLASS_REF_PASSWORD)
+
+ def test04(self):
+ """Conversion of a lib:AuthnRequest with extensions into a query and back."""
+
+ sp = lasso.Server(
+ os.path.join(dataDir, 'sp1-la/metadata.xml'),
+ os.path.join(dataDir, 'sp1-la/private-key-raw.pem'),
+ None,
+ os.path.join(dataDir, 'sp1-la/certificate.pem'))
+ sp.addProvider(
+ lasso.PROVIDER_ROLE_IDP,
+ os.path.join(dataDir, 'idp1-la/metadata.xml'),
+ os.path.join(dataDir, 'idp1-la/public-key.pem'),
+ os.path.join(dataDir, 'idp1-la/certificate.pem'))
+ spLogin = lasso.Login(sp)
+ spLogin.initAuthnRequest()
+ requestAuthnContext = lasso.LibRequestAuthnContext()
+ extensionList = []
+ for extension in (
+ '<action>do</action>',
+ '<action2>do action 2</action2><action3>do action 3</action3>'):
+ extensionList.append(
+ '<lib:Extension xmlns:lib="urn:liberty:iff:2003-08">%s</lib:Extension>'
+ % extension)
+ spLogin.request.extension = tuple(extensionList)
+ spLogin.request.protocolProfile = lasso.LIB_PROTOCOL_PROFILE_BRWS_ART
+ spLogin.buildAuthnRequestMsg()
+ authnRequestUrl = spLogin.msgUrl
+ authnRequestQuery = spLogin.msgUrl[spLogin.msgUrl.index('?') + 1:]
+ idp = lasso.Server(
+ os.path.join(dataDir, 'idp1-la/metadata.xml'),
+ os.path.join(dataDir, 'idp1-la/private-key-raw.pem'),
+ None,
+ os.path.join(dataDir, 'idp1-la/certificate.pem'))
+ idp.addProvider(
+ lasso.PROVIDER_ROLE_SP,
+ os.path.join(dataDir, 'sp1-la/metadata.xml'),
+ os.path.join(dataDir, 'sp1-la/public-key.pem'),
+ os.path.join(dataDir, 'sp1-la/certificate.pem'))
+ idpLogin = lasso.Login(idp)
+ idpLogin.processAuthnRequestMsg(authnRequestQuery)
+ self.failUnless(idpLogin.request.extension)
+ extensionsList = idpLogin.request.extension
+ self.failUnlessEqual(len(extensionsList), 1)
+ self.failUnless('<action>do</action>' in extensionsList[0])
+ self.failUnless('<action2>do action 2</action2>' in extensionsList[0])
+ self.failUnless('<action3>do action 3</action3>' in extensionsList[0])
+
+
+class LogoutTestCase(unittest.TestCase):
+ def test01(self):
+ """SP logout without session and identity; testing initRequest."""
+
+ lassoServer = lasso.Server(
+ os.path.join(dataDir, 'sp1-la/metadata.xml'),
+ os.path.join(dataDir, 'sp1-la/private-key-raw.pem'),
+ None,
+ os.path.join(dataDir, 'sp1-la/certificate.pem'))
+ lassoServer.addProvider(
+ lasso.PROVIDER_ROLE_IDP,
+ os.path.join(dataDir, 'idp1-la/metadata.xml'),
+ os.path.join(dataDir, 'idp1-la/public-key.pem'),
+ os.path.join(dataDir, 'idp1-la/certificate.pem'))
+ logout = lasso.Logout(lassoServer)
+ try:
+ logout.initRequest()
+ except lasso.Error, error:
+ if error[0] != lasso.PROFILE_ERROR_SESSION_NOT_FOUND:
+ raise
+ else:
+ self.fail('logout.initRequest without having set identity before should fail')
+
+ def test02(self):
+ """IDP logout without session and identity; testing logout.getNextProviderId."""
+
+ lassoServer = lasso.Server(
+ os.path.join(dataDir, 'idp1-la/metadata.xml'),
+ os.path.join(dataDir, 'idp1-la/private-key-raw.pem'),
+ None,
+ os.path.join(dataDir, 'idp1-la/certificate.pem'))
+ lassoServer.addProvider(
+ lasso.PROVIDER_ROLE_SP,
+ os.path.join(dataDir, 'sp1-la/metadata.xml'),
+ os.path.join(dataDir, 'sp1-la/public-key.pem'),
+ os.path.join(dataDir, 'sp1-la/certificate.pem'))
+ logout = lasso.Logout(lassoServer)
+ self.failIf(logout.getNextProviderId())
+
+ def test03(self):
+ """IDP logout; testing processRequestMsg with non Liberty query."""
+
+ lassoServer = lasso.Server(
+ os.path.join(dataDir, 'idp1-la/metadata.xml'),
+ os.path.join(dataDir, 'idp1-la/private-key-raw.pem'),
+ None,
+ os.path.join(dataDir, 'idp1-la/certificate.pem'))
+ lassoServer.addProvider(
+ lasso.PROVIDER_ROLE_SP,
+ os.path.join(dataDir, 'sp1-la/metadata.xml'),
+ os.path.join(dataDir, 'sp1-la/public-key.pem'),
+ os.path.join(dataDir, 'sp1-la/certificate.pem'))
+ logout = lasso.Logout(lassoServer)
+ # The processRequestMsg should fail but not abort.
+ try:
+ logout.processRequestMsg('passport=0&lasso=1')
+ except lasso.Error, error:
+ if error[0] != lasso.PROFILE_ERROR_INVALID_MSG:
+ raise
+ else:
+ self.fail('Logout processRequestMsg should have failed.')
+
+ def test04(self):
+ """IDP logout; testing processResponseMsg with non Liberty query."""
+
+ lassoServer = lasso.Server(
+ os.path.join(dataDir, 'idp1-la/metadata.xml'),
+ os.path.join(dataDir, 'idp1-la/private-key-raw.pem'),
+ None,
+ os.path.join(dataDir, 'idp1-la/certificate.pem'))
+ lassoServer.addProvider(
+ lasso.PROVIDER_ROLE_SP,
+ os.path.join(dataDir, 'sp1-la/metadata.xml'),
+ os.path.join(dataDir, 'sp1-la/public-key.pem'),
+ os.path.join(dataDir, 'sp1-la/certificate.pem'))
+ logout = lasso.Logout(lassoServer)
+ # The processResponseMsg should fail but not abort.
+ try:
+ logout.processResponseMsg('liberty=&alliance')
+ except lasso.Error, error:
+ if error[0] != lasso.PROFILE_ERROR_INVALID_MSG:
+ raise
+ else:
+ self.fail('Logout processResponseMsg should have failed.')
+
+ def test05(self):
+ """IDP logout; testing logout dump & newFromDump()."""
+
+ lassoServer = lasso.Server(
+ os.path.join(dataDir, 'idp1-la/metadata.xml'),
+ os.path.join(dataDir, 'idp1-la/private-key-raw.pem'),
+ None,
+ os.path.join(dataDir, 'idp1-la/certificate.pem'))
+ lassoServer.addProvider(
+ lasso.PROVIDER_ROLE_SP,
+ os.path.join(dataDir, 'sp1-la/metadata.xml'),
+ os.path.join(dataDir, 'sp1-la/public-key.pem'),
+ os.path.join(dataDir, 'sp1-la/certificate.pem'))
+
+
+class DefederationTestCase(unittest.TestCase):
+ def test01(self):
+ """IDP initiated defederation; testing processNotificationMsg with non Liberty query."""
+
+ lassoServer = lasso.Server(
+ os.path.join(dataDir, 'idp1-la/metadata.xml'),
+ os.path.join(dataDir, 'idp1-la/private-key-raw.pem'),
+ None,
+ os.path.join(dataDir, 'idp1-la/certificate.pem'))
+ lassoServer.addProvider(
+ lasso.PROVIDER_ROLE_SP,
+ os.path.join(dataDir, 'sp1-la/metadata.xml'),
+ os.path.join(dataDir, 'sp1-la/public-key.pem'),
+ os.path.join(dataDir, 'sp1-la/certificate.pem'))
+ defederation = lasso.Defederation(lassoServer)
+ # The processNotificationMsg should fail but not abort.
+ try:
+ defederation.processNotificationMsg('nonLibertyQuery=1')
+ except lasso.Error, error:
+ if error[0] != lasso.PROFILE_ERROR_INVALID_MSG:
+ raise
+ else:
+ self.fail('Defederation processNotificationMsg should have failed.')
+
+
+class IdentityTestCase(unittest.TestCase):
+ def test01(self):
+ """Identity newFromDump & dump."""
+ return
+ # test disabled since dump format changed
+ identityDump = """<Identity xmlns="http://www.entrouvert.org/namespaces/lasso/0.0" Version="1"><Federations><Federation xmlns="http://www.entrouvert.org/namespaces/lasso/0.0" Version="1" RemoteProviderID="https://sp1.entrouvert.lan/metadata"><LocalNameIdentifier><saml:NameIdentifier xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion" NameQualifier="https://proxy2.entrouvert.lan/metadata" Format="urn:liberty:iff:nameid:federated">_CD739B41C602EAEA93626EBD1751CB46</saml:NameIdentifier></LocalNameIdentifier></Federation><Federation xmlns="http://www.entrouvert.org/namespaces/lasso/0.0" Version="1" RemoteProviderID="https://idp1.entrouvert.lan/metadata"><RemoteNameIdentifier><saml:NameIdentifier xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion" NameQualifier="https://idp1.entrouvert.lan/metadata" Format="urn:liberty:iff:nameid:federated">_11EA77A4FED32C41824AC5DE87298E65</saml:NameIdentifier></RemoteNameIdentifier></Federation></Federations></Identity>"""
+ identity = lasso.Identity.newFromDump(identityDump)
+ newIdentityDump = identity.dump()
+ self.failUnlessEqual(identityDump, newIdentityDump)
+
+
+serverSuite = unittest.makeSuite(ServerTestCase, 'test')
+loginSuite = unittest.makeSuite(LoginTestCase, 'test')
+logoutSuite = unittest.makeSuite(LogoutTestCase, 'test')
+defederationSuite = unittest.makeSuite(DefederationTestCase, 'test')
+identitySuite = unittest.makeSuite(IdentityTestCase, 'test')
+
+allTests = unittest.TestSuite((serverSuite, loginSuite, logoutSuite, defederationSuite,
+ identitySuite))
+
+if __name__ == '__main__':
+ sys.exit(not unittest.TextTestRunner(verbosity = 2).run(allTests).wasSuccessful())
+