From 00a1503965b8d5765d5210ec4a4928bdc8ab8668 Mon Sep 17 00:00:00 2001 From: Rafael Cardenas Date: Wed, 2 Oct 2024 14:10:08 -0600 Subject: [PATCH] test: parse if-none-match headers --- src/fastify/__tests__/cache.test.ts | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/fastify/__tests__/cache.test.ts diff --git a/src/fastify/__tests__/cache.test.ts b/src/fastify/__tests__/cache.test.ts new file mode 100644 index 0000000..6281f38 --- /dev/null +++ b/src/fastify/__tests__/cache.test.ts @@ -0,0 +1,44 @@ +import { parseIfNoneMatchHeader } from '../cache'; + +describe('cache', () => { + test('parse if-none-match header', () => { + // Test various combinations of etags with and without weak-validation prefix, with and without + // wrapping quotes, without and without spaces after commas. + const vectors: { + input: string | undefined; + output: string[] | undefined; + }[] = [ + { input: '""', output: undefined }, + { input: '', output: undefined }, + { input: undefined, output: undefined }, + { + input: '"bfc13a64729c4290ef5b2c2730249c88ca92d82d"', + output: ['bfc13a64729c4290ef5b2c2730249c88ca92d82d'], + }, + { input: 'W/"67ab43", "54ed21", "7892dd"', output: ['67ab43', '54ed21', '7892dd'] }, + { input: '"fail space" ', output: ['fail space'] }, + { input: 'W/"5e15153d-120f"', output: ['5e15153d-120f'] }, + { + input: '"", "" , "asdf"', + output: ['', '', 'asdf'], + }, + { + input: '"","","asdf"', + output: ['', '', 'asdf'], + }, + { + input: 'W/"","","asdf"', + output: ['', '', 'asdf'], + }, + { + input: '"",W/"", W/"asdf", "abcd","123"', + output: ['', '', 'asdf', 'abcd', '123'], + }, + ]; + expect(vectors).toBeTruthy(); + for (const entry of vectors) { + const result = parseIfNoneMatchHeader(entry.input); + expect(result).toEqual(entry.output); + } + }); +});