@luckystack/test-runner 0.1.9 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -2,6 +2,17 @@ import { z, ZodType } from 'zod';
2
2
  import { getPrismaClient } from '@luckystack/core';
3
3
 
4
4
  type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
5
+ type ApiMethodMap$1 = Partial<Record<string, Partial<Record<string, Partial<Record<string, string>>>>>>;
6
+ type SyncMethodMap = Partial<Record<string, Partial<Record<string, Partial<Record<string, string>>>>>>;
7
+ interface ApiMetaEntry {
8
+ method: string;
9
+ auth: {
10
+ login: boolean;
11
+ additional?: Record<string, unknown>[];
12
+ };
13
+ rateLimit?: number | false;
14
+ }
15
+ type ApiMetaMap = Partial<Record<string, Partial<Record<string, Partial<Record<string, ApiMetaEntry>>>>>>;
5
16
  interface EndpointDescriptor {
6
17
  page: string;
7
18
  name: string;
@@ -27,8 +38,9 @@ interface RunContractSummary {
27
38
  results: ContractCheckResult[];
28
39
  }
29
40
 
30
- type ApiMethodMap$6 = Partial<Record<string, Partial<Record<string, Partial<Record<string, string>>>>>>;
31
- declare const walkEndpoints: (apiMethodMap: ApiMethodMap$6) => EndpointDescriptor[];
41
+ type ApiMethodMap = Partial<Record<string, Partial<Record<string, Partial<Record<string, string>>>>>>;
42
+ declare const walkEndpoints: (apiMethodMap: ApiMethodMap) => EndpointDescriptor[];
43
+ declare const walkSyncEndpoints: (syncMethodMap: SyncMethodMap) => EndpointDescriptor[];
32
44
 
33
45
  interface ContractCheckInput {
34
46
  endpoint: EndpointDescriptor;
@@ -51,9 +63,8 @@ interface ContractCheckInput {
51
63
  }
52
64
  declare const runContractCheck: (input: ContractCheckInput) => Promise<ContractCheckResult>;
53
65
 
54
- type ApiMethodMap$5 = Partial<Record<string, Partial<Record<string, Partial<Record<string, string>>>>>>;
55
66
  interface RunContractTestsInput {
56
- apiMethodMap: ApiMethodMap$5;
67
+ apiMethodMap: ApiMethodMap$1;
57
68
  baseUrl: string;
58
69
  /**
59
70
  * Endpoints to skip. Matched against `<page>/<name>` (version-agnostic) and
@@ -76,18 +87,9 @@ interface AuthEnforcementCheckInput {
76
87
  }
77
88
  declare const runAuthEnforcementCheck: (input: AuthEnforcementCheckInput) => Promise<ContractCheckResult>;
78
89
 
79
- type ApiMethodMap$4 = Partial<Record<string, Partial<Record<string, Partial<Record<string, string>>>>>>;
80
- type ApiMetaMap$2 = Partial<Record<string, Partial<Record<string, Partial<Record<string, {
81
- method: string;
82
- auth: {
83
- login: boolean;
84
- additional?: Record<string, unknown>[];
85
- };
86
- rateLimit?: number | false;
87
- }>>>>>>;
88
90
  interface RunAuthEnforcementTestsInput {
89
- apiMethodMap: ApiMethodMap$4;
90
- apiMetaMap: ApiMetaMap$2;
91
+ apiMethodMap: ApiMethodMap$1;
92
+ apiMetaMap: ApiMetaMap;
91
93
  baseUrl: string;
92
94
  skip?: string[];
93
95
  inputFor?: (endpoint: EndpointDescriptor) => unknown;
@@ -106,18 +108,9 @@ interface RateLimitCheckInput {
106
108
  }
107
109
  declare const runRateLimitCheck: (input: RateLimitCheckInput) => Promise<ContractCheckResult>;
108
110
 
109
- type ApiMethodMap$3 = Partial<Record<string, Partial<Record<string, Partial<Record<string, string>>>>>>;
110
- type ApiMetaMap$1 = Partial<Record<string, Partial<Record<string, Partial<Record<string, {
111
- method: string;
112
- auth: {
113
- login: boolean;
114
- additional?: Record<string, unknown>[];
115
- };
116
- rateLimit?: number | false;
117
- }>>>>>>;
118
111
  interface RunRateLimitTestsInput {
119
- apiMethodMap: ApiMethodMap$3;
120
- apiMetaMap: ApiMetaMap$1;
112
+ apiMethodMap: ApiMethodMap$1;
113
+ apiMetaMap: ApiMetaMap;
121
114
  baseUrl: string;
122
115
  skip?: string[];
123
116
  inputFor?: (endpoint: EndpointDescriptor) => unknown;
@@ -143,6 +136,42 @@ interface RunRateLimitTestsInput {
143
136
  }
144
137
  declare const runRateLimitTests: (input: RunRateLimitTestsInput) => Promise<RunContractSummary>;
145
138
 
139
+ interface CsrfEnforcementCheckInput {
140
+ endpoint: EndpointDescriptor;
141
+ baseUrl: string;
142
+ /**
143
+ * A valid session Cookie header (`<name>=<token>`). The probe deliberately
144
+ * carries it so the request passes the auth guard and reaches the CSRF check.
145
+ */
146
+ authCookie: string;
147
+ inputFor?: (endpoint: EndpointDescriptor) => unknown;
148
+ /** Per-call request timeout in ms. Defaults to 5000. */
149
+ requestTimeoutMs?: number;
150
+ /** Error code expected on CSRF rejection. Defaults to `auth.csrfMismatch`. */
151
+ expectedErrorCode?: string;
152
+ /** HTTP status expected on CSRF rejection. Defaults to 403; pass `false` to skip. */
153
+ expectedHttpStatus?: number | false;
154
+ }
155
+ declare const runCsrfEnforcementCheck: (input: CsrfEnforcementCheckInput) => Promise<ContractCheckResult>;
156
+
157
+ interface RunCsrfEnforcementTestsInput {
158
+ apiMethodMap: ApiMethodMap$1;
159
+ apiMetaMap: ApiMetaMap;
160
+ baseUrl: string;
161
+ /** Valid session Cookie header (`<name>=<token>`) the probes carry so they reach the CSRF check. */
162
+ authCookie: string;
163
+ skip?: string[];
164
+ inputFor?: (endpoint: EndpointDescriptor) => unknown;
165
+ /** Per-call request timeout in ms forwarded to each check. */
166
+ requestTimeoutMs?: number;
167
+ /** Error code expected on CSRF rejection. Defaults to `auth.csrfMismatch`. */
168
+ expectedErrorCode?: string;
169
+ /** HTTP status expected on CSRF rejection. Defaults to 403; pass `false` to skip. */
170
+ expectedHttpStatus?: number | false;
171
+ onResult?: (result: ContractCheckResult) => void;
172
+ }
173
+ declare const runCsrfEnforcementTests: (input: RunCsrfEnforcementTestsInput) => Promise<RunContractSummary>;
174
+
146
175
  interface FuzzCheckInput {
147
176
  endpoint: EndpointDescriptor;
148
177
  baseUrl: string;
@@ -152,9 +181,8 @@ interface FuzzCheckInput {
152
181
  }
153
182
  declare const runFuzzCheck: (input: FuzzCheckInput) => Promise<ContractCheckResult>;
154
183
 
155
- type ApiMethodMap$2 = Partial<Record<string, Partial<Record<string, Partial<Record<string, string>>>>>>;
156
184
  interface RunFuzzTestsInput {
157
- apiMethodMap: ApiMethodMap$2;
185
+ apiMethodMap: ApiMethodMap$1;
158
186
  baseUrl: string;
159
187
  skip?: string[];
160
188
  headers?: Record<string, string>;
@@ -165,8 +193,9 @@ declare const runFuzzTests: (input: RunFuzzTestsInput) => Promise<RunContractSum
165
193
  interface ResetServerStateInput {
166
194
  baseUrl: string;
167
195
  token?: string;
196
+ requestTimeoutMs?: number;
168
197
  }
169
- declare const resetServerState: ({ baseUrl, token }: ResetServerStateInput) => Promise<boolean>;
198
+ declare const resetServerState: ({ baseUrl, token, requestTimeoutMs }: ResetServerStateInput) => Promise<boolean>;
170
199
 
171
200
  declare const sampleSchemaInput: (schema: z.ZodType) => unknown;
172
201
 
@@ -211,7 +240,6 @@ interface OpenStreamWatcherInput {
211
240
  }
212
241
  declare const openStreamWatcher: <TChunk extends StreamChunkFrame = StreamChunkFrame>(input: OpenStreamWatcherInput) => Promise<StreamWatcher<TChunk>>;
213
242
 
214
- type ApiMethodMap$1 = Partial<Record<string, Partial<Record<string, Partial<Record<string, string>>>>>>;
215
243
  interface CustomTestCase {
216
244
  name: string;
217
245
  run: (ctx: TestContext) => Promise<void>;
@@ -312,18 +340,9 @@ interface TestExpect {
312
340
  }
313
341
  declare const runCustomTests: (input: RunCustomTestsInput) => Promise<RunCustomTestsSummary>;
314
342
 
315
- type ApiMethodMap = Partial<Record<string, Partial<Record<string, Partial<Record<string, string>>>>>>;
316
- type ApiMetaMap = Partial<Record<string, Partial<Record<string, Partial<Record<string, {
317
- method: string;
318
- auth: {
319
- login: boolean;
320
- additional?: Record<string, unknown>[];
321
- };
322
- rateLimit?: number | false;
323
- }>>>>>>;
324
343
  type ApiInputSchemas = Partial<Record<string, Partial<Record<string, Partial<Record<string, ZodType | undefined>>>>>>;
325
344
  interface RunAllTestsInput {
326
- apiMethodMap: ApiMethodMap;
345
+ apiMethodMap: ApiMethodMap$1;
327
346
  apiMetaMap: ApiMetaMap;
328
347
  apiInputSchemas: ApiInputSchemas;
329
348
  baseUrl: string;
@@ -339,12 +358,19 @@ interface RunAllTestsInput {
339
358
  noSweep?: boolean;
340
359
  noFuzz?: boolean;
341
360
  noRateLimit?: boolean;
361
+ /**
362
+ * Disable the CSRF-enforcement layer. Defaults to ON (the layer runs) — but it
363
+ * can only probe past the auth guard with a session, so it is a no-op unless an
364
+ * `authToken` is supplied.
365
+ */
366
+ noCsrf?: boolean;
342
367
  noCustom?: boolean;
343
368
  }
344
369
  interface RunAllTestsSummary {
345
370
  contract?: RunContractSummary;
346
371
  auth?: RunContractSummary;
347
372
  rateLimit?: RunContractSummary;
373
+ csrf?: RunContractSummary;
348
374
  fuzz?: RunContractSummary;
349
375
  custom?: RunCustomTestsSummary;
350
376
  totalPassed: number;
@@ -430,4 +456,13 @@ declare const registerTestReporter: (newReporter: TestReporter | null) => void;
430
456
  declare const getTestReporter: () => TestReporter | null;
431
457
  declare const resetTestExtensionsForTests: () => void;
432
458
 
433
- export { type AuthEnforcementCheckInput, type ContractCheckInput, type ContractCheckResult, type CustomTestCase, type CustomTestResult, type EndpointDescriptor, type FuzzCheckInput, type HttpMethod, type OpenStreamWatcherInput, type RateLimitCheckInput, type ResetServerStateInput, type RunAllTestsInput, type RunAllTestsSummary, type RunAuthEnforcementTestsInput, type RunContractSummary, type RunContractTestsInput, type RunCustomTestsInput, type RunCustomTestsSummary, type RunFuzzTestsInput, type RunRateLimitTestsInput, type StreamChunkFrame, type StreamWatcher, type TestContext, type TestExpect, type TestFixture, type TestLayer, type TestLayerInput, type TestLayerResult, type TestReporter, type TestResult, type TestSummary, discoverCustomTestFiles, getTestFixture, getTestReporter, listTestLayers, logContractResult, logContractSummary, logRunAllSummary, openStreamWatcher, registerTestFixture, registerTestLayer, registerTestReporter, resetServerState, resetTestExtensionsForTests, runAllTests, runAuthEnforcementCheck, runAuthEnforcementTests, runContractCheck, runContractTests, runCustomTests, runFuzzCheck, runFuzzTests, runRateLimitCheck, runRateLimitTests, sampleSchemaInput, walkEndpoints };
459
+ declare const LAYER_KEYS: {
460
+ readonly contract: "contract";
461
+ readonly auth: "auth-enforcement";
462
+ readonly rateLimit: "rate-limit";
463
+ readonly csrf: "csrf-enforcement";
464
+ readonly fuzz: "fuzz";
465
+ readonly custom: "custom";
466
+ };
467
+
468
+ export { type ApiMetaEntry, type ApiMetaMap, type ApiMethodMap$1 as ApiMethodMap, type AuthEnforcementCheckInput, type ContractCheckInput, type ContractCheckResult, type CsrfEnforcementCheckInput, type CustomTestCase, type CustomTestResult, type EndpointDescriptor, type FuzzCheckInput, type HttpMethod, LAYER_KEYS, type OpenStreamWatcherInput, type RateLimitCheckInput, type ResetServerStateInput, type RunAllTestsInput, type RunAllTestsSummary, type RunAuthEnforcementTestsInput, type RunContractSummary, type RunContractTestsInput, type RunCsrfEnforcementTestsInput, type RunCustomTestsInput, type RunCustomTestsSummary, type RunFuzzTestsInput, type RunRateLimitTestsInput, type StreamChunkFrame, type StreamWatcher, type SyncMethodMap, type TestContext, type TestExpect, type TestFixture, type TestLayer, type TestLayerInput, type TestLayerResult, type TestReporter, type TestResult, type TestSummary, discoverCustomTestFiles, getTestFixture, getTestReporter, listTestLayers, logContractResult, logContractSummary, logRunAllSummary, openStreamWatcher, registerTestFixture, registerTestLayer, registerTestReporter, resetServerState, resetTestExtensionsForTests, runAllTests, runAuthEnforcementCheck, runAuthEnforcementTests, runContractCheck, runContractTests, runCsrfEnforcementCheck, runCsrfEnforcementTests, runCustomTests, runFuzzCheck, runFuzzTests, runRateLimitCheck, runRateLimitTests, sampleSchemaInput, walkEndpoints, walkSyncEndpoints };