Skip to content

Commit 1e9e1a5

Browse files
authored
Merge pull request encode#5149 from tomchuk/master
Don't trim whitespace from authtoken passwords
2 parents 1ca5a9d + 70205cc commit 1e9e1a5

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

rest_framework/authtoken/serializers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
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(
10+
label=_("Password"),
11+
style={'input_type': 'password'},
12+
trim_whitespace=False
13+
)
1014

1115
def validate(self, attrs):
1216
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