コード例 #1
0
  def test_rules_only_(self):
    config_rules_only = """
      [[rules]]
      allow = [
        ['user1', 'res_a', 'GET'],
      ]
      deny = [
        ['user1', 'res_a', 'POST'],
      ]
    """
    ac = AccessControl(config_rules_only)

    is_allowed, reason = ac.check('user1', 'res_a', 'GET')
    self.assertEqual(is_allowed, True)
    self.assertEqual(reason, '[rules.1] "user1" is allowed to do "GET" on "res_a"')

    is_allowed, reason = ac.check('user1', 'res_a', 'POST')
    self.assertEqual(is_allowed, False)
    self.assertEqual(reason, '[rules.1] "user1" is not allowed to do "POST" on "res_a"')
コード例 #2
0
 def test_first_match_deny_(self):
   ac = AccessControl(config_first_match)
   is_allowed, reason = ac.check('user3', 'part_c', 'PUT')
   self.assertEqual(is_allowed, False)
   self.assertEqual(reason, '[rules.r2] "reader" is not allowed to do "PUT" on "res2"')
コード例 #3
0
 def test_first_match_allow_(self):
   ac = AccessControl(config_first_match)
   is_allowed, reason = ac.check('user1', 'part_b', 'GET')
   self.assertEqual(is_allowed, True)
   self.assertEqual(reason, '[rules.r1] "admin" is allowed to do "any action" on "res1"')
コード例 #4
0
 def test_rule_mismatch_(self):
   ac = AccessControl(config_first_match)
   is_allowed, reason = ac.check('user1', 'part_c', 'GET')
   self.assertEqual(is_allowed, True)
   self.assertEqual(reason, 'No matched rule found, use mismatch_decision: True')
コード例 #5
0
 def test_any_allow_deny_(self):
   ac = AccessControl(config_any_allow)
   is_allowed, reason = ac.check('user5', 'part_c', 'POST')
   self.assertEqual(is_allowed, False)
   self.assertEqual(reason, 'All matched rules denied')
コード例 #6
0
 def test_any_allow_allow_(self):
   ac = AccessControl(config_any_allow)
   is_allowed, reason = ac.check('user1', 'part_a', 'POST')
   self.assertEqual(is_allowed, True)
   self.assertEqual(reason, '[rules.r1] "admin" is allowed to do "*" on "res1"')
コード例 #7
0
 def test_all_allow_deny_(self):
   ac = AccessControl(config_all_allow)
   is_allowed, reason = ac.check('user5', 'part_a', 'POST')
   self.assertEqual(is_allowed, False)
   self.assertEqual(reason, '[rules.r2] "reader" is not allowed to do "POST" on "res2"')
コード例 #8
0
 def test_all_allow_allow_(self):
   ac = AccessControl(config_all_allow)
   is_allowed, reason = ac.check('user1', 'part_a', 'PUT')
   self.assertEqual(is_allowed, True)
   self.assertEqual(reason, 'All matched rules allowed')