-
Notifications
You must be signed in to change notification settings - Fork 579
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle missing vary header values
Co-authored-by: SukkaW <[email protected]>
- Loading branch information
Showing
4 changed files
with
83 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const { describe, test } = require('node:test') | ||
const assert = require('node:assert') | ||
const { parseVaryHeader } = require('../../lib/util/cache.js') | ||
|
||
describe('parseVaryHeader', () => { | ||
test('handles missing headers with null', () => { | ||
const result = parseVaryHeader('Accept-Encoding, Authorization', {}) | ||
assert.deepStrictEqual(result, { | ||
'accept-encoding': null, | ||
authorization: null | ||
}) | ||
}) | ||
|
||
test('handles mix of present and missing headers', () => { | ||
const result = parseVaryHeader('Accept-Encoding, Authorization', { | ||
authorization: 'Bearer token' | ||
Check failure Code scanning / CodeQL Hard-coded credentials Critical test
The hard-coded value "Bearer token" is used as
authorization header Error loading related location Loading |
||
}) | ||
assert.deepStrictEqual(result, { | ||
'accept-encoding': null, | ||
authorization: 'Bearer token' | ||
Check failure Code scanning / CodeQL Hard-coded credentials Critical test
The hard-coded value "Bearer token" is used as
authorization header Error loading related location Loading |
||
}) | ||
}) | ||
|
||
test('handles array input', () => { | ||
const result = parseVaryHeader(['Accept-Encoding', 'Authorization'], { | ||
'accept-encoding': 'gzip' | ||
}) | ||
assert.deepStrictEqual(result, { | ||
'accept-encoding': 'gzip', | ||
authorization: null | ||
}) | ||
}) | ||
|
||
test('preserves existing * behavior', () => { | ||
const headers = { accept: 'text/html' } | ||
const result = parseVaryHeader('*', headers) | ||
assert.deepStrictEqual(result, headers) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters