Don't trim whitespace from authtoken passwords

* Fixes #5148
parent 1ca5a9d0
......@@ -6,7 +6,8 @@ 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')
......
......@@ -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()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment