Add API key auth, secure CORS defaults, and a Postgres-backed integration suite - #6
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Authentication
POST /push/send,GET /devices/all,DELETE /devices) requireAuthorization: Bearer <API_KEY>, validated by a FastAPI dependency with constant-time comparison; missing/invalid credentials get 401 withWWW-Authenticate: BearerPOST /devices/registerstays open by design: it is called by the iOS app, and shipping the key in the app binary would expose it — worst case is junk registrations, which APNs pruning removesAPI_KEYis unsetCORS
CORS_ORIGINSlists explicit origins;main.pygained acreate_app()factory so this is testableEndpoint and config hygiene
GET /devices/clear(an unauthenticated destructive GET) is nowDELETE /deviceswith auth; a regression test pins the old route as goneDB_ECHO(statements include device tokens)DB_ECHOandAPNS_USE_SANDBOXIntegration test suite
tests/integration/boots the realuvicornprocess against real Postgres and drives it over HTTP: startup schema creation, the full device lifecycle, every auth path, empty-recipient push through the authed stack, and graceful shutdown (asserted exit code 0)INTEGRATION_DB_HOSTis setscripts/e2e_apns_sandbox.pychecked in as the documented manual check against Apple's real sandbox (needs credentials, so not CI-able)Test plan
ruff format --check, and mypy cleanAPI_KEY, clean shutdown