File size: 826 Bytes
45a105b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { describe, it, expect } from 'vitest'
import { b64urlToBuf, bufToB64url, toCreationOptions } from './passkey'

describe('passkey base64url helpers', () => {
  it('roundtrips bytes', () => {
    const bytes = new Uint8Array([0, 1, 250, 255, 62, 63])
    expect(new Uint8Array(b64urlToBuf(bufToB64url(bytes.buffer)))).toEqual(bytes)
  })
  it('is url-safe (no +/=)', () => {
    const s = bufToB64url(new Uint8Array([251, 255, 191]).buffer)
    expect(s).not.toMatch(/[+/=]/)
  })
  it('converts backend register options to ArrayBuffers', () => {
    const opts = toCreationOptions({ challenge: 'AAAA', user: { id: 'QUJD', name: 'a' }, rp: { name: 'x' } })
    expect(opts.publicKey!.challenge).toBeInstanceOf(ArrayBuffer)
    expect((opts.publicKey!.user as { id: ArrayBuffer }).id).toBeInstanceOf(ArrayBuffer)
  })
})