Skip to content

Commit 9ae5336

Browse files
authored
test: parse if-none-match headers (#31)
1 parent b224e06 commit 9ae5336

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/fastify/__tests__/cache.test.ts

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { parseIfNoneMatchHeader } from '../cache';
2+
3+
describe('cache', () => {
4+
test('parse if-none-match header', () => {
5+
// Test various combinations of etags with and without weak-validation prefix, with and without
6+
// wrapping quotes, without and without spaces after commas.
7+
const vectors: {
8+
input: string | undefined;
9+
output: string[] | undefined;
10+
}[] = [
11+
{ input: '""', output: undefined },
12+
{ input: '', output: undefined },
13+
{ input: undefined, output: undefined },
14+
{
15+
input: '"bfc13a64729c4290ef5b2c2730249c88ca92d82d"',
16+
output: ['bfc13a64729c4290ef5b2c2730249c88ca92d82d'],
17+
},
18+
{ input: 'W/"67ab43", "54ed21", "7892dd"', output: ['67ab43', '54ed21', '7892dd'] },
19+
{ input: '"fail space" ', output: ['fail space'] },
20+
{ input: 'W/"5e15153d-120f"', output: ['5e15153d-120f'] },
21+
{
22+
input: '"<etag_value>", "<etag_value>" , "asdf"',
23+
output: ['<etag_value>', '<etag_value>', 'asdf'],
24+
},
25+
{
26+
input: '"<etag_value>","<etag_value>","asdf"',
27+
output: ['<etag_value>', '<etag_value>', 'asdf'],
28+
},
29+
{
30+
input: 'W/"<etag_value>","<etag_value>","asdf"',
31+
output: ['<etag_value>', '<etag_value>', 'asdf'],
32+
},
33+
{
34+
input: '"<etag_value>",W/"<etag_value>", W/"asdf", "abcd","123"',
35+
output: ['<etag_value>', '<etag_value>', 'asdf', 'abcd', '123'],
36+
},
37+
];
38+
expect(vectors).toBeTruthy();
39+
for (const entry of vectors) {
40+
const result = parseIfNoneMatchHeader(entry.input);
41+
expect(result).toEqual(entry.output);
42+
}
43+
});
44+
});

0 commit comments

Comments
 (0)