source: TI12-security/trunk/NDGSecurity/python/Tests/esg_integration/test_attributeserviceclient.py @ 7681

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

Incomplete - task 16: NDG Security 2.0.1 - incl. updated Paster templates

  • Fix mutable keyword defaults
Line 
1#!/usr/bin/env python
2"""Test ESG Attribute Service - based on NDG SAML Attribute Authority unit
3tests
4
5"""
6__author__ = "P J Kershaw"
7__date__ = "02/08/10"
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)
14import os
15import unittest
16
17from datetime import datetime
18from xml.etree import ElementTree
19
20from ndg.saml.saml2.core import StatusCode
21from ndg.saml.saml2.binding.soap.client.attributequery import (
22                                        AttributeQuerySslSOAPBinding)
23
24from ndg.security.common.saml_utils.esg.xml.etree import EsgResponseElementTree
25from ndg.security.common.utils.etree import prettyPrint
26from ndg.security.common.utils.configfileparsers import (
27    CaseSensitiveConfigParser)
28
29   
30class EsgAttributeServiceIntegrationTestCase(unittest.TestCase):
31    """NDG Attribute Authority SAML SOAP Binding client unit tests"""
32    HERE_DIR = os.path.dirname(__file__)
33    CONFIG_FILENAME = 'test_attributeserviceclient.cfg'
34    CONFIG_FILEPATH = os.path.join(HERE_DIR, CONFIG_FILENAME)
35   
36    def __init__(self, *arg, **kw):
37        self.cfgParser = CaseSensitiveConfigParser()
38        self.cfgParser.read(self.__class__.CONFIG_FILEPATH)
39       
40        super(EsgAttributeServiceIntegrationTestCase, self).__init__(*arg, **kw)
41               
42    def _attributeQuery(self, thisSection):
43       
44        uri = self.cfgParser.get(thisSection, 'uri')
45        print("Calling Attribute Service %r ..." % uri)
46       
47        binding = AttributeQuerySslSOAPBinding.fromConfig(
48                                                self.__class__.CONFIG_FILEPATH, 
49                                                section=thisSection,
50                                                prefix='attributeQuery.')
51       
52        binding.subjectID = self.cfgParser.get(thisSection, 'subject')
53       
54        response = binding.send(uri=uri)
55       
56        # EsgResponseElementTree has an extension to support ESG Group/Role
57        # Attribute Value
58        samlResponseElem = EsgResponseElementTree.toXML(response)
59       
60        print("SAML Response ...")
61        print(ElementTree.tostring(samlResponseElem))
62        print("Pretty print SAML Response ...")
63        print(prettyPrint(samlResponseElem))
64       
65        self.assert_(response.status.statusCode.value==StatusCode.SUCCESS_URI)
66#       
67#    def test01ncarAttributeQuery(self):
68#        self._attributeQuery('test01ncarAttributeQuery')
69#       
70#    def test02pcmdiAttributeQuery(self):
71#        self._attributeQuery('test02pcmdiAttributeQuery')
72       
73    def test03pcmdiProductionAttributeQuery(self):
74        self._attributeQuery('test03pcmdiProductionAttributeQuery')
75
76       
77if __name__ == "__main__":
78    unittest.main()
Note: See TracBrowser for help on using the repository browser.