<s> """<STR_LIT>""" <EOL> import os . path <EOL> from oslo_policy import policy as oslo_policy <EOL> from oslo_serialization import jsonutils <EOL> import requests_mock <EOL> from nova import context <EOL> from nova import exception <EOL> from nova import policy <EOL> from nova import test <EOL> from nova . tests . unit import fake_policy <EOL> from nova . tests . unit import policy_fixture <EOL> from nova import utils <EOL> class PolicyFileTestCase ( test . NoDBTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( PolicyFileTestCase , self ) . setUp ( ) <EOL> self . context = context . RequestContext ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . target = { } <EOL> def test_modified_policy_reloads ( self ) : <EOL> with utils . tempdir ( ) as tmpdir : <EOL> tmpfilename = os . path . join ( tmpdir , '<STR_LIT>' ) <EOL> self . flags ( policy_file = tmpfilename , group = '<STR_LIT>' ) <EOL> policy . reset ( ) <EOL> action = "<STR_LIT>" <EOL> with open ( tmpfilename , "<STR_LIT:w>" ) as policyfile : <EOL> policyfile . write ( '<STR_LIT>' ) <EOL> policy . enforce ( self . context , action , self . target ) <EOL> with open ( tmpfilename , "<STR_LIT:w>" ) as policyfile : <EOL> policyfile . write ( '<STR_LIT>' ) <EOL> policy . _ENFORCER . load_rules ( True ) <EOL> self . assertRaises ( exception . PolicyNotAuthorized , policy . enforce , <EOL> self . context , action , self . target ) <EOL> class PolicyTestCase ( test . NoDBTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( PolicyTestCase , self ) . setUp ( ) <EOL> rules = { <EOL> "<STR_LIT:true>" : '<STR_LIT:@>' , <EOL> "<STR_LIT>" : '<STR_LIT:@>' , <EOL> "<STR_LIT>" : "<STR_LIT:!>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> policy . reset ( ) <EOL> policy . init ( ) <EOL> policy . set_rules ( oslo_policy . Rules . from_dict ( rules ) ) <EOL> self . context = context . RequestContext ( '<STR_LIT>' , '<STR_LIT>' , roles = [ '<STR_LIT>' ] ) <EOL> self . target = { } <EOL> def test_enforce_nonexistent_action_throws ( self ) : <EOL> action = "<STR_LIT>" <EOL> self . assertRaises ( exception . PolicyNotAuthorized , policy . enforce , <EOL> self . context , action , self . target ) <EOL> def test_enforce_bad_action_throws ( self ) : <EOL> action = "<STR_LIT>" <EOL> self . assertRaises ( exception . PolicyNotAuthorized , policy . enforce , <EOL> self . context , action , self . target ) <EOL> def test_enforce_bad_action_noraise ( self ) : <EOL> action = "<STR_LIT>" <EOL> result = policy . enforce ( self . context , action , self . target , False ) <EOL> self . assertFalse ( result ) <EOL> def test_enforce_good_action ( self ) : <EOL> action = "<STR_LIT>" <EOL> result = policy . enforce ( self . context , action , self . target ) <EOL> self . assertTrue ( result ) <EOL> @ requests_mock . mock ( ) <EOL> def test_enforce_http_true ( self , req_mock ) : <EOL> req_mock . post ( '<STR_LIT>' , <EOL> text = '<STR_LIT:True>' ) <EOL> action = "<STR_LIT>" <EOL> target = { } <EOL> result = policy . enforce ( self . context , action , target ) <EOL> self . assertTrue ( result ) <EOL> @ requests_mock . mock ( ) <EOL> def test_enforce_http_false ( self , req_mock ) : <EOL> req_mock . post ( '<STR_LIT>' , <EOL> text = '<STR_LIT:False>' ) <EOL> action = "<STR_LIT>" <EOL> target = { } <EOL> self . assertRaises ( exception . PolicyNotAuthorized , policy . enforce , <EOL> self . context , action , target ) <EOL> def test_templatized_enforcement ( self ) : <EOL> target_mine = { '<STR_LIT>' : '<STR_LIT>' } <EOL> target_not_mine = { '<STR_LIT>' : '<STR_LIT>' } <EOL> action = "<STR_LIT>" <EOL> policy . enforce ( self . context , action , target_mine ) <EOL> self . assertRaises ( exception . PolicyNotAuthorized , policy . enforce , <EOL> self . context , action , target_not_mine ) <EOL> def test_early_AND_enforcement ( self ) : <EOL> action = "<STR_LIT>" <EOL> self . assertRaises ( exception . PolicyNotAuthorized , policy . enforce , <EOL> self . context , action , self . target ) <EOL> def test_early_OR_enforcement ( self ) : <EOL> action = "<STR_LIT>" <EOL> policy . enforce ( self . context , action , self . target ) <EOL> def test_ignore_case_role_check ( self ) : <EOL> lowercase_action = "<STR_LIT>" <EOL> uppercase_action = "<STR_LIT>" <EOL> admin_context = context . RequestContext ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> roles = [ '<STR_LIT>' ] ) <EOL> policy . enforce ( admin_context , lowercase_action , self . target ) <EOL> policy . enforce ( admin_context , uppercase_action , self . target ) <EOL> class DefaultPolicyTestCase ( test . NoDBTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( DefaultPolicyTestCase , self ) . setUp ( ) <EOL> self . rules = { <EOL> "<STR_LIT:default>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : "<STR_LIT:!>" , <EOL> } <EOL> self . _set_rules ( '<STR_LIT:default>' ) <EOL> self . context = context . RequestContext ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def _set_rules ( self , default_rule ) : <EOL> policy . reset ( ) <EOL> rules = oslo_policy . Rules . from_dict ( self . rules ) <EOL> policy . init ( rules = rules , default_rule = default_rule , use_conf = False ) <EOL> def test_policy_called ( self ) : <EOL> self . assertRaises ( exception . PolicyNotAuthorized , policy . enforce , <EOL> self . context , "<STR_LIT>" , { } ) <EOL> def test_not_found_policy_calls_default ( self ) : <EOL> policy . enforce ( self . context , "<STR_LIT>" , { } ) <EOL> def test_default_not_found ( self ) : <EOL> self . _set_rules ( "<STR_LIT>" ) <EOL> self . assertRaises ( exception . PolicyNotAuthorized , policy . enforce , <EOL> self . context , "<STR_LIT>" , { } ) <EOL> class IsAdminCheckTestCase ( test . NoDBTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( IsAdminCheckTestCase , self ) . setUp ( ) <EOL> policy . init ( ) <EOL> def test_init_true ( self ) : <EOL> check = policy . IsAdminCheck ( '<STR_LIT>' , '<STR_LIT:True>' ) <EOL> self . assertEqual ( check . kind , '<STR_LIT>' ) <EOL> self . assertEqual ( check . match , '<STR_LIT:True>' ) <EOL> self . assertTrue ( check . expected ) <EOL> def test_init_false ( self ) : <EOL> check = policy . IsAdminCheck ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( check . kind , '<STR_LIT>' ) <EOL> self . assertEqual ( check . match , '<STR_LIT:False>' ) <EOL> self . assertFalse ( check . expected ) <EOL> def test_call_true ( self ) : <EOL> check = policy . IsAdminCheck ( '<STR_LIT>' , '<STR_LIT:True>' ) <EOL> self . assertEqual ( check ( '<STR_LIT:target>' , dict ( is_admin = True ) , <EOL> policy . _ENFORCER ) , True ) <EOL> self . assertEqual ( check ( '<STR_LIT:target>' , dict ( is_admin = False ) , <EOL> policy . _ENFORCER ) , False ) <EOL> def test_call_false ( self ) : <EOL> check = policy . IsAdminCheck ( '<STR_LIT>' , '<STR_LIT:False>' ) <EOL> self . assertEqual ( check ( '<STR_LIT:target>' , dict ( is_admin = True ) , <EOL> policy . _ENFORCER ) , False ) <EOL> self . assertEqual ( check ( '<STR_LIT:target>' , dict ( is_admin = False ) , <EOL> policy . _ENFORCER ) , True ) <EOL> class AdminRolePolicyTestCase ( test . NoDBTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( AdminRolePolicyTestCase , self ) . setUp ( ) <EOL> self . policy = self . useFixture ( policy_fixture . RoleBasedPolicyFixture ( ) ) <EOL> self . context = context . RequestContext ( '<STR_LIT>' , '<STR_LIT>' , roles = [ '<STR_LIT>' ] ) <EOL> self . actions = policy . get_rules ( ) . keys ( ) <EOL> self . target = { } <EOL> def test_enforce_admin_actions_with_nonadmin_context_throws ( self ) : <EOL> """<STR_LIT>""" <EOL> for action in self . actions : <EOL> self . assertRaises ( exception . PolicyNotAuthorized , policy . enforce , <EOL> self . context , action , self . target ) <EOL> class RealRolePolicyTestCase ( test . NoDBTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( RealRolePolicyTestCase , self ) . setUp ( ) <EOL> self . policy = self . useFixture ( policy_fixture . RealPolicyFixture ( ) ) <EOL> self . non_admin_context = context . RequestContext ( '<STR_LIT>' , '<STR_LIT>' , <EOL> roles = [ '<STR_LIT>' ] ) <EOL> self . admin_context = context . RequestContext ( '<STR_LIT>' , '<STR_LIT>' , True , <EOL> roles = [ '<STR_LIT>' ] ) <EOL> self . target = { } <EOL> self . fake_policy = jsonutils . loads ( fake_policy . policy_data ) <EOL> self . admin_only_rules = ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ) <EOL> self . admin_or_owner_rules = ( <EOL> "<STR_LIT:default>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ) <EOL> self . non_admin_only_rules = ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> self . allow_all_rules = ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ) <EOL> def test_all_rules_in_sample_file ( self ) : <EOL> special_rules = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:default>" ] <EOL> for ( name , rule ) in self . fake_policy . items ( ) : <EOL> if name in special_rules : <EOL> continue <EOL> self . assertIn ( name , policy . get_rules ( ) ) <EOL> def test_admin_only_rules ( self ) : <EOL> for rule in self . admin_only_rules : <EOL> self . assertRaises ( exception . PolicyNotAuthorized , policy . enforce , <EOL> self . non_admin_context , rule , self . target ) <EOL> policy . enforce ( self . admin_context , rule , self . target ) <EOL> def test_non_admin_only_rules ( self ) : <EOL> for rule in self . non_admin_only_rules : <EOL> self . assertRaises ( exception . PolicyNotAuthorized , policy . enforce , <EOL> self . admin_context , rule , self . target ) <EOL> policy . enforce ( self . non_admin_context , rule , self . target ) <EOL> def test_admin_or_owner_rules ( self ) : <EOL> for rule in self . admin_or_owner_rules : <EOL> self . assertRaises ( exception . PolicyNotAuthorized , policy . enforce , <EOL> self . non_admin_context , rule , self . target ) <EOL> policy . enforce ( self . non_admin_context , rule , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_no_empty_rules ( self ) : <EOL> rules = policy . get_rules ( ) <EOL> for rule in rules : <EOL> self . assertNotEqual ( '<STR_LIT>' , str ( rule ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % rule ) <EOL> def test_allow_all_rules ( self ) : <EOL> for rule in self . allow_all_rules : <EOL> policy . enforce ( self . non_admin_context , rule , self . target ) <EOL> def test_rule_missing ( self ) : <EOL> rules = policy . get_rules ( ) <EOL> special_rules = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> result = set ( rules . keys ( ) ) - set ( self . admin_only_rules + <EOL> self . admin_or_owner_rules + self . non_admin_only_rules + <EOL> self . allow_all_rules + special_rules ) <EOL> self . assertEqual ( set ( [ ] ) , result ) </s>
