|
| 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