mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-18 04:20:53 +03:00
Merge pull request #5149 from tomchuk/master
Don't trim whitespace from authtoken passwords
This commit is contained in:
commit
1e9e1a5bfe
|
@ -6,7 +6,11 @@ from rest_framework import serializers
|
||||||
|
|
||||||
class AuthTokenSerializer(serializers.Serializer):
|
class AuthTokenSerializer(serializers.Serializer):
|
||||||
username = serializers.CharField(label=_("Username"))
|
username = serializers.CharField(label=_("Username"))
|
||||||
password = serializers.CharField(label=_("Password"), style={'input_type': 'password'})
|
password = serializers.CharField(
|
||||||
|
label=_("Password"),
|
||||||
|
style={'input_type': 'password'},
|
||||||
|
trim_whitespace=False
|
||||||
|
)
|
||||||
|
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
username = attrs.get('username')
|
username = attrs.get('username')
|
||||||
|
|
|
@ -27,3 +27,9 @@ class AuthTokenTests(TestCase):
|
||||||
def test_validate_raise_error_if_no_credentials_provided(self):
|
def test_validate_raise_error_if_no_credentials_provided(self):
|
||||||
with pytest.raises(ValidationError):
|
with pytest.raises(ValidationError):
|
||||||
AuthTokenSerializer().validate({})
|
AuthTokenSerializer().validate({})
|
||||||
|
|
||||||
|
def test_whitespace_in_password(self):
|
||||||
|
data = {'username': self.user.username, 'password': 'test pass '}
|
||||||
|
self.user.set_password(data['password'])
|
||||||
|
self.user.save()
|
||||||
|
assert AuthTokenSerializer(data=data).is_valid()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user