Skip to content

Commit

Permalink
Fix #439: characters in usernames in URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Ross committed Jul 14, 2016
1 parent ebd8248 commit 54f92ed
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 6 deletions.
29 changes: 29 additions & 0 deletions cadasta/organization/tests/test_urls_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,25 @@ def test_organization_users_detail(self):
kwargs={'slug': 'org-slug', 'username': 'n_smith'}) ==
version_url('/organizations/org-slug/users/n_smith/'))

assert (reverse(version_ns('organization:users_detail'),
kwargs={'slug': 'org-slug',
'username': 'n_smith-@+.'}) ==
version_url('/organizations/org-slug/users/n_smith-@+./'))

resolved = resolve(
version_url('/organizations/org-slug/users/n_smith/'))

assert resolved.func.__name__ == api.OrganizationUsersDetail.__name__
assert resolved.kwargs['slug'] == 'org-slug'
assert resolved.kwargs['username'] == 'n_smith'

resolved = resolve(
version_url('/organizations/org-slug/users/n_smith-@+./'))

assert resolved.func.__name__ == api.OrganizationUsersDetail.__name__
assert resolved.kwargs['slug'] == 'org-slug'
assert resolved.kwargs['username'] == 'n_smith-@+.'


class ProjectUrlTest(TestCase):

Expand Down Expand Up @@ -96,9 +108,26 @@ def test_project_users_detail(self):
'/organizations/habitat/projects/123abc/users/barbara/')
assert actual == expected

actual = reverse(
version_ns('organization:project_users_detail'),
kwargs={'organization': 'habitat',
'project': '123abc',
'username': 'barbara-@+.'}
)
expected = version_url(
'/organizations/habitat/projects/123abc/users/barbara-@+./')
assert actual == expected

resolved = resolve(version_url(
'/organizations/habitat/projects/123abc/users/barbara/'))
assert resolved.func.__name__ == api.ProjectUsersDetail.__name__
assert resolved.kwargs['organization'] == 'habitat'
assert resolved.kwargs['project'] == '123abc'
assert resolved.kwargs['username'] == 'barbara'

resolved = resolve(version_url(
'/organizations/habitat/projects/123abc/users/barbara-@+./'))
assert resolved.func.__name__ == api.ProjectUsersDetail.__name__
assert resolved.kwargs['organization'] == 'habitat'
assert resolved.kwargs['project'] == '123abc'
assert resolved.kwargs['username'] == 'barbara-@+.'
37 changes: 37 additions & 0 deletions cadasta/organization/tests/test_urls_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,19 @@ def test_user_activate(self):
url = reverse('user:activate', kwargs={'user': 'user-name'})
assert (url == '/users/user-name/activate/')

url = reverse('user:activate', kwargs={'user': 'user-name-with-+@.'})
assert (url == '/users/user-name-with-+@./activate/')

resolved = resolve('/users/user-name/activate/')
assert resolved.func.__name__ == default.UserActivation.__name__
assert resolved.kwargs['user'] == 'user-name'
assert resolved.func.view_initkwargs['new_state'] is True

resolved = resolve('/users/user-name-with-+@./activate/')
assert resolved.func.__name__ == default.UserActivation.__name__
assert resolved.kwargs['user'] == 'user-name-with-+@.'
assert resolved.func.view_initkwargs['new_state'] is True

def test_user_deactivate(self):
url = reverse('user:deactivate', kwargs={'user': 'user-name'})
assert (url == '/users/user-name/deactivate/')
Expand Down Expand Up @@ -205,21 +213,50 @@ def test_member_edit(self):
)
assert url == '/organizations/org-slug/members/some-user/'

url = reverse(
'organization:members_edit',
kwargs={'slug': 'org-slug', 'username': 'some-user-with-+@.'}
)
assert url == '/organizations/org-slug/members/some-user-with-+@./'

resolved = resolve('/organizations/org-slug/members/some-user/')
assert (resolved.func.__name__ ==
default.OrganizationMembersEdit.__name__)
assert resolved.kwargs['slug'] == 'org-slug'
assert resolved.kwargs['username'] == 'some-user'

resolved = resolve(
'/organizations/org-slug/members/some-user-with-+@./'
)
assert (resolved.func.__name__ ==
default.OrganizationMembersEdit.__name__)
assert resolved.kwargs['slug'] == 'org-slug'
assert resolved.kwargs['username'] == 'some-user-with-+@.'

def test_member_remove(self):
url = reverse(
'organization:members_remove',
kwargs={'slug': 'org-slug', 'username': 'some-user'}
)
assert url == '/organizations/org-slug/members/some-user/remove/'

url = reverse(
'organization:members_remove',
kwargs={'slug': 'org-slug', 'username': 'some-user-with-+@.'}
)
assert (url ==
'/organizations/org-slug/members/some-user-with-+@./remove/')

resolved = resolve('/organizations/org-slug/members/some-user/remove/')
assert (resolved.func.__name__ ==
default.OrganizationMembersRemove.__name__)
assert resolved.kwargs['slug'] == 'org-slug'
assert resolved.kwargs['username'] == 'some-user'

resolved = resolve(
'/organizations/org-slug/members/some-user-with-+@./remove/'
)
assert (resolved.func.__name__ ==
default.OrganizationMembersRemove.__name__)
assert resolved.kwargs['slug'] == 'org-slug'
assert resolved.kwargs['username'] == 'some-user-with-+@.'
4 changes: 2 additions & 2 deletions cadasta/organization/urls/api/organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
api.OrganizationUsers.as_view(),
name='users'),
url(
r'^(?P<slug>[-\w]+)/users/(?P<username>[-\w]+)/$',
r'^(?P<slug>[-\w]+)/users/(?P<username>[-@+.\w]+)/$',
api.OrganizationUsersDetail.as_view(),
name='users_detail'),
url(
Expand All @@ -33,7 +33,7 @@
name='project_users'),
url(
r'^(?P<organization>[-\w]+)/projects/'
'(?P<project>[-\w]+)/users/(?P<username>[-\w]+)/$',
'(?P<project>[-\w]+)/users/(?P<username>[-@+.\w]+)/$',
api.ProjectUsersDetail.as_view(),
name='project_users_detail'),
]
4 changes: 2 additions & 2 deletions cadasta/organization/urls/default/organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@
default.OrganizationMembersAdd.as_view(),
name='members_add'),
url(
r'^(?P<slug>[-\w]+)/members/(?P<username>[-\w]+)/$',
r'^(?P<slug>[-\w]+)/members/(?P<username>[-@+.\w]+)/$',
default.OrganizationMembersEdit.as_view(),
name='members_edit'),
url(
r'^(?P<slug>[-\w]+)/members/(?P<username>[-\w]+)/remove/$',
r'^(?P<slug>[-\w]+)/members/(?P<username>[-@+.\w]+)/remove/$',
default.OrganizationMembersRemove.as_view(),
name='members_remove'),
]
4 changes: 2 additions & 2 deletions cadasta/organization/urls/default/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

urlpatterns = [
url(r'^$', default.UserList.as_view(), name='list'),
url(r'^(?P<user>[-\w]+)/activate/$',
url(r'^(?P<user>[-@+.\w]+)/activate/$',
default.UserActivation.as_view(new_state=True),
name='activate'),
url(r'^(?P<user>[-\w]+)/deactivate/$',
url(r'^(?P<user>[-@+.\w]+)/deactivate/$',
default.UserActivation.as_view(new_state=False),
name='deactivate')
]

0 comments on commit 54f92ed

Please sign in to comment.