1 | """Unit tests XACML Context handler. This PIP presents a SAML interface for its |
---|
2 | Policy Enforcement Point and has a SAML interface to query a remote attribute |
---|
3 | authority 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:$' |
---|
11 | import logging |
---|
12 | logging.basicConfig(level=logging.DEBUG) |
---|
13 | log = logging.getLogger(__name__) |
---|
14 | |
---|
15 | from os import path |
---|
16 | import unittest |
---|
17 | |
---|
18 | from ConfigParser import SafeConfigParser |
---|
19 | from ndg.security.test.unit import BaseTestCase |
---|
20 | from ndg.security.server.xacml.ctx_handler.saml_ctx_handler import SamlCtxHandler |
---|
21 | |
---|
22 | |
---|
23 | class 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 | |
---|
59 | if __name__ == "__main__": |
---|
60 | unittest.main() |
---|