From b23e87e102f52cd5db62e2ba503c19274c40a737 Mon Sep 17 00:00:00 2001 From: Eliot Berriot Date: Tue, 23 Apr 2019 11:35:59 +0200 Subject: [PATCH] Fix #798: Allow users with dots in their usernames to request a subsonic password --- api/funkwhale_api/users/views.py | 1 + api/tests/users/test_views.py | 15 +++++++++++++++ changes/changelog.d/798.bugfix | 1 + 3 files changed, 17 insertions(+) create mode 100644 changes/changelog.d/798.bugfix diff --git a/api/funkwhale_api/users/views.py b/api/funkwhale_api/users/views.py index 85103afc6..8cbb23bd1 100644 --- a/api/funkwhale_api/users/views.py +++ b/api/funkwhale_api/users/views.py @@ -28,6 +28,7 @@ class UserViewSet(mixins.UpdateModelMixin, viewsets.GenericViewSet): queryset = models.User.objects.all() serializer_class = serializers.UserWriteSerializer lookup_field = "username" + lookup_value_regex = r"[a-zA-Z0-9-_.]+" required_scope = "profile" @action(methods=["get"], detail=False) diff --git a/api/tests/users/test_views.py b/api/tests/users/test_views.py index 92e9922bf..57094a838 100644 --- a/api/tests/users/test_views.py +++ b/api/tests/users/test_views.py @@ -225,6 +225,21 @@ def test_user_can_get_subsonic_token(logged_in_api_client): assert response.data == {"subsonic_api_token": "test"} +def test_user_can_request_new_subsonic_token_uncommon_username(logged_in_api_client): + user = logged_in_api_client.user + user.username = "firstname.lastname" + user.subsonic_api_token = "test" + user.save() + + url = reverse( + "api:v1:users:users-subsonic-token", kwargs={"username": user.username} + ) + + response = logged_in_api_client.post(url) + + assert response.status_code == 200 + + def test_user_can_delete_subsonic_token(logged_in_api_client): user = logged_in_api_client.user user.subsonic_api_token = "test" diff --git a/changes/changelog.d/798.bugfix b/changes/changelog.d/798.bugfix new file mode 100644 index 000000000..d1cd2eb6c --- /dev/null +++ b/changes/changelog.d/798.bugfix @@ -0,0 +1 @@ +Allow users with dots in their usernames to request a subsonic password (#798)