@bleedingdev/modern-js-server-runtime-extensions 3.9.0-ultramodern.8 → 3.9.3-ultramodern.1

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.
Files changed (85) hide show
  1. package/README.md +3 -1
  2. package/dist/cjs/backend-federation-security/index.js +73 -152
  3. package/dist/cjs/bff-policy/index.js +7 -0
  4. package/dist/cjs/bff-policy/node.js +20 -4
  5. package/dist/cjs/bff-policy/operationContracts.js +150 -135
  6. package/dist/cjs/bff-policy/operationIdentity.js +81 -0
  7. package/dist/cjs/bff-policy/producer.js +79 -0
  8. package/dist/cjs/localisedLoader.js +65 -0
  9. package/dist/cjs/localisedLoaderPlugin.js +2 -2
  10. package/dist/cjs/module-federation-css/remote.js +2 -1
  11. package/dist/cjs/static-serving/staticModuleFederation.js +49 -12
  12. package/dist/esm/backend-federation-security/index.mjs +73 -152
  13. package/dist/esm/bff-policy/index.mjs +1 -0
  14. package/dist/esm/bff-policy/operationIdentity.mjs +30 -0
  15. package/dist/esm/bff-policy/producer.mjs +31 -0
  16. package/dist/esm/localisedLoader.mjs +24 -0
  17. package/dist/esm/localisedLoaderPlugin.mjs +2 -2
  18. package/dist/esm/module-federation-css/remote.mjs +2 -1
  19. package/dist/esm-node/backend-federation-security/index.mjs +73 -152
  20. package/dist/esm-node/bff-policy/index.mjs +1 -0
  21. package/dist/esm-node/bff-policy/node.mjs +1 -0
  22. package/dist/esm-node/bff-policy/operationContracts.mjs +5 -27
  23. package/dist/esm-node/bff-policy/operationIdentity.mjs +31 -0
  24. package/dist/esm-node/bff-policy/producer.mjs +32 -0
  25. package/dist/esm-node/localisedLoader.mjs +25 -0
  26. package/dist/esm-node/localisedLoaderPlugin.mjs +2 -2
  27. package/dist/esm-node/module-federation-css/remote.mjs +2 -1
  28. package/dist/esm-node/static-serving/staticModuleFederation.mjs +49 -12
  29. package/dist/types/backend-federation-security/node.d.ts +1 -1
  30. package/dist/types/bff-policy/index.d.ts +1 -0
  31. package/dist/types/bff-policy/node.d.ts +1 -0
  32. package/dist/types/bff-policy/operationContracts.d.ts +2 -41
  33. package/dist/types/bff-policy/operationIdentity.d.ts +34 -0
  34. package/dist/types/bff-policy/producer.d.ts +10 -0
  35. package/dist/types/localisedLoader.d.ts +15 -0
  36. package/dist/types/module-federation-css/remote.d.ts +2 -0
  37. package/dist/types-esm/backend-federation-security/node.d.mts +1 -1
  38. package/dist/types-esm/bff-policy/index.d.mts +1 -0
  39. package/dist/types-esm/bff-policy/node.d.mts +1 -0
  40. package/dist/types-esm/bff-policy/operationContracts.d.mts +2 -41
  41. package/dist/types-esm/bff-policy/operationIdentity.d.mts +34 -0
  42. package/dist/types-esm/bff-policy/producer.d.mts +10 -0
  43. package/dist/types-esm/localisedLoader.d.mts +15 -0
  44. package/dist/types-esm/module-federation-css/remote.d.mts +2 -0
  45. package/package.json +47 -19
  46. package/src/backend-federation-security/index.ts +151 -318
  47. package/src/backend-federation-security/node.ts +24 -22
  48. package/src/bff-policy/index.ts +1 -0
  49. package/src/bff-policy/node.ts +1 -0
  50. package/src/bff-policy/operationContracts.ts +13 -86
  51. package/src/bff-policy/operationIdentity.ts +90 -0
  52. package/src/bff-policy/producer.ts +40 -0
  53. package/src/contract-gate-snapshot-store/resolve.ts +0 -1
  54. package/src/localisedLoader.ts +50 -0
  55. package/src/localisedLoaderPlugin.ts +6 -7
  56. package/src/module-federation-css/remote.ts +3 -1
  57. package/src/static-serving/staticModuleFederation.ts +127 -22
  58. package/rslib.config.mts +0 -38
  59. package/rstest.config.mts +0 -18
  60. package/tests/backendFederationSecurity.test.ts +0 -416
  61. package/tests/bff-policy/crossProjectPolicy.matrix.test.ts +0 -450
  62. package/tests/bff-policy/crossProjectPolicy.test.ts +0 -197
  63. package/tests/bff-policy/operationContracts.test.ts +0 -221
  64. package/tests/bff-policy/optionalZodPeer.test.ts +0 -30
  65. package/tests/bff-policy/resolveCrossProjectPolicy.test.ts +0 -76
  66. package/tests/contractGateSnapshotObserver.test.ts +0 -347
  67. package/tests/contractGateSnapshotStore.test.ts +0 -225
  68. package/tests/env.test.ts +0 -54
  69. package/tests/helpers.ts +0 -20
  70. package/tests/localisedLoader.test.ts +0 -120
  71. package/tests/mfCache.test.ts +0 -63
  72. package/tests/moduleFederationCss.test.ts +0 -348
  73. package/tests/nativeErrorResponse.test.ts +0 -118
  74. package/tests/nativeServerAssembly.test.ts +0 -385
  75. package/tests/runtimeLifecycle.test.ts +0 -159
  76. package/tests/static-serving/ordering.test.ts +0 -214
  77. package/tests/static-serving/static.test.ts +0 -411
  78. package/tests/telemetry.test.ts +0 -248
  79. package/tests/telemetryHealthMonitor.test.ts +0 -183
  80. package/tests/telemetryHealthObservation.test.ts +0 -302
  81. package/tests/telemetryLifecycle.test.ts +0 -123
  82. package/tests/telemetryRegistryQueueMatrix.test.ts +0 -130
  83. package/tests/telemetryTraceparent.test.ts +0 -167
  84. package/tests/tsconfig.json +0 -11
  85. package/tsconfig.json +0 -10
