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

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

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