source: TI12-security/trunk/NDGSecurity/python/Tests/esg_integration/test_soapauthzdecisioninterface.py @ 6577

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDGSecurity/python/Tests/esg_integration/test_soapauthzdecisioninterface.py@6577
Revision 6577, 2.9 KB checked in by pjkersha, 12 years ago (diff)

End to end testing with ESG prototype SAML Authz service.

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2"""Unit tests for WSGI SAML 2.0 SOAP Authorisation Decision Query Interface
3
4NERC DataGrid Project
5"""
6__author__ = "P J Kershaw"
7__date__ = "15/02/2010"
8__copyright__ = "(C) 2010 Science and Technology Facilities Council"
9__license__ = "BSD - see LICENSE file in top-level directory"
10__contact__ = "Philip.Kershaw@stfc.ac.uk"
11__revision__ = '$Id: $'
12import logging
13logging.basicConfig(level=logging.DEBUG)
14
15import unittest
16from os import path
17from xml.etree import ElementTree
18
19from saml.saml2.core import StatusCode, DecisionType, Action
20from saml.xml.etree import ResponseElementTree
21from ndg.security.common.saml_utils.binding.soap.authzdecisionquery import ( 
22                                        AuthzDecisionQuerySslSOAPBinding)
23
24class EsgAuthzServiceTestCase(unittest.TestCase):
25    THIS_DIR = path.dirname(__file__)
26    CA_DIR = path.join(THIS_DIR, 'ca')
27
28    def _readParamFile(filePath):
29        try:
30            return open(filePath).read().strip()
31        except IOError:
32            return None
33   
34    RESOURCE_URI = _readParamFile(path.join(THIS_DIR, 'resource.txt'))
35    SUBJECT = _readParamFile(path.join(THIS_DIR, 'subject.txt'))
36    ISSUER_NAME = '/O=STFC/OU=BADC/CN=TestAuthorizationClient'
37    ACTION = 'Read'
38    ACTION_NS_URI = Action.RWEDC_NEGATION_NS_URI
39    AUTHZ_SERVICE_URI = _readParamFile(path.join(THIS_DIR, 'endpoint.txt'))
40       
41    def test01ValidQuery(self):       
42        binding = AuthzDecisionQuerySslSOAPBinding()
43        binding.actions.append(Action())
44        binding.actions[0].namespace = EsgAuthzServiceTestCase.ACTION_NS_URI
45        binding.actions[0].value = EsgAuthzServiceTestCase.ACTION   
46        binding.resourceURI = EsgAuthzServiceTestCase.RESOURCE_URI
47        binding.subjectID = EsgAuthzServiceTestCase.SUBJECT
48        binding.issuerName = EsgAuthzServiceTestCase.ISSUER_NAME
49       
50        # SSL Context Proxy settings
51        binding.sslCACertDir = EsgAuthzServiceTestCase.CA_DIR
52
53        response = binding.send(uri=EsgAuthzServiceTestCase.AUTHZ_SERVICE_URI)
54        samlResponseElem = ResponseElementTree.toXML(response)
55       
56        print("SAML Response ...")
57        print(ElementTree.tostring(samlResponseElem))
58        print("Pretty print SAML Response ...")
59        print(prettyPrint(samlResponseElem))
60
61
62        self.assert_(samlResponse.status.statusCode.value == \
63                     StatusCode.SUCCESS_URI)
64        self.assert_(samlResponse.inResponseTo == query.id)
65        self.assert_(samlResponse.assertions[0].subject.nameID.value == \
66                     query.subject.nameID.value)
67        self.assert_(samlResponse.assertions[0])
68        self.assert_(samlResponse.assertions[0].authzDecisionStatements[0])
69        self.assert_(samlResponse.assertions[0].authzDecisionStatements[0
70                                            ].decision == DecisionType.PERMIT)
71       
72
73 
74if __name__ == "__main__":
75    unittest.main()
Note: See TracBrowser for help on using the repository browser.