Package ndg :: Package xacml :: Package test :: Package context :: Module test_pdp_with_policy_set_internal_references
[hide private]

Source Code for Module ndg.xacml.test.context.test_pdp_with_policy_set_internal_references

 1  """NDG XACML PDP tests with policy set references resolved internally by ID 
 2   
 3  NERC DataGrid 
 4  """ 
 5  __author__ = "R B Wilkinson" 
 6  __date__ = "02/11/11" 
 7  __copyright__ = "(C) 2011 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$" 
12   
13  import logging 
14  import os.path 
15  import time 
16  import unittest 
17   
18  from ndg.xacml.parsers.etree.factory import ReaderFactory 
19  from ndg.xacml.core.context.pdp import PDP 
20  from ndg.xacml.core.context.result import Decision 
21  from ndg.xacml.test import THIS_DIR 
22  from ndg.xacml.test.context import XacmlContextBaseTestCase 
23   
24   
25  logging.basicConfig(level=logging.ERROR) 
26   
27 -class Test(XacmlContextBaseTestCase):
28 29 RESOURCE_DL1_ID = 'http://localhost/download/set1/action-and-single-subject-role-restricted-1' 30 RESOURCE_DL2_ID = 'http://localhost/download/set3/action-and-single-subject-role-restricted-2' 31 RESOURCE_VIEW1_ID = 'http://localhost/view/set1/action-and-single-subject-role-restricted-1' 32 RESOURCE_VIEW2_ID = 'http://localhost/view/set2/action-and-single-subject-role-restricted-2' 33 XACML_POLICY_SET_FILENAME = 'policy_set_internal_references.xml' 34 XACML_POLICY_SET_FILEPATH = os.path.join(THIS_DIR, XACML_POLICY_SET_FILENAME) 35
36 - def setUp(self):
37 print "Setting up" 38 self.pdp = PDP.fromPolicySource(self.__class__.XACML_POLICY_SET_FILEPATH, ReaderFactory) 39 print "Setup complete"
40 41
42 - def test01(self):
43 request = self._createRequestCtx( 44 self.__class__.RESOURCE_DL1_ID, 45 subjectRoles=('staff',)) 46 print "Starting request" 47 start_time = time.time() 48 response = self.pdp.evaluate(request) 49 print("Response received after %fs" % (time.time() - start_time)) 50 self.failIf(response is None, "Null response") 51 for result in response.results: 52 self.failIf(result.decision != Decision.PERMIT, 53 "Expecting Permit decision")
54
55 - def test02(self):
56 request = self._createRequestCtx( 57 self.__class__.RESOURCE_DL2_ID, 58 subjectRoles=('staff',)) 59 print "Starting request" 60 start_time = time.time() 61 response = self.pdp.evaluate(request) 62 print("Response received after %fs" % (time.time() - start_time)) 63 self.failIf(response is None, "Null response") 64 for result in response.results: 65 self.failIf(result.decision != Decision.DENY, 66 "Expecting Deny decision")
67
68 - def test03(self):
69 request = self._createRequestCtx( 70 self.__class__.RESOURCE_VIEW1_ID, 71 subjectRoles=('admin',)) 72 print "Starting request" 73 start_time = time.time() 74 response = self.pdp.evaluate(request) 75 print("Response received after %fs" % (time.time() - start_time)) 76 self.failIf(response is None, "Null response") 77 for result in response.results: 78 self.failIf(result.decision != Decision.DENY, 79 "Expecting Deny decision")
80
81 - def test04(self):
82 request = self._createRequestCtx( 83 self.__class__.RESOURCE_VIEW2_ID, 84 subjectRoles=('staff',)) 85 print "Starting request" 86 start_time = time.time() 87 response = self.pdp.evaluate(request) 88 print("Response received after %fs" % (time.time() - start_time)) 89 self.failIf(response is None, "Null response") 90 for result in response.results: 91 self.failIf(result.decision != Decision.PERMIT, 92 "Expecting Permit decision")
93 94 95 if __name__ == "__main__": 96 unittest.main() 97