mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
Send security notification when recovery code is used or created by admin (#5719)
* Send security notification when recovery code is used or created by admin "Where to store recovery codes" is one of these problems there is no right answer to, so many people store them in a less-than-optimal place. If that's the reality we live in, this PR adds at least a little security so one notices when they get used :) * Add sentence
This commit is contained in:
@@ -42,8 +42,10 @@ from django.contrib.auth.tokens import (
|
||||
)
|
||||
from django.core import mail as djmail
|
||||
from django.test import RequestFactory, TestCase, override_settings
|
||||
from django.utils.crypto import get_random_string
|
||||
from django.utils.timezone import now
|
||||
from django_otp.oath import TOTP
|
||||
from django_otp.plugins.otp_static.models import StaticDevice
|
||||
from django_otp.plugins.otp_totp.models import TOTPDevice
|
||||
from webauthn.authentication.verify_authentication_response import (
|
||||
VerifiedAuthentication,
|
||||
@@ -492,6 +494,20 @@ class Login2FAFormTest(TestCase):
|
||||
|
||||
m.undo()
|
||||
|
||||
def test_recovery_code_valid(self):
|
||||
djmail.outbox = []
|
||||
d, __ = StaticDevice.objects.get_or_create(user=self.user, name='emergency')
|
||||
token = d.token_set.create(token=get_random_string(length=12, allowed_chars='1234567890'))
|
||||
|
||||
response = self.client.get('/control/login/2fa')
|
||||
assert 'token' in response.content.decode()
|
||||
response = self.client.post('/control/login/2fa', {
|
||||
'token': token.token,
|
||||
})
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertIn('/control/', response['Location'])
|
||||
assert "recovery code" in djmail.outbox[0].body
|
||||
|
||||
|
||||
class FakeRedis(object):
|
||||
def get_redis_connection(self, connection_string):
|
||||
|
||||
Reference in New Issue
Block a user