mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-14 05:36:50 +03:00
parent
1ca5a9d042
commit
c9c383dfad
|
@ -6,7 +6,8 @@ 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