Skip to content

Commit c9c383d

Browse files
committed
Don't trim whitespace from authtoken passwords
* Fixes encode#5148
1 parent 1ca5a9d commit c9c383d

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

rest_framework/authtoken/serializers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
class AuthTokenSerializer(serializers.Serializer):
88
username = serializers.CharField(label=_("Username"))
9-
password = serializers.CharField(label=_("Password"), style={'input_type': 'password'})
9+
password = serializers.CharField(label=_("Password"),
10+
style={'input_type': 'password'}, trim_whitespace=False)
1011

1112
def validate(self, attrs):
1213
username = attrs.get('username')

tests/test_authtoken.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,9 @@ def test_token_string_representation(self):
2727
def test_validate_raise_error_if_no_credentials_provided(self):
2828
with pytest.raises(ValidationError):
2929
AuthTokenSerializer().validate({})
30+
31+
def test_whitespace_in_password(self):
32+
data = {'username': self.user.username, 'password': 'test pass '}
33+
self.user.set_password(data['password'])
34+
self.user.save()
35+
assert AuthTokenSerializer(data=data).is_valid()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy