BS-001 Initialize BortStack foundation and project workflow

This commit is contained in:
rob
2026-11-10 14:02:50 +00:00
parent 1ec90a082f
commit 52265961cb
119 changed files with 10298 additions and 64 deletions
+67
View File
@@ -0,0 +1,67 @@
from email_service import EmailDeliveryError
VALID_MESSAGE = {
"name": "Example Person",
"email": "person@example.com",
"subject": "A useful question",
"message": "This message is long enough to be accepted.",
"website": "",
}
def test_contact_delivers_valid_message(client, monkeypatch):
delivered = {}
def capture(**payload):
delivered.update(payload)
monkeypatch.setattr("routes.contact_routes.send_contact_email", capture)
response = client.post("/api/contact", json=VALID_MESSAGE)
assert response.status_code == 200
assert delivered == {
key: VALID_MESSAGE[key] for key in ("name", "email", "subject", "message")
}
def test_contact_rejects_invalid_and_injection_input(client):
assert client.post("/api/contact", json={}).status_code == 400
assert client.post(
"/api/contact",
json={**VALID_MESSAGE, "email": "person@example.com\nBcc:test@example.com"},
).status_code == 400
assert client.post(
"/api/contact",
json={**VALID_MESSAGE, "subject": "Hello\r\nBcc: test@example.com"},
).status_code == 400
assert client.post(
"/api/contact", json={**VALID_MESSAGE, "message": "short"}
).status_code == 400
def test_contact_honeypot_does_not_deliver(client, monkeypatch):
def unexpected(**_payload):
raise AssertionError("honeypot submission must not be delivered")
monkeypatch.setattr("routes.contact_routes.send_contact_email", unexpected)
response = client.post(
"/api/contact", json={**VALID_MESSAGE, "website": "https://bot.invalid"}
)
assert response.status_code == 200
def test_contact_delivery_failure_is_generic(client, monkeypatch):
def fail(**_payload):
raise EmailDeliveryError("provider detail must not escape")
monkeypatch.setattr("routes.contact_routes.send_contact_email", fail)
response = client.post("/api/contact", json=VALID_MESSAGE)
assert response.status_code == 503
assert response.get_json()["message"] == "Unable to send message right now"
def test_contact_rate_limit_rejects_sixth_submission(client, monkeypatch):
monkeypatch.setattr("routes.contact_routes.send_contact_email", lambda **_: None)
responses = [client.post("/api/contact", json=VALID_MESSAGE) for _ in range(6)]
assert [response.status_code for response in responses[:5]] == [200] * 5
assert responses[5].status_code == 429