source: TI12-security/trunk/NDGSecurity/python/ndg_security_test/ndg/security/test/unit/authz/xacml/test_saml_ctx_handler.py @ 7339

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDGSecurity/python/ndg_security_test/ndg/security/test/unit/authz/xacml/test_saml_ctx_handler.py@7339
Revision 7339, 2.1 KB checked in by pjkersha, 9 years ago (diff)

Moved XACML unit tests to ndg.security.test.unit.authz.xacml

Line 
1"""Unit tests XACML Context handler.  This PIP presents a SAML interface for its
2Policy Enforcement Point and has a SAML interface to query a remote attribute
3authority for attributes
4"""
5__author__ = "P J Kershaw"
6__date__ = "13/08/10"
7__copyright__ = "(C) 2010 Science and Technology Facilities Council"
8__license__ = "BSD - see LICENSE file in top-level directory"
9__contact__ = "Philip.Kershaw@stfc.ac.uk"
10__revision__ = '$Id:$'
11import logging
12logging.basicConfig(level=logging.DEBUG)
13log = logging.getLogger(__name__)
14
15from os import path
16import unittest
17
18from ConfigParser import SafeConfigParser
19from ndg.security.test.unit import BaseTestCase
20from ndg.security.server.xacml.ctx_handler.saml_ctx_handler import SamlCtxHandler
21
22
23class SamlCtxHandlerTestCase(BaseTestCase):
24    """Test XACML Context handler.  This PIP presents a SAML interface for its
25    Policy Enforcement Point and has a SAML interface to query a remote
26    attribute authority for attributes
27    """
28    THIS_DIR = path.abspath(path.dirname(__file__))
29    CONFIG_FILENAME = 'saml_ctx_handler.cfg'
30    CONFIG_FILEPATH = path.join(THIS_DIR, CONFIG_FILENAME)
31       
32    def test01Init(self):
33        handler = SamlCtxHandler()
34        self.assert_(handler)
35       
36    def test02InitFromConfigFile(self):
37        # Initialise from settings in a config file
38        handler = SamlCtxHandler.fromConfig(self.__class__.CONFIG_FILEPATH)
39        self.assert_(handler)
40        self.assert_(handler.policyFilePath)
41       
42    def test03InitFromKeywords(self):
43        # Initialise from a dictionary
44       
45        # Populate by reading from the config file
46        cfg = SafeConfigParser(defaults={'here': self.__class__.THIS_DIR})
47        cfg.optionxform = str
48        cfg.read(self.__class__.CONFIG_FILEPATH)
49        kw = dict(cfg.items('DEFAULT'))
50       
51        handler = SamlCtxHandler.fromKeywords(**kw)
52        self.assert_(handler)
53        self.assert_(handler.pip.attributeQuery)
54        self.assert_(handler.policyFilePath)
55        self.assert_(handler.issuerName)
56        self.assert_(handler.issuerFormat)
57        self.assert_(handler.assertionLifetime)
58       
59if __name__ == "__main__":
60    unittest.main()
Note: See TracBrowser for help on using the repository browser.