initial commit
Some checks failed
CI / Run tests (push) Has been cancelled
CI / Docker build test (push) Has been cancelled
CI / Lint (ruff + mypy) (push) Has been cancelled

This commit is contained in:
2026-03-30 16:46:26 +07:00
commit 2a7dfa95c8
67 changed files with 5864 additions and 0 deletions

42
tests/test_api_webhook.py Normal file
View File

@@ -0,0 +1,42 @@
import pytest
from httpx import ASGITransport, AsyncClient
from glitchup_bot.api.app import app
from glitchup_bot.config import clear_settings_cache
@pytest.mark.asyncio
async def test_webhook_rejects_invalid_secret(monkeypatch):
monkeypatch.setenv("WEBHOOK_SECRET", "expected-secret")
clear_settings_cache()
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://testserver") as client:
response = await client.post(
"/webhooks/glitchtip", json={"text": "GlitchTip Alert", "attachments": []}
)
assert response.status_code == 403
@pytest.mark.asyncio
async def test_webhook_accepts_valid_secret(monkeypatch):
received = []
async def fake_process(payload: dict) -> None:
received.append(payload)
monkeypatch.setenv("WEBHOOK_SECRET", "expected-secret")
clear_settings_cache()
monkeypatch.setattr("glitchup_bot.api.webhook.process_webhook_payload", fake_process)
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://testserver") as client:
response = await client.post(
"/webhooks/glitchtip",
headers={"X-Webhook-Secret": "expected-secret"},
json={"text": "GlitchTip Alert", "attachments": []},
)
assert response.status_code == 200
assert received == [{"text": "GlitchTip Alert", "attachments": []}]