Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions scripts/check_dev_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,16 @@ def check_routes(base_url, context=None, *, solution_templates_status=401):
("/api/token/", "POST", 400),
):
status, content_type, body = request(base_url, path, method, context)
assert status == expected and content_type == "application/json", (method, path, status, content_type)
json.loads(body)
assert content_type == "application/json", (method, path, status, content_type)
payload = json.loads(body)
# Repeated DEV deploys share the password reset API's anonymous rate limit.
throttled = (
path == "/auth/reset_password/"
and status == 429
and isinstance(payload, dict)
and bool(payload.get("detail"))
)
assert status == expected or throttled, (method, path, status, content_type)
sys.stdout.write(f"API {method} OK: {path} ({status})\n")


Expand Down
20 changes: 20 additions & 0 deletions scripts/tests/test_dev_nginx_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,31 @@
from threading import Thread
import time
import unittest
from unittest.mock import patch

sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from check_dev_routes import check_routes, request # noqa: E402


class DevRoutingSmokeTests(unittest.TestCase):
def test_only_password_reset_can_report_a_rate_limit(self):
def response(_base, path, method="GET", context=None):
if path == "/":
return 200, "text/html", b"<app-root></app-root>"
if "routing_check" in path:
return 200, "text/html", b"" if method == "HEAD" else b"<app-root></app-root>"
if path == throttled_path:
return 429, "application/json", b'{"detail":"Request was throttled."}'
return (400 if method == "POST" else 401), "application/json", b"{}"

with patch("check_dev_routes.request", side_effect=response):
throttled_path = "/auth/reset_password/"
check_routes("https://dev.procollab.ru")
throttled_path = "/api/token/"
with self.assertRaises(AssertionError):
check_routes("https://dev.procollab.ru")


class Backend(BaseHTTPRequestHandler):
def respond(self, status):
body = json.dumps({"backend_method": self.command, "backend_path": self.path}).encode()
Expand Down
Loading