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

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

Parsing functionality near complete for rule1.xml

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_FILENAME = "rule1.xml"
21    XACML_FILEPATH = path.join(THIS_DIR, XACML_FILENAME)
22   
23    def test01ETreeParseRule1Policy(self):
24        policy = PolicyReader.parse(XACMLTestCase.XACML_FILEPATH)
25        self.assert_(policy)
26       
27        self.assert_(
28            policy.policyId == "urn:oasis:names:tc:example:SimplePolicy1")
29       
30        self.assert_(policy.ruleCombiningAlgId == \
31        "urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:deny-overrides")
32       
33        self.assert_(
34            "Med Example Corp access control policy" in policy.description)
35       
36        self.assert_(len(policy.target.subjects) == 0)
37       
38        self.assert_(policy.rules[0].id == \
39                     "urn:oasis:names:tc:xacml:2.0:example:SimpleRule1")
40       
41        self.assert_(policy.rules[0].effect == 'Permit')
42       
43        self.assert_(
44            'Any subject with an e-mail name in the med.example.com domain' in \
45            policy.rules[0].description)
46       
47        self.assert_(len(policy.rules[0].subjects) == 1)
48        self.assert_(len(policy.rules[0].actions) == 0)
49        self.assert_(len(policy.rules[0].resources) == 0)
50        self.assert_(len(policy.rules[0].environments) == 0)
51       
52        self.assert_(len(policy.rules[0].subjects[0].subjectMatches) == 1)
53       
54        self.assert_(policy.rules[0].subjects[0].subjectMatches[0].id == \
55                     "urn:oasis:names:tc:xacml:1.0:function:rfc822Name-match")
56       
57        self.assert_(policy.rules[0].subjects[0].subjectMatches[0
58            ].attributeValue.dataType == \
59            "urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name")
60       
61        self.assert_(policy.rules[0].subjects[0].subjectMatches[0
62            ].attributeDesignator.dataType == \
63            "urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name")
64       
65        # Attribute ID
66        self.assert_(policy.rules[0].subjects[0].subjectMatches[0
67            ].attributeDesignator.attributeId == \
68            "urn:oasis:names:tc:xacml:1.0:subject:subject-id")
69       
70
71
72if __name__ == "__main__":
73    unittest.main()
Note: See TracBrowser for help on using the repository browser.