summaryrefslogtreecommitdiffhomepage
path: root/packages/server/src/assertion/generateAssertionOptions.test.ts
blob: bd2d48d8a6b95955f7e7b38b6a959d788f4ee7de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import generateAssertionOptions from './generateAssertionOptions';

test('should generate credential request options suitable for sending via JSON', () => {
  const challenge = 'totallyrandomvalue';

  const options = generateAssertionOptions({
    ...goodOpts1,
    timeout: 1,
    challenge,
  });

  expect(options).toEqual({
    challenge,
    allowCredentials: [
      {
        id: 'MTIzNA==',
        type: 'public-key',
        transports: ['usb', 'ble', 'nfc', 'internal'],
      },
      {
        id: 'NTY3OA==',
        type: 'public-key',
        transports: ['usb', 'ble', 'nfc', 'internal'],
      },
    ],
    timeout: 1,
  });
});

test('defaults to 60 seconds if no timeout is specified', () => {
  const options = generateAssertionOptions(goodOpts1);

  expect(options.timeout).toEqual(60000);
});

test('should not set userVerification if not specified', () => {
  const options = generateAssertionOptions(goodOpts1);

  expect(options.userVerification).toEqual(undefined);
});

test('should set userVerification if specified', () => {
  const options = generateAssertionOptions({
    ...goodOpts1,
    userVerification: 'required',
  });

  expect(options.userVerification).toEqual('required');
});

test('should set extensions if specified', () => {
  const options = generateAssertionOptions({
    ...goodOpts1,
    extensions: { appid: 'simplewebauthn' },
  });

  expect(options.extensions).toEqual({
    appid: 'simplewebauthn',
  });
});

const goodOpts1 = {
  challenge: 'totallyrandomvalue',
  allowedBase64CredentialIDs: [
    Buffer.from('1234', 'ascii').toString('base64'),
    Buffer.from('5678', 'ascii').toString('base64'),
  ],
};