Add MCP auth helper tests and remove redundant request proof initiali…#354
Add MCP auth helper tests and remove redundant request proof initiali…#354calvadev merged 3 commits intoshopstr-eng:mainfrom
Conversation
|
@YASH-ai-bit is attempting to deploy a commit to the shopstr-eng Team on Vercel. A member of the Team first needs to authorize it. |
arnavkirti
left a comment
There was a problem hiding this comment.
- Use
Date.now = jest.fn()orjest.useFakeTimers()to freeze time, so tests oncreated_atare not flaky over long durations. Right now they rely onDate.now()inline and arithmetic (e.g.,- 3600) which is OK but more brittle. - Consider grouping Nostr auth constants to improve readability, e.g. reuse a base event object and spread it in each test instead of repeating
kind: 27235and thecreated_atcalculation. - Add a test for the case where
verifyEventthrows (if that’s a realistic failure mode) to ensure the helper either catches or propagates as intended.
Also, Is there a dedicated migration for mcp_request_proofs now? If not, can you clarify why it’s safe to remove this CREATE TABLE from initializeApiKeysTable?
|
Thanks for the tip! There isn’t a separate migration for There were two I might be missing something in SQL part, but by functionality, the two looked duplicates. |
Please verify the SQL part once, otherwise Looks good! |
|
Thanks! |
|
LGTM!! |
|
Hey @calvadev, just a quick question about the SQL syntax you fixed. After the fix it has two PRIMARY KEY declarations, one inline and other table-level constraint. It would create error on table creation, please look into it. |
Summary
This PR adds direct test coverage for the MCP auth helpers in
utils/mcp/auth.tsand removes a redundantmcp_request_proofsinitialization block from the same file.What changed
utils/mcp/__tests__/auth.test.tsgenerateApiKey()hashApiKey()verifyApiKey()extractBearerToken()verifyNostrAuth()CREATE TABLE IF NOT EXISTS mcp_request_proofs ...block frominitializeApiKeysTable()inutils/mcp/auth.tsWhy
utils/mcp/__tests__/request-proof-server.test.tsalready covers the request-proof flow, but the helper logic inutils/mcp/auth.tsdid not have direct regression coverage yet.This PR fills that gap and also cleans up the redundant
mcp_request_proofstable/index initialization inutils/mcp/auth.tswhile keeping the intended behavior unchanged.Testing
Ran:
npm test -- utils/mcp/__tests__/auth.test.tsnpm test -- utils/mcp/__tests__/request-proof-server.test.tsNotes
The schema cleanup in
utils/mcp/auth.tsis meant to be behavior-preserving. The samemcp_request_proofstable is already initialized earlier ininitializeApiKeysTable(), so this just keeps a single initialization block there.