2018-11-16 09:08:15 +00:00
|
|
|
"""passbook Mod 2FA Middleware Test"""
|
2018-11-16 08:10:35 +00:00
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
from django.contrib.auth.models import AnonymousUser
|
|
|
|
from django.test import RequestFactory, TestCase
|
|
|
|
from django.urls import reverse
|
|
|
|
|
2018-11-16 12:08:37 +00:00
|
|
|
from passbook.core.views import overview
|
2018-11-16 09:08:15 +00:00
|
|
|
from passbook.tfa.middleware import tfa_force_verify
|
2018-11-16 08:10:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestMiddleware(TestCase):
|
2018-11-16 09:08:15 +00:00
|
|
|
"""passbook 2FA Middleware Test"""
|
2018-11-16 08:10:35 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
os.environ['RECAPTCHA_TESTING'] = 'True'
|
|
|
|
self.factory = RequestFactory()
|
|
|
|
|
|
|
|
def test_tfa_force_verify_anon(self):
|
2018-11-16 09:08:15 +00:00
|
|
|
"""Test Anonymous TFA Force"""
|
2018-11-16 12:08:37 +00:00
|
|
|
request = self.factory.get(reverse('passbook_core:overview'))
|
2018-11-16 08:10:35 +00:00
|
|
|
request.user = AnonymousUser()
|
2018-11-16 12:08:37 +00:00
|
|
|
response = tfa_force_verify(overview.OverviewView.as_view())(request)
|
2018-11-16 08:10:35 +00:00
|
|
|
self.assertEqual(response.status_code, 302)
|