You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.7 KiB

  1. from hc.accounts.models import Credential
  2. from hc.test import BaseTestCase
  3. class RemoveCredentialTestCase(BaseTestCase):
  4. def setUp(self):
  5. super().setUp()
  6. self.profile.totp = "0" * 32
  7. self.profile.save()
  8. self.url = "/accounts/two_factor/totp/remove/"
  9. def test_it_requires_sudo_mode(self):
  10. self.client.login(username="[email protected]", password="password")
  11. r = self.client.get(self.url)
  12. self.assertContains(r, "We have sent a confirmation code")
  13. def test_it_shows_form(self):
  14. self.client.login(username="[email protected]", password="password")
  15. self.set_sudo_flag()
  16. r = self.client.get(self.url)
  17. self.assertContains(r, "Disable Authenticator App")
  18. self.assertContains(r, "two-factor authentication will no longer be active")
  19. def test_it_skips_warning_when_other_2fa_methods_exist(self):
  20. self.c = Credential.objects.create(user=self.alice, name="Alices Key")
  21. self.client.login(username="[email protected]", password="password")
  22. self.set_sudo_flag()
  23. r = self.client.get(self.url)
  24. self.assertNotContains(r, "two-factor authentication will no longer be active")
  25. def test_it_removes_totp(self):
  26. self.client.login(username="[email protected]", password="password")
  27. self.set_sudo_flag()
  28. r = self.client.post(self.url, {"disable_totp": "1"}, follow=True)
  29. self.assertRedirects(r, "/accounts/profile/")
  30. self.assertContains(r, "Disabled the authenticator app.")
  31. self.profile.refresh_from_db()
  32. self.assertIsNone(self.profile.totp)
  33. self.assertIsNone(self.profile.totp_created)