Document and verify admin analytics endpoint authentication - #34
Open
samuel2926i39-art wants to merge 1 commit into
Open
Document and verify admin analytics endpoint authentication#34samuel2926i39-art wants to merge 1 commit into
samuel2926i39-art wants to merge 1 commit into
Conversation
Verifies all /api/admin/* routes (including the four analytics endpoints the dashboard calls) already enforce adminAuthMiddleware via router.use(), returning 401 for missing/invalid bearer tokens. Adds a docs page covering token configuration, scope, expiration, and rotation, and a test suite that exercises every admin route's auth boundary without requiring a live database.
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
Resolves the auth gap flagged in #22 for the indexer's admin analytics
endpoints: the four
/api/admin/analytics/*routes (and the rest of/api/admin/*) were already gated byadminAuthMiddleware, but there wasno documentation of the token scheme and no test coverage proving the
enforcement actually holds. This PR adds both.
docs/admin-authentication.md: documents howADMIN_SECRETisconfigured, its scope (all-or-nothing across
/api/admin/*), that it hasno built-in expiration, and the manual rotation procedure. Also confirms
no request logger dumps the
Authorizationheader today, and flags thatas an invariant to preserve.
indexer/test/api/admin-auth.test.js: a new test suite covering every/api/admin/*route (API keys, audit log, and all four analyticsroutes) — asserts 401 on missing header, 401 on an invalid bearer token,
and 200 with the correct DB call on a valid token for a representative
analytics route.
Before / after
Before: auth enforcement existed in code but was undocumented and
untested — a future refactor of
routes/admin.jscould silently droprouter.use(adminAuthMiddleware)from a new route with nothing to catch it.After: the auth contract is documented, and the test suite fails loudly
if any
/api/admin/*route stops enforcing authentication or startsreturning the wrong status code.
Testing
indexer/src/admin/adminAuth.jsandindexer/src/routes/admin.jsdirectly to confirm
router.use(adminAuthMiddleware)applies to allseven routes, including all four analytics endpoints, before writing the
tests.
jest.unstable_mockModuleon../../src/db.js) so it doesn't require a live Postgres instance, unlikethe other
test/api/*.test.jsfiles.available and installing one was out of scope for this change. The suite
follows this repo's existing supertest + jest ESM conventions
(see
test/api/wallet.test.js), so it should run as-is vianpm test --prefix indexer(glob already includestest/api/*.test.js).Please run CI/local tests to confirm before merging.
Closes #22