Skip to content

Document and verify admin analytics endpoint authentication - #34

Open
samuel2926i39-art wants to merge 1 commit into
octraban:mainfrom
samuel2926i39-art:fix/admin-auth-docs-22
Open

Document and verify admin analytics endpoint authentication#34
samuel2926i39-art wants to merge 1 commit into
octraban:mainfrom
samuel2926i39-art:fix/admin-auth-docs-22

Conversation

@samuel2926i39-art

Copy link
Copy Markdown

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 by adminAuthMiddleware, but there was
no documentation of the token scheme and no test coverage proving the
enforcement actually holds. This PR adds both.

  • docs/admin-authentication.md: documents how ADMIN_SECRET is
    configured, its scope (all-or-nothing across /api/admin/*), that it has
    no built-in expiration, and the manual rotation procedure. Also confirms
    no request logger dumps the Authorization header today, and flags that
    as 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 analytics
    routes) — 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.js could silently drop
router.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 starts
returning the wrong status code.

Testing

  • Reviewed indexer/src/admin/adminAuth.js and indexer/src/routes/admin.js
    directly to confirm router.use(adminAuthMiddleware) applies to all
    seven routes, including all four analytics endpoints, before writing the
    tests.
  • The new test suite mocks the DB pool (jest.unstable_mockModule on
    ../../src/db.js) so it doesn't require a live Postgres instance, unlike
    the other test/api/*.test.js files.
  • Not executed locally — this environment has no Node.js runtime
    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 via
    npm test --prefix indexer (glob already includes test/api/*.test.js).
    Please run CI/local tests to confirm before merging.

Closes #22

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document and verify authentication for the indexer admin analytics endpoints

1 participant