Allow usernames with plus signs in unblock view (#77)

This fixes bug #GH76 where an exception like

```
Reverse for 'defender_unblock_username_view' with arguments '(u'user+test@domain.tld',)' and keyword arguments '{}' not found. 1 pattern(s) tried: [u'admin/defender/blocks/username/(?P[A-Za-z0-9-._@]+)/unblock$']
```

was raised when trying to access the `/admin/defender/blocks/` URL when a user with a plus sign had been locked out.
This commit is contained in:
Israel Saeta Pérez 2017-06-10 16:39:19 +02:00 committed by Ken Cochrane
parent c4f3a61036
commit 69db1cfb70
3 changed files with 14 additions and 2 deletions

View file

@ -1,6 +1,8 @@
from django.conf.urls import url, include from django.conf.urls import url, include
from django.contrib import admin from django.contrib import admin
from .urls import urlpatterns as original_urlpatterns
urlpatterns = [ urlpatterns = [
url(r'^admin/', include(admin.site.urls)), url(r'^admin/', include(admin.site.urls)),
] ] + original_urlpatterns

View file

@ -532,6 +532,16 @@ class AccessAttemptTest(DefenderTestCase):
from .admin import AccessAttemptAdmin from .admin import AccessAttemptAdmin
AccessAttemptAdmin AccessAttemptAdmin
def test_unblock_view_user_with_plus(self):
"""
There is an available admin view for unblocking a user
with a plus sign in the username.
Regression test for #GH76.
"""
reverse('defender_unblock_username_view',
kwargs={'username': 'user+test@test.tld'})
def test_decorator_middleware(self): def test_decorator_middleware(self):
# because watch_login is called twice in this test (once by the # because watch_login is called twice in this test (once by the
# middleware and once by the decorator) we have half as many attempts # middleware and once by the decorator) we have half as many attempts

View file

@ -6,7 +6,7 @@ urlpatterns = [
name="defender_blocks_view"), name="defender_blocks_view"),
url(r'^blocks/ip/(?P<ip_address>[A-Za-z0-9-._]+)/unblock$', unblock_ip_view, url(r'^blocks/ip/(?P<ip_address>[A-Za-z0-9-._]+)/unblock$', unblock_ip_view,
name="defender_unblock_ip_view"), name="defender_unblock_ip_view"),
url(r'^blocks/username/(?P<username>[A-Za-z0-9-._@]+)/unblock$', url(r'^blocks/username/(?P<username>[A-Za-z0-9-._@\+]+)/unblock$',
unblock_username_view, unblock_username_view,
name="defender_unblock_username_view"), name="defender_unblock_username_view"),
] ]