1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Fixed #33269 -- Made AnonymousUser/PermissionsMixin.has_perms() raise ValueError on string or non-iterable perm_list.

This commit is contained in:
Lie Ryan
2021-10-11 14:54:50 +11:00
committed by Mariusz Felisiak
parent 4bfe8c0eec
commit 05cde4764d
2 changed files with 19 additions and 0 deletions

View File

@@ -53,6 +53,13 @@ class BaseBackendTest(TestCase):
self.assertIs(self.user.has_perm('group_perm'), True)
self.assertIs(self.user.has_perm('other_perm', TestObj()), False)
def test_has_perms_perm_list_invalid(self):
msg = 'perm_list must be an iterable of permissions.'
with self.assertRaisesMessage(ValueError, msg):
self.user.has_perms('user_perm')
with self.assertRaisesMessage(ValueError, msg):
self.user.has_perms(object())
class CountingMD5PasswordHasher(MD5PasswordHasher):
"""Hasher that counts how many times it computes a hash."""
@@ -476,6 +483,13 @@ class AnonymousUserBackendTest(SimpleTestCase):
self.assertIs(self.user1.has_perms(['anon'], TestObj()), True)
self.assertIs(self.user1.has_perms(['anon', 'perm'], TestObj()), False)
def test_has_perms_perm_list_invalid(self):
msg = 'perm_list must be an iterable of permissions.'
with self.assertRaisesMessage(ValueError, msg):
self.user1.has_perms('perm')
with self.assertRaisesMessage(ValueError, msg):
self.user1.has_perms(object())
def test_has_module_perms(self):
self.assertIs(self.user1.has_module_perms("app1"), True)
self.assertIs(self.user1.has_module_perms("app2"), False)