|
1 | | - |
2 | 1 | from django.test import TestCase, override_settings |
3 | 2 |
|
4 | | -from thunderbird_accounts.authentication.models import AllowListEntry, User |
| 3 | +from thunderbird_accounts.authentication.models import AllowListEntry, User, UsernameBlockListEntry |
5 | 4 | from thunderbird_accounts.authentication.reserved import is_reserved, servers, support |
6 | 5 | from thunderbird_accounts.authentication.utils import is_email_in_allow_list |
7 | 6 |
|
| 7 | + |
8 | 8 | class IsReservedUnitTests(TestCase): |
9 | 9 | def test_brand_names(self): |
10 | 10 | for brand in ['thunderbird', 'thundermail', 'tbpro', 'mozilla', 'firefox', 'help', 'support', 'mzla']: |
@@ -95,6 +95,25 @@ def test_partial_matches_should_pass(self): |
95 | 95 | for name in ['user123', 'myusernamex', 'rooted', 'teamwork', 'contacting']: |
96 | 96 | self.assertFalse(is_reserved(name)) |
97 | 97 |
|
| 98 | + def test_username_block_list_entries(self): |
| 99 | + block_list_entries = ['skeletons', 'dog*', 'pizza'] |
| 100 | + for name in block_list_entries: |
| 101 | + name = name.replace('*', '') |
| 102 | + self.assertFalse(is_reserved(name)) |
| 103 | + |
| 104 | + for name in block_list_entries: |
| 105 | + UsernameBlockListEntry.objects.create(pattern=name) |
| 106 | + |
| 107 | + # Add some entries that will pass with the wildcard entry (dog) |
| 108 | + block_list_entries += ['dog-dog', 'dog-skeleton'] |
| 109 | + # Add some entries that will fail the wildcard entry (dog) |
| 110 | + not_reserved_entries = ['skeleton-dog', 'skeletons2'] |
| 111 | + |
| 112 | + for name in block_list_entries: |
| 113 | + self.assertTrue(is_reserved(name)) |
| 114 | + for name in not_reserved_entries: |
| 115 | + self.assertFalse(is_reserved(name)) |
| 116 | + |
98 | 117 |
|
99 | 118 | @override_settings(USE_ALLOW_LIST=True) |
100 | 119 | class IsEmailInAllowListUnitTests(TestCase): |
|
0 commit comments