Skip to content
Myr

buffer.test.ts

This file

Path

src/utils/buffer.test.ts

55 lines · 1.7 KiB · TypeScript

Last changed by

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

History of this file

Take it

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

lines 1–55why, one step back
1import { timingSafeEqual } from './buffer'
23describe('buffer', () => {4 const crypto = global.crypto5 beforeAll(() => {6 global.crypto = require('crypto').webcrypto7 })8 afterAll(() => {9 global.crypto = crypto10 })1112 it('positive', async () => {13 expect(14 await timingSafeEqual(15 '127e6fbfe24a750e72930c220a8e138275656b8e5d8f48a98c3c92df2caba935',16 '127e6fbfe24a750e72930c220a8e138275656b8e5d8f48a98c3c92df2caba935'17 )18 ).toBe(true)19 expect(await timingSafeEqual('a', 'a')).toBe(true)20 expect(await timingSafeEqual('', '')).toBe(true)21 expect(await timingSafeEqual(undefined, undefined)).toBe(true)22 expect(await timingSafeEqual(true, true)).toBe(true)23 expect(await timingSafeEqual(false, false)).toBe(true)24 })2526 it('negative', async () => {27 expect(await timingSafeEqual('a', 'b')).toBe(false)28 expect(29 await timingSafeEqual(30 'a',31 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'32 )33 ).toBe(false)34 expect(35 await timingSafeEqual(36 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',37 'a'38 )39 ).toBe(false)40 expect(await timingSafeEqual('alpha', 'beta')).toBe(false)41 expect(await timingSafeEqual(false, true)).toBe(false)42 expect(await timingSafeEqual(false, undefined)).toBe(false)43 expect(44 await timingSafeEqual(45 () => {},46 () => {}47 )48 ).toBe(false)49 expect(await timingSafeEqual({}, {})).toBe(false)50 expect(await timingSafeEqual({ a: 1 }, { a: 1 })).toBe(false)51 expect(await timingSafeEqual({ a: 1 }, { a: 2 })).toBe(false)52 expect(await timingSafeEqual([1, 2], [1, 2])).toBe(false)53 expect(await timingSafeEqual([1, 2], [1, 2, 3])).toBe(false)54 })55})