mirror of
https://github.com/healthchecks/healthchecks.git
synced 2024-11-24 16:26:49 +00:00
5e051bfc30
Rather than redirecting to login page, return HTTP 403 Forbidden
42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
from hc.api.models import Check
|
|
from hc.test import BaseTestCase
|
|
|
|
|
|
class StatusTestCase(BaseTestCase):
|
|
def setUp(self) -> None:
|
|
super().setUp()
|
|
self.check = Check(project=self.project, name="Alice Was Here")
|
|
self.check.tags = "foo"
|
|
self.check.save()
|
|
|
|
self.url = f"/projects/{self.project.code}/checks/status/"
|
|
|
|
def test_it_works(self) -> None:
|
|
self.client.login(username="alice@example.org", password="password")
|
|
r = self.client.get(self.url)
|
|
self.assertEqual(r.status_code, 200)
|
|
doc = r.json()
|
|
|
|
self.assertEqual(doc["tags"]["foo"], ["up", "1 up"])
|
|
|
|
detail = doc["details"][0]
|
|
self.assertEqual(detail["code"], str(self.check.code))
|
|
self.assertEqual(detail["status"], "new")
|
|
self.assertIn("Never", detail["last_ping"])
|
|
|
|
def test_it_returns_403_for_anon_requests(self) -> None:
|
|
r = self.client.get(self.url)
|
|
self.assertEqual(r.status_code, 403)
|
|
|
|
def test_it_allows_cross_team_access(self) -> None:
|
|
self.client.login(username="bob@example.org", password="password")
|
|
r = self.client.get(self.url)
|
|
self.assertEqual(r.status_code, 200)
|
|
|
|
def test_it_checks_ownership(self) -> None:
|
|
self.client.login(username="charlie@example.org", password="password")
|
|
r = self.client.get(self.url)
|
|
self.assertEqual(r.status_code, 404)
|