add test_post_login_with_2fa

This commit is contained in:
Hugh Rundle 2022-10-15 07:11:03 +11:00
parent a1c3f15d80
commit 905aa66f38

View file

@ -110,29 +110,29 @@ class TwoFactorViews(TestCase):
self.assertIsInstance(result, TemplateResponse) self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)
# def test_post_login_with_2fa(self, *_): def test_post_login_with_2fa(self, *_):
# """check 2FA login works""" """check 2FA login works"""
# NOTE this throws a redis error. view = views.LoginWith2FA.as_view()
# Possibly because the function it tests wants to check the user database? form = forms.Confirm2FAForm()
# can we mock that? totp = pyotp.TOTP("UEWMVJHO23G5XLMVSOCL6TNTSSACJH2X")
# view = views.LoginWith2FA.as_view()
# form = forms.Confirm2FAForm()
# totp = pyotp.TOTP('UEWMVJHO23G5XLMVSOCL6TNTSSACJH2X')
# form.data["otp"] = totp.now() form.data["otp"] = totp.now()
# request = self.factory.post("", form.data) request = self.factory.post("", form.data)
# request.user = self.local_user request.user = self.local_user
# middleware = SessionMiddleware(request) middleware = SessionMiddleware(request)
# middleware.process_request(request) middleware.process_request(request)
# request.session['2fa_auth_time'] = time.time() request.session["2fa_auth_time"] = time.time()
# request.session['2fa_user'] = self.local_user.username request.session["2fa_user"] = self.local_user.username
# request.session.save() request.session.save()
# with patch("bookwyrm.views.preferences.two_factor_auth.LoginWith2FA"): with patch("bookwyrm.views.preferences.two_factor_auth.LoginWith2FA"), patch(
# result = view(request) "bookwyrm.views.preferences.two_factor_auth.login"
# self.assertIsInstance(result, TemplateResponse) ):
# self.assertEqual(result.status_code, 200) result = view(request)
self.assertEqual(result.url, "/")
self.assertEqual(result.status_code, 302)
self.assertTrue(request.user.is_authenticated)
def test_post_login_with_2fa_wrong_code(self, *_): def test_post_login_with_2fa_wrong_code(self, *_):
"""check 2FA login fails""" """check 2FA login fails"""