Skip to content

Commit 92cfc9a

Browse files
committed
test: export skew protection config and assert that configuration file was written with it instead of inlining it again in test
1 parent fae7557 commit 92cfc9a

File tree

2 files changed

+21
-45
lines changed

2 files changed

+21
-45
lines changed

src/build/skew-protection.test.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
EnabledOrDisabledReason,
1010
setSkewProtection,
1111
shouldEnableSkewProtection,
12+
skewProtectionConfig,
1213
} from './skew-protection.js'
1314

1415
// Mock fs promises
@@ -298,27 +299,7 @@ describe('setSkewProtection', () => {
298299
expect(mkdir).toHaveBeenCalledWith('/test/path', { recursive: true })
299300
expect(writeFile).toHaveBeenCalledWith(
300301
'/test/path/skew-protection.json',
301-
JSON.stringify(
302-
{
303-
patterns: ['.*'],
304-
sources: [
305-
{
306-
type: 'cookie',
307-
name: '__vdpl',
308-
},
309-
{
310-
type: 'header',
311-
name: 'X-Deployment-Id',
312-
},
313-
{
314-
type: 'query',
315-
name: 'dpl',
316-
},
317-
],
318-
},
319-
null,
320-
2,
321-
),
302+
JSON.stringify(skewProtectionConfig),
322303
)
323304
})
324305

src/build/skew-protection.ts

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@ const optInOptions = new Set([
2020
EnabledOrDisabledReason.OPT_IN_ENV_VAR,
2121
])
2222

23+
export const skewProtectionConfig = {
24+
patterns: ['.*'],
25+
sources: [
26+
{
27+
type: 'cookie',
28+
name: '__vdpl',
29+
},
30+
{
31+
type: 'header',
32+
name: 'X-Deployment-Id',
33+
},
34+
{
35+
type: 'query',
36+
name: 'dpl',
37+
},
38+
],
39+
}
40+
2341
export function shouldEnableSkewProtection(ctx: PluginContext) {
2442
let enabledOrDisabledReason: EnabledOrDisabledReason = EnabledOrDisabledReason.OPT_OUT_DEFAULT
2543

@@ -85,28 +103,5 @@ export const setSkewProtection = async (ctx: PluginContext, span: Span) => {
85103
await mkdir(dirname(ctx.skewProtectionConfigPath), {
86104
recursive: true,
87105
})
88-
await writeFile(
89-
ctx.skewProtectionConfigPath,
90-
JSON.stringify(
91-
{
92-
patterns: ['.*'],
93-
sources: [
94-
{
95-
type: 'cookie',
96-
name: '__vdpl',
97-
},
98-
{
99-
type: 'header',
100-
name: 'X-Deployment-Id',
101-
},
102-
{
103-
type: 'query',
104-
name: 'dpl',
105-
},
106-
],
107-
},
108-
null,
109-
2,
110-
),
111-
)
106+
await writeFile(ctx.skewProtectionConfigPath, JSON.stringify(skewProtectionConfig))
112107
}

0 commit comments

Comments
 (0)