Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions drfpasswordless/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,8 @@ class CallbackToken(AbstractBaseCallbackToken):

class Meta(AbstractBaseCallbackToken.Meta):
verbose_name = 'Callback Token'

def save(self, force_insert=False, force_update=False, using=None,
update_fields=None):
self.full_clean()
super().save(force_insert, force_update, using, update_fields)
9 changes: 8 additions & 1 deletion tests/test_authentication.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from django.core.exceptions import ValidationError
from rest_framework import status
from rest_framework.authtoken.models import Token
from rest_framework.test import APITestCase

from django.contrib.auth import get_user_model
from drfpasswordless.settings import api_settings, DEFAULTS
from drfpasswordless.utils import CallbackToken
from drfpasswordless.utils import CallbackToken, create_callback_token_for_user

User = get_user_model()

Expand All @@ -24,6 +25,12 @@ def test_email_signup_failed(self):
response = self.client.post(self.url, data)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

def test_email_callback_token_create(self):
email = '1234567890' * 23 + '@example.com'
user = User.objects.create(email=email)
with self.assertRaises(ValidationError):
create_callback_token_for_user(user, "EMAIL")

def test_email_signup_success(self):
email = '[email protected]'
data = {'email': email}
Expand Down