Skip to content
Myr

buffer.test.ts

This file

Path

src/utils/buffer.test.ts

43 lines · 1.7 KiB · TypeScript

Last changed by

feat: basic auth middleware supports overriding `hashFunction` (#128)Yusuke Wadabefore adoption7a31de5

History of this file

Take it

refactor: create `utils/crypto.ts` (#118)Yusuke Wadabefore adoptionbea8aef

line 1why, one step back
1import { timingSafeEqual } from './buffer'

feat: basic auth middleware supports overriding `hashFunction` (#128)Yusuke Wadabefore adoption7a31de5

line 2why, one step back
2import { SHA256 as sha256CryptoJS } from 'crypto-js'

refactor(utils): better management for utils modules to avoid kitchen sink issue (#59)Minghebefore adoptionc522636

lines 3–16why, one step back
3
4describe('buffer', () => {5 it('positive', async () => {6 expect(7 await timingSafeEqual(8 '127e6fbfe24a750e72930c220a8e138275656b8e5d8f48a98c3c92df2caba935',9 '127e6fbfe24a750e72930c220a8e138275656b8e5d8f48a98c3c92df2caba935'10 )11 ).toBe(true)12 expect(await timingSafeEqual('a', 'a')).toBe(true)13 expect(await timingSafeEqual('', '')).toBe(true)14 expect(await timingSafeEqual(undefined, undefined)).toBe(true)15 expect(await timingSafeEqual(true, true)).toBe(true)16 expect(await timingSafeEqual(false, false)).toBe(true)

feat: basic auth middleware supports overriding `hashFunction` (#128)Yusuke Wadabefore adoption7a31de5

line 17why, one step back
17 expect(await timingSafeEqual(true, true, (d: string) => sha256CryptoJS(d).toString()))

refactor(utils): better management for utils modules to avoid kitchen sink issue (#59)Minghebefore adoptionc522636

lines 18–21why, one step back
18 })
1920 it('negative', async () => {21 expect(await timingSafeEqual('a', 'b')).toBe(false)

chore: set up prettier (#106)Yusuke Wadabefore adoption9c397fb

lines 22–27why, one step back
22 expect(
23 await timingSafeEqual('a', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')24 ).toBe(false)25 expect(26 await timingSafeEqual('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'a')27 ).toBe(false)

refactor(utils): better management for utils modules to avoid kitchen sink issue (#59)Minghebefore adoptionc522636

lines 28–43why, one step back
28 expect(await timingSafeEqual('alpha', 'beta')).toBe(false)
29 expect(await timingSafeEqual(false, true)).toBe(false)30 expect(await timingSafeEqual(false, undefined)).toBe(false)31 expect(32 await timingSafeEqual(33 () => {},34 () => {}35 )36 ).toBe(false)37 expect(await timingSafeEqual({}, {})).toBe(false)38 expect(await timingSafeEqual({ a: 1 }, { a: 1 })).toBe(false)39 expect(await timingSafeEqual({ a: 1 }, { a: 2 })).toBe(false)40 expect(await timingSafeEqual([1, 2], [1, 2])).toBe(false)41 expect(await timingSafeEqual([1, 2], [1, 2, 3])).toBe(false)42 })43})