Implement security hardening, notification pipeline, and CI test suite
All checks were successful
CI / test (push) Successful in 9m2s
All checks were successful
CI / test (push) Successful in 9m2s
Security hardening: - Added IP/user rate limiting with Redis-backed counters and fail-open behavior. - Added message anti-spam controls (per-chat rate + duplicate cooldown). - Implemented refresh token rotation with JTI tracking and revoke support. Notification pipeline: - Added Celery app and async notification tasks for mention/offline delivery. - Added Redis-based presence tracking and integrated it into realtime connect/disconnect. - Added notification dispatch from message flow and notifications listing endpoint. Quality gates and CI: - Added pytest async integration tests for auth and chat/message lifecycle. - Added pytest config, test fixtures, and GitHub Actions CI workflow. - Fixed bcrypt/passlib compatibility by pinning bcrypt version. - Documented worker and quality-gate commands in README.
This commit is contained in:
61
tests/test_chat_message_flow.py
Normal file
61
tests/test_chat_message_flow.py
Normal file
@@ -0,0 +1,61 @@
|
||||
from sqlalchemy import select
|
||||
|
||||
from app.auth.models import EmailVerificationToken
|
||||
from app.chats.models import ChatType
|
||||
|
||||
|
||||
async def _create_verified_user(client, db_session, email: str, username: str, password: str) -> dict:
|
||||
await client.post(
|
||||
"/api/v1/auth/register",
|
||||
json={"email": email, "username": username, "password": password},
|
||||
)
|
||||
token_row = await db_session.execute(select(EmailVerificationToken).order_by(EmailVerificationToken.id.desc()))
|
||||
verify_token = token_row.scalar_one().token
|
||||
await client.post("/api/v1/auth/verify-email", json={"token": verify_token})
|
||||
login_response = await client.post("/api/v1/auth/login", json={"email": email, "password": password})
|
||||
return login_response.json()
|
||||
|
||||
|
||||
async def test_private_chat_message_lifecycle(client, db_session):
|
||||
u1 = await _create_verified_user(client, db_session, "u1@example.com", "user_one", "strongpass123")
|
||||
u2 = await _create_verified_user(client, db_session, "u2@example.com", "user_two", "strongpass123")
|
||||
|
||||
me_u2 = await client.get("/api/v1/auth/me", headers={"Authorization": f"Bearer {u2['access_token']}"})
|
||||
u2_id = me_u2.json()["id"]
|
||||
|
||||
create_chat_response = await client.post(
|
||||
"/api/v1/chats",
|
||||
headers={"Authorization": f"Bearer {u1['access_token']}"},
|
||||
json={"type": ChatType.PRIVATE.value, "title": None, "member_ids": [u2_id]},
|
||||
)
|
||||
assert create_chat_response.status_code == 200
|
||||
chat_id = create_chat_response.json()["id"]
|
||||
|
||||
send_message_response = await client.post(
|
||||
"/api/v1/messages",
|
||||
headers={"Authorization": f"Bearer {u1['access_token']}"},
|
||||
json={"chat_id": chat_id, "type": "text", "text": "hello @user_two"},
|
||||
)
|
||||
assert send_message_response.status_code == 201
|
||||
message_id = send_message_response.json()["id"]
|
||||
|
||||
list_messages_response = await client.get(
|
||||
f"/api/v1/messages/{chat_id}",
|
||||
headers={"Authorization": f"Bearer {u2['access_token']}"},
|
||||
)
|
||||
assert list_messages_response.status_code == 200
|
||||
assert len(list_messages_response.json()) == 1
|
||||
|
||||
edit_message_response = await client.put(
|
||||
f"/api/v1/messages/{message_id}",
|
||||
headers={"Authorization": f"Bearer {u1['access_token']}"},
|
||||
json={"text": "edited text"},
|
||||
)
|
||||
assert edit_message_response.status_code == 200
|
||||
assert edit_message_response.json()["text"] == "edited text"
|
||||
|
||||
delete_message_response = await client.delete(
|
||||
f"/api/v1/messages/{message_id}",
|
||||
headers={"Authorization": f"Bearer {u1['access_token']}"},
|
||||
)
|
||||
assert delete_message_response.status_code == 204
|
||||
Reference in New Issue
Block a user