Skip to content
Myr

buffer.test.ts

This file

Path

src/utils/buffer.test.ts

67 lines · 2.2 KiB · TypeScript

Last changed by

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

History of this file

Take it

feat: Basic-auth with polyfill (#86)Yusuke Wadabefore adoptiond5280a1

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

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

lines 2–11why, one step back
2
3describe('buffer', () => {4 const crypto = global.crypto5 beforeAll(() => {6 global.crypto = require('crypto').webcrypto7 })8 afterAll(() => {9 global.crypto = crypto10 })11

feat: Basic-auth with polyfill (#86)Yusuke Wadabefore adoptiond5280a1

lines 12–19why, one step back
12 it('decodeBaes64', async () => {
13 expect(await decodeBase64('aG9vb29vb29vbw==')).toBe('hooooooooo')14 expect(await decodeBase64('54KO')).toBe('炎')1516 expect(await decodeBase64('abcdedf')).not.toBe('abcdef')17 })1819 it('sha256', async () => {

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

lines 20–25why, one step back
20 expect(await sha256('hono')).toBe(
21 '8b3dc17add91b7e8f0b5109a389927d66001139cd9b03fa7b95f83126e1b2b23'22 )23 expect(await sha256('炎')).toBe(24 '1fddc5a562ee1fbeb4fc6def7d4be4911fcdae4273b02ae3a507b170ba0ea169'25 )

feat: Basic-auth with polyfill (#86)Yusuke Wadabefore adoptiond5280a1

lines 26–29why, one step back
26
27 expect(await sha256('abcdedf')).not.toBe('abcdef')28 })29

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

lines 30–45why, one step back
30 it('positive', async () => {
31 expect(32 await timingSafeEqual(33 '127e6fbfe24a750e72930c220a8e138275656b8e5d8f48a98c3c92df2caba935',34 '127e6fbfe24a750e72930c220a8e138275656b8e5d8f48a98c3c92df2caba935'35 )36 ).toBe(true)37 expect(await timingSafeEqual('a', 'a')).toBe(true)38 expect(await timingSafeEqual('', '')).toBe(true)39 expect(await timingSafeEqual(undefined, undefined)).toBe(true)40 expect(await timingSafeEqual(true, true)).toBe(true)41 expect(await timingSafeEqual(false, false)).toBe(true)42 })4344 it('negative', async () => {45 expect(await timingSafeEqual('a', 'b')).toBe(false)

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

lines 46–51why, one step back
46 expect(
47 await timingSafeEqual('a', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')48 ).toBe(false)49 expect(50 await timingSafeEqual('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'a')51 ).toBe(false)

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

lines 52–67why, one step back
52 expect(await timingSafeEqual('alpha', 'beta')).toBe(false)
53 expect(await timingSafeEqual(false, true)).toBe(false)54 expect(await timingSafeEqual(false, undefined)).toBe(false)55 expect(56 await timingSafeEqual(57 () => {},58 () => {}59 )60 ).toBe(false)61 expect(await timingSafeEqual({}, {})).toBe(false)62 expect(await timingSafeEqual({ a: 1 }, { a: 1 })).toBe(false)63 expect(await timingSafeEqual({ a: 1 }, { a: 2 })).toBe(false)64 expect(await timingSafeEqual([1, 2], [1, 2])).toBe(false)65 expect(await timingSafeEqual([1, 2], [1, 2, 3])).toBe(false)66 })67})