-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR #112 from WayneLambert/develop
Add Two-Factor Authentication by Email
- Loading branch information
Showing
38 changed files
with
761 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,4 +178,4 @@ celerybeat-schedule | |
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
.pyre/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,18 @@ | |
|
||
from django.contrib.auth.models import AnonymousUser | ||
from django.core.files.uploadedfile import InMemoryUploadedFile | ||
from django.utils import timezone | ||
|
||
import pytest | ||
|
||
from django_otp.util import random_hex | ||
from mixer.backend.django import mixer | ||
from PIL import Image | ||
|
||
from apps.blog.models import Category, Post | ||
from apps.blog.tests import helpers | ||
from apps.users.models import EmailToken | ||
from apps.users.utils import get_challenge_expiration_timestamp | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
|
@@ -43,10 +47,34 @@ def auth_user(client, django_user_model, test_password): | |
email='[email protected]', | ||
password=test_password, | ||
) | ||
client.login(username=user.username, password=test_password) | ||
client.login(username=user.get_username(), password=test_password) | ||
return user | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
def device_auth_user(client, auth_user, test_password): | ||
""" An two-factor authenticated user object using device token """ | ||
auth_user.totpdevice_set.create(name='default', key=random_hex(), confirmed=True) | ||
client.login(username=auth_user.get_username(), password=test_password) | ||
return auth_user | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
def email_auth_user(client, auth_user, test_password): | ||
""" An two-factor authenticated user object using email token """ | ||
email_token = EmailToken.objects.create( | ||
challenge_email_address=auth_user.email, | ||
challenge_token='123456', | ||
challenge_generation_timestamp=timezone.now(), | ||
challenge_expiration_timestamp=get_challenge_expiration_timestamp(), | ||
challenge_completed=True, # Emulates challenge passed | ||
user_id=auth_user.pk | ||
) | ||
email_token.save() | ||
client.login(username=auth_user.get_username(), password=test_password) | ||
return auth_user | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
def unauth_user(): | ||
""" An unauthenticated user (i.e. an anonymous user) """ | ||
|
@@ -95,7 +123,7 @@ def li_sec_user(django_user_model, client, test_password, **kwargs): | |
kwargs['last_name'] = 'Morse' | ||
kwargs['email'] = '[email protected]' | ||
user = django_user_model.objects.create_user(pk=3, **kwargs) | ||
client.login(username=user.username, password=test_password) | ||
client.login(username=user.get_username(), password=test_password) | ||
return user | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.