Welcome to mirror list, hosted at ThFree Co, Russian Federation.

util_spec.js « webauthn « authentication « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c9b8bfd86793b6148a2e15db0e2618ae849260d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { base64ToBuffer, bufferToBase64 } from '~/authentication/webauthn/util';

const encodedString = 'SGVsbG8gd29ybGQh';
const stringBytes = [72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 33];

describe('Webauthn utils', () => {
  it('base64ToBuffer', () => {
    const toArray = (val) => new Uint8Array(val);

    expect(base64ToBuffer(encodedString)).toBeInstanceOf(ArrayBuffer);

    expect(toArray(base64ToBuffer(encodedString))).toEqual(toArray(stringBytes));
  });

  it('bufferToBase64', () => {
    const buffer = base64ToBuffer(encodedString);
    expect(bufferToBase64(buffer)).toBe(encodedString);
  });
});