mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 19:41:11 +00:00
code formatting
This commit is contained in:
parent
b63d4bec60
commit
9d36722783
3 changed files with 14 additions and 13 deletions
|
@ -29,7 +29,7 @@ class LoginViews(TestCase):
|
||||||
"password",
|
"password",
|
||||||
local=True,
|
local=True,
|
||||||
localname="mouse",
|
localname="mouse",
|
||||||
two_factor_auth=False
|
two_factor_auth=False,
|
||||||
)
|
)
|
||||||
self.rat = models.User.objects.create_user(
|
self.rat = models.User.objects.create_user(
|
||||||
"rat@your.domain.here",
|
"rat@your.domain.here",
|
||||||
|
@ -44,7 +44,7 @@ class LoginViews(TestCase):
|
||||||
"password",
|
"password",
|
||||||
local=True,
|
local=True,
|
||||||
localname="badger",
|
localname="badger",
|
||||||
two_factor_auth=True
|
two_factor_auth=True,
|
||||||
)
|
)
|
||||||
self.anonymous_user = AnonymousUser
|
self.anonymous_user = AnonymousUser
|
||||||
self.anonymous_user.is_authenticated = False
|
self.anonymous_user.is_authenticated = False
|
||||||
|
|
|
@ -34,8 +34,7 @@ class TwoFactorViews(TestCase):
|
||||||
two_factor_auth=True,
|
two_factor_auth=True,
|
||||||
otp_secret="UEWMVJHO23G5XLMVSOCL6TNTSSACJH2X",
|
otp_secret="UEWMVJHO23G5XLMVSOCL6TNTSSACJH2X",
|
||||||
hotp_secret="DRMNMOU7ZRKH5YPW7PADOEYUF7MRIH46",
|
hotp_secret="DRMNMOU7ZRKH5YPW7PADOEYUF7MRIH46",
|
||||||
hotp_count=0
|
hotp_count=0,
|
||||||
|
|
||||||
)
|
)
|
||||||
self.anonymous_user = AnonymousUser
|
self.anonymous_user = AnonymousUser
|
||||||
self.anonymous_user.is_authenticated = False
|
self.anonymous_user.is_authenticated = False
|
||||||
|
@ -74,7 +73,7 @@ class TwoFactorViews(TestCase):
|
||||||
"""check 2FA login works"""
|
"""check 2FA login works"""
|
||||||
view = views.Confirm2FA.as_view()
|
view = views.Confirm2FA.as_view()
|
||||||
form = forms.Confirm2FAForm()
|
form = forms.Confirm2FAForm()
|
||||||
totp = pyotp.TOTP('UEWMVJHO23G5XLMVSOCL6TNTSSACJH2X')
|
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
|
||||||
|
@ -84,7 +83,6 @@ 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_get_disable_2fa(self, *_):
|
def test_get_disable_2fa(self, *_):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
view = views.Disable2FA.as_view()
|
view = views.Disable2FA.as_view()
|
||||||
|
@ -149,8 +147,8 @@ class TwoFactorViews(TestCase):
|
||||||
|
|
||||||
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"):
|
||||||
|
@ -158,14 +156,14 @@ class TwoFactorViews(TestCase):
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
result.context_data["form"]["otp"].errors[0],
|
result.context_data["form"]["otp"].errors[0],
|
||||||
'Incorrect code',
|
"Incorrect code",
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_post_login_with_2fa_expired(self, *_):
|
def test_post_login_with_2fa_expired(self, *_):
|
||||||
"""check 2FA login fails"""
|
"""check 2FA login fails"""
|
||||||
view = views.LoginWith2FA.as_view()
|
view = views.LoginWith2FA.as_view()
|
||||||
form = forms.Confirm2FAForm()
|
form = forms.Confirm2FAForm()
|
||||||
totp = pyotp.TOTP('UEWMVJHO23G5XLMVSOCL6TNTSSACJH2X')
|
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)
|
||||||
|
@ -173,14 +171,15 @@ class TwoFactorViews(TestCase):
|
||||||
|
|
||||||
middleware = SessionMiddleware(request)
|
middleware = SessionMiddleware(request)
|
||||||
middleware.process_request(request)
|
middleware.process_request(request)
|
||||||
request.session['2fa_user'] = self.local_user.username
|
request.session["2fa_user"] = self.local_user.username
|
||||||
request.session['2fa_auth_time'] = "1663977030"
|
request.session["2fa_auth_time"] = "1663977030"
|
||||||
|
|
||||||
with patch("bookwyrm.views.preferences.two_factor_auth.LoginWith2FA"):
|
with patch("bookwyrm.views.preferences.two_factor_auth.LoginWith2FA"):
|
||||||
result = view(request)
|
result = view(request)
|
||||||
self.assertEqual(result.url, "/")
|
self.assertEqual(result.url, "/")
|
||||||
self.assertEqual(result.status_code, 302)
|
self.assertEqual(result.status_code, 302)
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Edit2FA
|
Edit2FA
|
||||||
- get ✔
|
- get ✔
|
||||||
|
|
|
@ -109,7 +109,9 @@ class LoginWith2FA(View):
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
"""Check 2FA code and allow/disallow login"""
|
"""Check 2FA code and allow/disallow login"""
|
||||||
user = models.User.objects.get(username=request.session["2fa_user"])
|
user = models.User.objects.get(username=request.session["2fa_user"])
|
||||||
elapsed_time = datetime.now() - datetime.fromtimestamp(int(request.session["2fa_auth_time"]))
|
elapsed_time = datetime.now() - datetime.fromtimestamp(
|
||||||
|
int(request.session["2fa_auth_time"])
|
||||||
|
)
|
||||||
form = forms.Confirm2FAForm(request.POST, instance=user)
|
form = forms.Confirm2FAForm(request.POST, instance=user)
|
||||||
# don't allow the login credentials to last too long before completing login
|
# don't allow the login credentials to last too long before completing login
|
||||||
if elapsed_time > timedelta(seconds=60):
|
if elapsed_time > timedelta(seconds=60):
|
||||||
|
|
Loading…
Reference in a new issue