@@ -1,450 +0,0 @@
1
- import {
2
- type CrossProjectPolicyConfig,
3
- type CrossProjectPolicyViolationReason,
4
- evaluateCrossProjectPolicy,
5
- } from '../../src/bff-policy/crossProjectPolicy';
6
-
7
- const ENVELOPE_HEADER = 'x-modernjs-bff-envelope';
8
- const OPERATION_CONTEXT_HEADER = 'x-operation-id';
9
- const OPERATION_CONTEXT_DETAIL_HEADER = 'x-modernjs-bff-operation-context';
10
- const VERIFIED_PRODUCER_HEADER = 'x-verified-producer';
11
-
12
- const OMIT = Symbol('omit header');
13
-
14
- type RawHeader = {
15
- kind: 'raw';
16
- value: string;
17
- };
18
-
19
- type HeaderInput = RawHeader | unknown | typeof OMIT;
20
-
21
- type PolicyMatrixScenario = {
22
- name: string;
23
- headers?: Record<string, unknown>;
24
- envelope?: HeaderInput;
25
- operationContext?: string | typeof OMIT;
26
- detail?: HeaderInput;
27
- config: CrossProjectPolicyConfig;
28
- nodeEnv?: string;
29
- expected:
30
- | {
31
- kind: 'allow';
32
- }
33
- | {
34
- kind: 'deny';
35
- reason: CrossProjectPolicyViolationReason;
36
- };
37
- };
38
-
39
- const raw = (value: string): RawHeader => ({
40
- kind: 'raw',
41
- value,
42
- });
43
-
44
- const isRawHeader = (value: HeaderInput): value is RawHeader =>
45
- Boolean(
46
- value &&
47
- typeof value === 'object' &&
48
- 'kind' in value &&
49
- value.kind === 'raw',
50
- );
51
-
52
- const encodeHeader = (value: HeaderInput): string =>
53
- isRawHeader(value) ? value.value : JSON.stringify(value);
54
-
55
- const validEnvelope = {
56
- requestId: 'crm.producer-a',
57
- };
58
-
59
- const validOperationContext = 'crm.producer-a:GET:/api/customer';
60
-
61
- const validDetail = {
62
- requestId: 'crm.producer-a',
63
- operationId: validOperationContext,
64
- method: 'GET',
65
- routePath: '/api/customer',
66
- schemaHash: 'schema-1',
67
- operationVersion: 1,
68
- };
69
-
70
- const strictContractConfig = {
71
- enabled: true,
72
- expectedOperationContracts: {
73
- 'GET:/api/customer': {
74
- schemaHash: 'schema-1',
75
- operationVersion: 1,
76
- },
77
- },
78
- } satisfies CrossProjectPolicyConfig;
79
-
80
- const verifyProducerHeader = (headers: Record<string, unknown>) =>
81
- typeof headers[VERIFIED_PRODUCER_HEADER] === 'string'
82
- ? headers[VERIFIED_PRODUCER_HEADER]
83
- : undefined;
84
-
85
- const buildHeaders = ({
86
- headers,
87
- envelope,
88
- operationContext,
89
- detail,
90
- }: Pick<
91
- PolicyMatrixScenario,
92
- 'headers' | 'envelope' | 'operationContext' | 'detail'
93
- >): Record<string, unknown> => {
94
- const result: Record<string, unknown> = {
95
- ...headers,
96
- };
97
-
98
- const envelopeInput = envelope ?? validEnvelope;
99
- if (envelopeInput !== OMIT) {
100
- result[ENVELOPE_HEADER] = encodeHeader(envelopeInput);
101
- }
102
-
103
- const operationContextInput = operationContext ?? validOperationContext;
104
- if (operationContextInput !== OMIT) {
105
- result[OPERATION_CONTEXT_HEADER] = operationContextInput;
106
- }
107
-
108
- const detailInput = detail ?? validDetail;
109
- if (detailInput !== OMIT) {
110
- result[OPERATION_CONTEXT_DETAIL_HEADER] = encodeHeader(detailInput);
111
- }
112
-
113
- return result;
114
- };
115
-
116
- const withNodeEnv = <T>(nodeEnv: string | undefined, callback: () => T): T => {
117
- if (!nodeEnv) {
118
- return callback();
119
- }
120
-
121
- const previousNodeEnv = process.env.NODE_ENV;
122
- process.env.NODE_ENV = nodeEnv;
123
- try {
124
- return callback();
125
- } finally {
126
- if (typeof previousNodeEnv === 'undefined') {
127
- delete process.env.NODE_ENV;
128
- } else {
129
- process.env.NODE_ENV = previousNodeEnv;
130
- }
131
- }
132
- };
133
-
134
- const policyMatrix = [
135
- {
136
- name: 'allow: full valid context with verified namespace and contract',
137
- headers: {
138
- [VERIFIED_PRODUCER_HEADER]: 'crm',
139
- },
140
- config: {
141
- ...strictContractConfig,
142
- allowedNamespaces: ['crm'],
143
- verifyProducerIdentity: verifyProducerHeader,
144
- },
145
- expected: {
146
- kind: 'allow',
147
- },
148
- },
149
- {
150
- name: 'allow: valid context with optional detail operationId omitted',
151
- detail: {
152
- requestId: 'crm.producer-a',
153
- method: 'GET',
154
- routePath: '/api/customer',
155
- schemaHash: 'schema-1',
156
- operationVersion: 1,
157
- },
158
- config: strictContractConfig,
159
- expected: {
160
- kind: 'allow',
161
- },
162
- },
163
- {
164
- name: 'deny: envelope header missing',
165
- envelope: OMIT,
166
- config: strictContractConfig,
167
- expected: {
168
- kind: 'deny',
169
- reason: 'missing_envelope',
170
- },
171
- },
172
- {
173
- name: 'deny: envelope header is not JSON',
174
- envelope: raw('not-json'),
175
- config: strictContractConfig,
176
- expected: {
177
- kind: 'deny',
178
- reason: 'invalid_envelope',
179
- },
180
- },
181
- {
182
- name: 'deny: envelope header JSON is not an object',
183
- envelope: 123,
184
- config: strictContractConfig,
185
- expected: {
186
- kind: 'deny',
187
- reason: 'invalid_envelope',
188
- },
189
- },
190
- {
191
- name: 'deny: envelope requestId missing',
192
- envelope: {},
193
- config: strictContractConfig,
194
- expected: {
195
- kind: 'deny',
196
- reason: 'missing_request_id',
197
- },
198
- },
199
- {
200
- name: 'deny: namespace outside verified allowlist',
201
- headers: {
202
- [VERIFIED_PRODUCER_HEADER]: 'billing',
203
- },
204
- envelope: {
205
- requestId: 'billing.producer-a',
206
- },
207
- operationContext: 'billing.producer-a:GET:/api/customer',
208
- detail: {
209
- requestId: 'billing.producer-a',
210
- operationId: 'billing.producer-a:GET:/api/customer',
211
- method: 'GET',
212
- routePath: '/api/customer',
213
- schemaHash: 'schema-1',
214
- operationVersion: 1,
215
- },
216
- config: {
217
- ...strictContractConfig,
218
- allowedNamespaces: ['crm'],
219
- verifyProducerIdentity: verifyProducerHeader,
220
- },
221
- expected: {
222
- kind: 'deny',
223
- reason: 'namespace_not_allowed',
224
- },
225
- },
226
- {
227
- name: 'deny: producer identity cannot be verified',
228
- config: {
229
- ...strictContractConfig,
230
- verifyProducerIdentity: () => undefined,
231
- },
232
- expected: {
233
- kind: 'deny',
234
- reason: 'producer_identity_mismatch',
235
- },
236
- },
237
- {
238
- name: 'deny: producer identity does not match envelope namespace',
239
- headers: {
240
- [VERIFIED_PRODUCER_HEADER]: 'billing',
241
- },
242
- config: {
243
- ...strictContractConfig,
244
- verifyProducerIdentity: verifyProducerHeader,
245
- },
246
- expected: {
247
- kind: 'deny',
248
- reason: 'producer_identity_mismatch',
249
- },
250
- },
251
- {
252
- name: 'deny: allowlist without producer verifier fails closed',
253
- config: {
254
- enabled: true,
255
- allowedNamespaces: ['crm'],
256
- requireOperationContext: false,
257
- },
258
- expected: {
259
- kind: 'deny',
260
- reason: 'producer_identity_mismatch',
261
- },
262
- },
263
- {
264
- name: 'deny: operation context header missing',
265
- operationContext: OMIT,
266
- config: strictContractConfig,
267
- expected: {
268
- kind: 'deny',
269
- reason: 'missing_operation_context',
270
- },
271
- },
272
- {
273
- name: 'deny: operation context requestId does not match envelope',
274
- operationContext: 'billing.producer-a:GET:/api/customer',
275
- config: strictContractConfig,
276
- expected: {
277
- kind: 'deny',
278
- reason: 'operation_context_mismatch',
279
- },
280
- },
281
- {
282
- name: 'deny: operation context details header missing',
283
- detail: OMIT,
284
- config: strictContractConfig,
285
- expected: {
286
- kind: 'deny',
287
- reason: 'missing_operation_context_details',
288
- },
289
- },
290
- {
291
- name: 'deny: operation context details header is not JSON',
292
- detail: raw('not-json'),
293
- config: strictContractConfig,
294
- expected: {
295
- kind: 'deny',
296
- reason: 'invalid_operation_context_details',
297
- },
298
- },
299
- {
300
- name: 'deny: operation context details JSON is not an object',
301
- detail: ['not-an-object'],
302
- config: strictContractConfig,
303
- expected: {
304
- kind: 'deny',
305
- reason: 'invalid_operation_context_details',
306
- },
307
- },
308
- {
309
- name: 'deny: operation context details requestId mismatch',
310
- detail: {
311
- ...validDetail,
312
- requestId: 'billing.producer-a',
313
- },
314
- config: strictContractConfig,
315
- expected: {
316
- kind: 'deny',
317
- reason: 'operation_context_details_request_id_mismatch',
318
- },
319
- },
320
- {
321
- name: 'deny: operation context detail operationId conflicts with header',
322
- detail: {
323
- requestId: 'crm.producer-a',
324
- operationId: 'crm.producer-a:GET:/api/invoice',
325
- method: 'GET',
326
- routePath: '/api/invoice',
327
- schemaHash: 'schema-invoice',
328
- operationVersion: 1,
329
- },
330
- config: {
331
- enabled: true,
332
- expectedOperationContracts: {
333
- 'GET:/api/invoice': {
334
- schemaHash: 'schema-invoice',
335
- operationVersion: 1,
336
- },
337
- },
338
- },
339
- expected: {
340
- kind: 'deny',
341
- reason: 'operation_context_mismatch',
342
- },
343
- },
344
- {
345
- name: 'deny: operation schema hash missing',
346
- detail: {
347
- requestId: 'crm.producer-a',
348
- operationId: validOperationContext,
349
- method: 'GET',
350
- routePath: '/api/customer',
351
- operationVersion: 1,
352
- },
353
- config: strictContractConfig,
354
- expected: {
355
- kind: 'deny',
356
- reason: 'missing_operation_schema_hash',
357
- },
358
- },
359
- {
360
- name: 'deny: operation schema hash mismatches contract',
361
- detail: {
362
- ...validDetail,
363
- schemaHash: 'schema-actual',
364
- },
365
- config: {
366
- enabled: true,
367
- expectedOperationContracts: {
368
- 'GET:/api/customer': {
369
- schemaHash: 'schema-expected',
370
- operationVersion: 1,
371
- },
372
- },
373
- },
374
- expected: {
375
- kind: 'deny',
376
- reason: 'operation_schema_hash_mismatch',
377
- },
378
- },
379
- {
380
- name: 'deny: operation version missing',
381
- detail: {
382
- requestId: 'crm.producer-a',
383
- operationId: validOperationContext,
384
- method: 'GET',
385
- routePath: '/api/customer',
386
- schemaHash: 'schema-1',
387
- },
388
- config: strictContractConfig,
389
- expected: {
390
- kind: 'deny',
391
- reason: 'missing_operation_version',
392
- },
393
- },
394
- {
395
- name: 'deny: operation version mismatches contract',
396
- detail: {
397
- ...validDetail,
398
- operationVersion: 2,
399
- },
400
- config: strictContractConfig,
401
- expected: {
402
- kind: 'deny',
403
- reason: 'operation_version_mismatch',
404
- },
405
- },
406
- {
407
- name: 'deny: unknown operation contract',
408
- operationContext: 'crm.producer-a:GET:/api/unknown',
409
- detail: {
410
- requestId: 'crm.producer-a',
411
- operationId: 'crm.producer-a:GET:/api/unknown',
412
- method: 'GET',
413
- routePath: '/api/unknown',
414
- schemaHash: 'schema-1',
415
- operationVersion: 1,
416
- },
417
- config: strictContractConfig,
418
- expected: {
419
- kind: 'deny',
420
- reason: 'unknown_operation_contract',
421
- },
422
- },
423
- {
424
- name: 'deny: empty operation contract map fails closed',
425
- config: {
426
- enabled: true,
427
- expectedOperationContracts: {},
428
- },
429
- expected: {
430
- kind: 'deny',
431
- reason: 'unknown_operation_contract',
432
- },
433
- },
434
- ] satisfies PolicyMatrixScenario[];
435
-
436
- describe('cross-project policy matrix', () => {
437
- for (const scenario of policyMatrix) {
438
- test(scenario.name, () => {
439
- const violation = withNodeEnv(scenario.nodeEnv, () =>
440
- evaluateCrossProjectPolicy(buildHeaders(scenario), scenario.config),
441
- );
442
-
443
- if (scenario.expected.kind === 'allow') {
444
- expect(violation).toBeNull();
445
- } else {
446
- expect(violation?.reason).toBe(scenario.expected.reason);
447
- }
448
- });
449
- }
450
- });
@@ -1,197 +0,0 @@
1
- import {
2
- type CrossProjectOperationContract,
3
- evaluateCrossProjectPolicy,
4
- resolveCrossProjectRequestObservation,
5
- } from '../../src/bff-policy/crossProjectPolicy';
6
- import { buildOperationContractMap } from '../../src/bff-policy/operationContracts';
7
-
8
- // Header/reason permutations live in crossProjectPolicy.matrix.test.ts.
9
- // This file only covers behaviour that matrix cannot express: binding a
10
- // contract to the *observed* request.
11
- describe('cross-project policy', () => {
12
- test('denies operation metadata that does not match the observed request', () => {
13
- const contracts = buildOperationContractMap({
14
- handlers: [
15
- { name: 'getCustomer', httpMethod: 'GET', routePath: '/api/customer' },
16
- {
17
- name: 'createInvoice',
18
- httpMethod: 'POST',
19
- routePath: '/api/invoice',
20
- },
21
- ],
22
- requestId: 'crm.producer-a',
23
- });
24
- const forgedContract = contracts['POST:/api/invoice']!;
25
-
26
- const violation = evaluateCrossProjectPolicy(
27
- {
28
- 'x-modernjs-bff-envelope': JSON.stringify({
29
- requestId: forgedContract.requestId,
30
- }),
31
- 'x-operation-id': forgedContract.operationId,
32
- 'x-modernjs-bff-operation-context': JSON.stringify(forgedContract),
33
- },
34
- { enabled: true, expectedOperationContracts: contracts },
35
- { method: 'GET', routePath: '/api/customer' },
36
- );
37
-
38
- expect(violation?.reason).toBe('operation_context_mismatch');
39
- });
40
-
41
- test('binds operation identity when a manual contract omits operationId', () => {
42
- const requestId = 'crm.producer-a';
43
- const violation = evaluateCrossProjectPolicy(
44
- {
45
- 'x-modernjs-bff-envelope': JSON.stringify({ requestId }),
46
- 'x-operation-id': `${requestId}:forged-operation`,
47
- 'x-modernjs-bff-operation-context': JSON.stringify({
48
- requestId,
49
- operationId: `${requestId}:forged-operation`,
50
- method: 'GET',
51
- routePath: '/api/customer',
52
- schemaHash: 'schema-customer',
53
- operationVersion: 1,
54
- }),
55
- },
56
- {
57
- enabled: true,
58
- expectedOperationContracts: {
59
- 'GET:/api/customer': {
60
- schemaHash: 'schema-customer',
61
- operationVersion: 1,
62
- },
63
- },
64
- },
65
- { method: 'GET', routePath: '/api/customer' },
66
- );
67
-
68
- expect(violation?.reason).toBe('operation_context_mismatch');
69
- });
70
-
71
- test('allows unknown operation contracts when allowUnknownOperations is true', () => {
72
- const violation = evaluateCrossProjectPolicy(
73
- {
74
- 'x-modernjs-bff-envelope': JSON.stringify({
75
- requestId: 'crm.producer-a',
76
- }),
77
- 'x-operation-id': 'crm.producer-a:GET:/api/unknown',
78
- 'x-modernjs-bff-operation-context': JSON.stringify({
79
- requestId: 'crm.producer-a',
80
- operationId: 'crm.producer-a:GET:/api/unknown',
81
- method: 'GET',
82
- routePath: '/api/unknown',
83
- schemaHash: 'schema-1',
84
- operationVersion: 1,
85
- }),
86
- },
87
- {
88
- enabled: true,
89
- allowUnknownOperations: true,
90
- expectedOperationContracts: {
91
- 'GET:/api/customer': { schemaHash: 'schema-1', operationVersion: 1 },
92
- },
93
- },
94
- );
95
-
96
- expect(violation).toBeNull();
97
- });
98
- });
99
-
100
- describe('cross-project request observation', () => {
101
- const resolve = (
102
- pathname: string,
103
- expectedOperationContracts: Record<string, CrossProjectOperationContract>,
104
- method = 'GET',
105
- ) =>
106
- resolveCrossProjectRequestObservation(
107
- { method, pathname },
108
- { expectedOperationContracts },
109
- );
110
-
111
- test('fails closed when two route templates have the same specificity', () => {
112
- expect(
113
- resolve('/foo/42', {
114
- 'GET:/api/:entity/42': {},
115
- 'GET:/api/foo/:id': {},
116
- }),
117
- ).toEqual({ method: 'GET', routePath: '/foo/42' });
118
- });
119
-
120
- test('does not strip a dynamic mount prefix', () => {
121
- expect(
122
- resolve('/products/42', { 'GET:/api/:tenant/products/:id': {} }),
123
- ).toEqual({ method: 'GET', routePath: '/products/42' });
124
- });
125
-
126
- test('fails closed for a nonterminal wildcard template', () => {
127
- expect(resolve('/anything/admin', { 'GET:/api/*/admin': {} })).toEqual({
128
- method: 'GET',
129
- routePath: '/anything/admin',
130
- });
131
- });
132
-
133
- test.each([
134
- '/files/a%2Fb',
135
- '/files/%ZZ',
136
- ])('fails closed for ambiguous or malformed percent encoding in %s', pathname => {
137
- expect(resolve(pathname, { 'GET:/api/files/:id': {} })).toEqual({
138
- method: 'GET',
139
- routePath: pathname,
140
- });
141
- });
142
-
143
- test('preserves trailing-slash distinctions while accepting an exact trailing template', () => {
144
- expect(resolve('/products/42/', { 'GET:/api/products/:id': {} })).toEqual({
145
- method: 'GET',
146
- routePath: '/products/42/',
147
- });
148
- expect(resolve('/products/42/', { 'GET:/api/products/:id/': {} })).toEqual({
149
- method: 'GET',
150
- routePath: '/api/products/:id/',
151
- });
152
- });
153
-
154
- test('binds a mounted root request to the fixed producer prefix', () => {
155
- expect(resolve('/', { 'GET:/api': {} })).toEqual({
156
- method: 'GET',
157
- routePath: '/api',
158
- });
159
- });
160
-
161
- test('denies a GET contract sent to a same-route POST operation', () => {
162
- const contracts = buildOperationContractMap({
163
- handlers: [
164
- {
165
- name: 'getProduct',
166
- httpMethod: 'GET',
167
- routePath: '/api/products/:id',
168
- },
169
- {
170
- name: 'updateProduct',
171
- httpMethod: 'POST',
172
- routePath: '/api/products/:id',
173
- },
174
- ],
175
- requestId: 'catalog.producer-a',
176
- });
177
- const getContract = contracts['GET:/api/products/:id']!;
178
- const observedRequest = resolveCrossProjectRequestObservation(
179
- { method: 'POST', pathname: '/products/42' },
180
- { expectedOperationContracts: contracts },
181
- );
182
-
183
- const violation = evaluateCrossProjectPolicy(
184
- {
185
- 'x-modernjs-bff-envelope': JSON.stringify({
186
- requestId: getContract.requestId,
187
- }),
188
- 'x-operation-id': getContract.operationId,
189
- 'x-modernjs-bff-operation-context': JSON.stringify(getContract),
190
- },
191
- { enabled: true, expectedOperationContracts: contracts },
192
- observedRequest,
193
- );
194
-
195
- expect(violation?.reason).toBe('operation_context_mismatch');
196
- });
197
- });