Merge pull request #5149 from tomchuk/master

Don't trim whitespace from authtoken passwords
This commit is contained in:
Xavier Ordoquy 2017-05-18 09:12:48 +00:00 committed by GitHub
commit 1e9e1a5bfe
2 changed files with 11 additions and 1 deletions

View File

@ -6,7 +6,11 @@ from rest_framework import serializers
class AuthTokenSerializer(serializers.Serializer):
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):
username = attrs.get('username')

View File

@ -27,3 +27,9 @@ class AuthTokenTests(TestCase):
def test_validate_raise_error_if_no_credentials_provided(self):
with pytest.raises(ValidationError):
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()