This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/passbook/recovery/tests.py

36 lines
1.2 KiB
Python
Raw Normal View History

2019-10-14 15:12:56 +00:00
"""recovery tests"""
from io import StringIO
from django.core.management import call_command
from django.shortcuts import reverse
from django.test import TestCase
from passbook.core.models import Nonce, User
from passbook.lib.config import CONFIG
2019-10-14 15:12:56 +00:00
class TestRecovery(TestCase):
"""recovery tests"""
def setUp(self):
2019-12-31 11:51:16 +00:00
self.user = User.objects.create_user(username="recovery-test-user")
2019-10-14 15:12:56 +00:00
def test_create_key(self):
"""Test creation of a new key"""
CONFIG.update_from_dict({"domain": "testserver"})
2019-10-14 15:12:56 +00:00
out = StringIO()
self.assertEqual(len(Nonce.objects.all()), 0)
2019-12-31 11:51:16 +00:00
call_command("create_recovery_key", "1", self.user.username, stdout=out)
self.assertIn("https://testserver/recovery/use-nonce/", out.getvalue())
self.assertEqual(len(Nonce.objects.all()), 1)
2019-10-14 15:12:56 +00:00
def test_recovery_view(self):
"""Test recovery view"""
out = StringIO()
2019-12-31 11:51:16 +00:00
call_command("create_recovery_key", "1", self.user.username, stdout=out)
nonce = Nonce.objects.first()
2019-12-31 11:51:16 +00:00
self.client.get(
reverse("passbook_recovery:use-nonce", kwargs={"uuid": str(nonce.uuid)})
2019-12-31 11:51:16 +00:00
)
self.assertEqual(int(self.client.session["_auth_user_id"]), nonce.user.pk)