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

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

 1  ''' 
 2  Created on 31 Aug 2011 
 3   
 4  @author: rwilkinson 
 5  ''' 
 6  import logging 
 7  import os.path 
 8  import time 
 9  import unittest 
10   
11  from ndg.xacml.parsers.etree.factory import ReaderFactory 
12  from ndg.xacml.core.context.pdp import PDP 
13  from ndg.xacml.core.context.result import Decision 
14  from ndg.xacml.test import THIS_DIR 
15  from ndg.xacml.test.context import XacmlContextBaseTestCase 
16   
17   
18  logging.basicConfig(level=logging.ERROR) 
19   
20 -class Test(XacmlContextBaseTestCase):
21 """Tests for FAAM policy set with nested policies for efficiency. 22 """ 23 RESOURCE_B555_ID = 'http://localhost/download/badc/faam/data/2010/b555-sep-15/core_raw/b555_raw_data.dat' 24 XACML_FAAM_FILENAME = 'policy_faam_policyset.xml' 25 XACML_FILEPATH = os.path.join(THIS_DIR, 'faam_policyset', XACML_FAAM_FILENAME) 26
27 - def setUp(self):
28 print "Setting up" 29 self.pdp = PDP.fromPolicySource(self.__class__.XACML_FILEPATH, ReaderFactory) 30 print "Setup complete"
31 32
33 - def test01(self):
34 request = self._createRequestCtx( 35 self.__class__.RESOURCE_B555_ID, 36 subjectRoles=('faam_admin',)) 37 print "Starting request" 38 start_time = time.time() 39 response = self.pdp.evaluate(request) 40 print("Response received after %fs" % (time.time() - start_time)) 41 self.failIf(response is None, "Null response") 42 for result in response.results: 43 self.failIf(result.decision != Decision.PERMIT, 44 45 "Expecting Permit decision")
46 - def test02(self):
47 request = self._createRequestCtx( 48 self.__class__.RESOURCE_B555_ID, 49 subjectRoles=('group1',)) 50 print "Starting request" 51 start_time = time.time() 52 response = self.pdp.evaluate(request) 53 print("Response received after %fs" % (time.time() - start_time)) 54 self.failIf(response is None, "Null response") 55 for result in response.results: 56 self.failIf(result.decision != Decision.DENY, 57 "Expecting Deny decision")
58
59 - def test03(self):
60 request = self._createRequestCtx( 61 self.__class__.RESOURCE_B555_ID, 62 subjectRoles=('faam_admin',)) 63 print "Starting request" 64 start_time = time.time() 65 response = self.pdp.evaluate(request) 66 print("Response received after %fs" % (time.time() - start_time)) 67 self.failIf(response is None, "Null response") 68 for result in response.results: 69 self.failIf(result.decision != Decision.PERMIT, 70 "Expecting Permit decision")
71 72 73 74 if __name__ == "__main__": 75 unittest.main() 76