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.

50 lines
1.8 KiB

9 years ago
9 years ago
9 years ago
  1. from django.contrib.auth.hashers import make_password
  2. from hc.test import BaseTestCase
  3. class CheckTokenTestCase(BaseTestCase):
  4. def setUp(self):
  5. super(CheckTokenTestCase, self).setUp()
  6. self.profile.token = make_password("secret-token", "login")
  7. self.profile.save()
  8. self.checks_url = "/projects/%s/checks/" % self.project.code
  9. def test_it_shows_form(self):
  10. r = self.client.get("/accounts/check_token/alice/secret-token/")
  11. self.assertContains(r, "You are about to log in")
  12. def test_it_redirects(self):
  13. r = self.client.post("/accounts/check_token/alice/secret-token/")
  14. self.assertRedirects(r, self.checks_url)
  15. # After login, token should be blank
  16. self.profile.refresh_from_db()
  17. self.assertEqual(self.profile.token, "")
  18. def test_it_redirects_already_logged_in(self):
  19. # Login
  20. self.client.login(username="[email protected]", password="password")
  21. # Login again, when already authenticated
  22. r = self.client.post("/accounts/check_token/alice/secret-token/")
  23. self.assertRedirects(r, self.checks_url)
  24. def test_it_redirects_bad_login(self):
  25. # Login with a bad token
  26. url = "/accounts/check_token/alice/invalid-token/"
  27. r = self.client.post(url, follow=True)
  28. self.assertRedirects(r, "/accounts/login/")
  29. self.assertContains(r, "incorrect or expired")
  30. def test_it_handles_next_parameter(self):
  31. url = "/accounts/check_token/alice/secret-token/?next=" + self.channels_url
  32. r = self.client.post(url)
  33. self.assertRedirects(r, self.channels_url)
  34. def test_it_ignores_bad_next_parameter(self):
  35. url = "/accounts/check_token/alice/secret-token/?next=/evil/"
  36. r = self.client.post(url)
  37. self.assertRedirects(r, self.checks_url)