{"record":{"id":"206e3a21cb2a18e0","repo":"ruvnet/ruflo","slug":"invalid-token","errorCode":null,"errorMessage":"Invalid token","messagePattern":"Invalid token","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/testing/src/helpers/mock-factory.ts","lineNumber":549,"sourceCode":"    }\n    return { valid: true };\n  });\n\n  mock.hashPassword.mockImplementation(async (password: string) => {\n    return `hashed:${Buffer.from(password).toString('base64')}`;\n  });\n\n  mock.verifyPassword.mockImplementation(async (password: string, hash: string) => {\n    return hash === `hashed:${Buffer.from(password).toString('base64')}`;\n  });\n\n  mock.generateToken.mockImplementation(async (payload: Record<string, unknown>) => {\n    return `token:${Buffer.from(JSON.stringify(payload)).toString('base64')}`;\n  });\n\n  mock.verifyToken.mockImplementation(async (token: string) => {\n    if (!token.startsWith('token:')) {\n      throw new Error('Invalid token');\n    }\n    return JSON.parse(Buffer.from(token.slice(6), 'base64').toString());\n  });\n\n  mock.executeSecurely.mockImplementation(async () => ({\n    stdout: '',\n    stderr: '',\n    exitCode: 0,\n    duration: 100,\n  }));\n\n  return mock;\n}\n\n/**\n * Create mock swarm coordinator\n */\nexport function createMockSwarmCoordinator(): MockedInterface<ISwarmCoordinator> & { state: SwarmState } {","sourceCodeStart":531,"sourceCodeEnd":567,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/testing/src/helpers/mock-factory.ts#L531-L567","documentation":"This mock auth service from the testing mock-factory only accepts tokens minted by its own generateToken(), which produces token: followed by base64-encoded JSON. verifyToken() throws Invalid token for anything else: real JWTs, opaque bearer tokens, or corrupted strings. The mock hash format (hashed: plus base64) and token format are paired by design.","triggerScenarios":"Passing a real JWT or an environment-configured bearer token to mock.verifyToken(); hand-building token strings in tests with the wrong encoding; token truncation or corruption in transit.","commonSituations":"Pointing an app configured with production auth at the test mock without swapping token minting; copying token fixtures from another environment; base64 vs base64url mismatches.","solutions":["Mint tokens in tests with await mock.generateToken(payload) and pass that to verifyToken","If an externally built token is required, construct it as token: plus base64 of JSON.stringify(payload)","Keep the mock generate/verify pair together; do not mix real auth clients with mock verification"],"exampleFix":"// before\nconst payload = await mock.verifyToken(realJwt); // throws: Invalid token\n\n// after\nconst token = await mock.generateToken({ sub: 'user-1' });\nconst payload = await mock.verifyToken(token);","handlingStrategy":"validation","validationCode":"function isMockToken(token: string): boolean {\n  return token.startsWith('token:');\n}\n\nif (!isMockToken(token)) {\n  token = await mock.generateToken({ sub: 'test-user' }); // mint a mock token\n}\nconst payload = await mock.verifyToken(token);","typeGuard":"function isMockToken(token: string): token is string {\n  return token.startsWith('token:') && token.length > 6;\n}","tryCatchPattern":"try {\n  payload = await mock.verifyToken(token);\n} catch (err) {\n  if (err instanceof Error && err.message === 'Invalid token') {\n    const minted = await mock.generateToken(originalPayload);\n    payload = await mock.verifyToken(minted);\n  } else {\n    throw err;\n  }\n}","preventionTips":["Always mint tokens through the mock in test setup instead of reusing env-based tokens","Centralize token creation in one test helper so no test hand-builds token strings","Treat prefix or format mismatches as config smells: never mix mock auth with real auth clients"],"tags":["testing","mocks","auth","token"],"backgroundTag":"invalid-token","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}