source: TI12-security/trunk/NDG_XACML/ndg/xacml/test/test_xacml.py @ 6751

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDG_XACML/ndg/xacml/test/test_xacml.py@6751
Revision 6751, 2.9 KB checked in by pjkersha, 10 years ago (diff)

Working rule1 example parsing, working on rule2 which contains a target resource.

Line 
1"""NDG XACML unit test package
2
3NERC DataGrid Project
4"""
5__author__ = "P J Kershaw"
6__date__ = "16/03/10"
7__copyright__ = "(C) 2010 Science and Technology Facilities Council"
8__contact__ = "Philip.Kershaw@stfc.ac.uk"
9__license__ = "BSD - see LICENSE file in top-level directory"
10__contact__ = "Philip.Kershaw@stfc.ac.uk"
11__revision__ = "$Id: $"
12import unittest
13from os import path
14
15from ndg.xacml.parsers.etree.policyreader import PolicyReader
16
17
18class XACMLTestCase(unittest.TestCase):
19    THIS_DIR = path.dirname(__file__)
20    XACML_TEST1_FILENAME = "rule1.xml"
21    XACML_TEST1_FILEPATH = path.join(THIS_DIR, XACML_TEST1_FILENAME)
22    XACML_TEST2_FILENAME = "rule2.xml"
23    XACML_TEST2_FILEPATH = path.join(THIS_DIR, XACML_TEST2_FILENAME)
24   
25    def test01ETreeParseRule1Policy(self):
26        policy = PolicyReader.parse(XACMLTestCase.XACML_TEST1_FILEPATH)
27        self.assert_(policy)
28       
29        self.assert_(
30            policy.policyId == "urn:oasis:names:tc:example:SimplePolicy1")
31       
32        self.assert_(policy.ruleCombiningAlgId == \
33        "urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:deny-overrides")
34       
35        self.assert_(
36            "Med Example Corp access control policy" in policy.description)
37       
38        self.assert_(len(policy.target.subjects) == 0)
39       
40        self.assert_(policy.rules[0].id == \
41                     "urn:oasis:names:tc:xacml:2.0:example:SimpleRule1")
42       
43        self.assert_(policy.rules[0].effect == 'Permit')
44       
45        self.assert_(
46            'Any subject with an e-mail name in the med.example.com domain' in \
47            policy.rules[0].description)
48       
49        self.assert_(len(policy.rules[0].target.subjects) == 1)
50        self.assert_(len(policy.rules[0].target.actions) == 0)
51        self.assert_(len(policy.rules[0].target.resources) == 0)
52        self.assert_(len(policy.rules[0].target.environments) == 0)
53       
54        self.assert_(len(policy.rules[0].target.subjects[0].subjectMatches) == 1)
55       
56        self.assert_(policy.rules[0].target.subjects[0].subjectMatches[0
57            ].matchId == \
58            "urn:oasis:names:tc:xacml:1.0:function:rfc822Name-match")
59       
60        self.assert_(policy.rules[0].target.subjects[0].subjectMatches[0
61            ].attributeValue.dataType == \
62            "urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name")
63       
64        self.assert_(policy.rules[0].target.subjects[0].subjectMatches[0
65            ].attributeDesignator.dataType == \
66            "urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name")
67       
68        # Attribute ID
69        self.assert_(policy.rules[0].target.subjects[0].subjectMatches[0
70            ].attributeDesignator.attributeId == \
71            "urn:oasis:names:tc:xacml:1.0:subject:subject-id")
72         
73    def test02ETreeParseRule2Policy(self):
74        policy = PolicyReader.parse(XACMLTestCase.XACML_TEST2_FILEPATH)
75        self.assert_(policy)
76
77
78if __name__ == "__main__":
79    unittest.main()
Note: See TracBrowser for help on using the repository browser.