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

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

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