MCPcopy
hub / github.com/vitest-dev/vitest / isValidApiRequest

Function isValidApiRequest

packages/vitest/src/api/check.ts:5–22  ·  view source on GitHub ↗
(config: ResolvedConfig, req: IncomingMessage)

Source from the content-addressed store, hash-verified

3import crypto from 'node:crypto'
4
5export function isValidApiRequest(config: ResolvedConfig, req: IncomingMessage): boolean {
6 const url = new URL(req.url ?? '', 'http://localhost')
7
8 // validate token. token is injected in ui/tester/orchestrator html, which is cross origin protected.
9 try {
10 const token = url.searchParams.get('token')
11 if (token && crypto.timingSafeEqual(
12 Buffer.from(token),
13 Buffer.from(config.api.token),
14 )) {
15 return true
16 }
17 }
18 // an error is thrown when the length is incorrect
19 catch {}
20
21 return false
22}

Callers 4

setupFunction · 0.90
configureServerFunction · 0.85
setupBrowserRpcFunction · 0.85
handlerFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected