summaryrefslogtreecommitdiffhomepage
path: root/packages/server/src/helpers/parseAuthenticatorData.test.ts
blob: 0e4b1120ab4c7d7fcb82621df9fa96d1ae5a0536 (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
import { assertEquals } from 'https://deno.land/std@0.198.0/assert/mod.ts';

import { parseAuthenticatorData } from './parseAuthenticatorData.ts';
import { AuthenticationExtensionsAuthenticatorOutputs } from './decodeAuthenticatorExtensions.ts';
import { isoBase64URL } from './iso/index.ts';

// Grabbed this from a Conformance test, contains attestation data
const authDataWithAT = isoBase64URL.toBuffer(
  'SZYN5YgOjGh0NBcPZHZgW4/krrmihjLHmVzzuoMdl2NBAAAAJch83ZdWwUm4niTLNjZU81AAIHa7Ksm5br3hAh3UjxP9+4rqu8BEsD+7SZ2xWe1/yHv6pAEDAzkBACBZAQDcxA7Ehs9goWB2Hbl6e9v+aUub9rvy2M7Hkvf+iCzMGE63e3sCEW5Ru33KNy4um46s9jalcBHtZgtEnyeRoQvszis+ws5o4Da0vQfuzlpBmjWT1dV6LuP+vs9wrfObW4jlA5bKEIhv63+jAxOtdXGVzo75PxBlqxrmrr5IR9n8Fw7clwRsDkjgRHaNcQVbwq/qdNwU5H3hZKu9szTwBS5NGRq01EaDF2014YSTFjwtAmZ3PU1tcO/QD2U2zg6eB5grfWDeAJtRE8cbndDWc8aLL0aeC37Q36+TVsGe6AhBgHEw6eO3I3NW5r9v/26CqMPBDwmEundeq1iGyKfMloobIUMBAAE=',
  'base64',
);

// Grabbed this from a Conformance test, contains extension data
const authDataWithED = isoBase64URL.toBuffer(
  'SZYN5YgOjGh0NBcPZHZgW4/krrmihjLHmVzzuoMdl2OBAAAAjaFxZXhhbXBsZS5leHRlbnNpb254dlRoaXMgaXMgYW4gZXhhbXBsZSBleHRlbnNpb24hIElmIHlvdSByZWFkIHRoaXMgbWVzc2FnZSwgeW91IHByb2JhYmx5IHN1Y2Nlc3NmdWxseSBwYXNzaW5nIGNvbmZvcm1hbmNlIHRlc3RzLiBHb29kIGpvYiE=',
  'base64',
);

Deno.test('should parse flags', () => {
  const parsed = parseAuthenticatorData(authDataWithED);

  const { flags } = parsed;

  assertEquals(flags.up, true);
  assertEquals(flags.uv, false);
  assertEquals(flags.be, false);
  assertEquals(flags.bs, false);
  assertEquals(flags.at, false);
  assertEquals(flags.ed, true);
});

Deno.test('should parse attestation data', () => {
  const parsed = parseAuthenticatorData(authDataWithAT);

  const { credentialID, credentialPublicKey, aaguid, counter } = parsed;

  assertEquals(
    isoBase64URL.fromBuffer(credentialID!),
    'drsqybluveECHdSPE_37iuq7wESwP7tJnbFZ7X_Ie_o',
  );
  assertEquals(
    isoBase64URL.fromBuffer(credentialPublicKey!, 'base64'),
    'pAEDAzkBACBZAQDcxA7Ehs9goWB2Hbl6e9v+aUub9rvy2M7Hkvf+iCzMGE63e3sCEW5Ru33KNy4um46s9jalcBHtZgtEnyeRoQvszis+ws5o4Da0vQfuzlpBmjWT1dV6LuP+vs9wrfObW4jlA5bKEIhv63+jAxOtdXGVzo75PxBlqxrmrr5IR9n8Fw7clwRsDkjgRHaNcQVbwq/qdNwU5H3hZKu9szTwBS5NGRq01EaDF2014YSTFjwtAmZ3PU1tcO/QD2U2zg6eB5grfWDeAJtRE8cbndDWc8aLL0aeC37Q36+TVsGe6AhBgHEw6eO3I3NW5r9v/26CqMPBDwmEundeq1iGyKfMloobIUMBAAE=',
  );
  assertEquals(
    isoBase64URL.fromBuffer(aaguid!, 'base64'),
    'yHzdl1bBSbieJMs2NlTzUA==',
  );
  assertEquals(
    counter,
    37,
  );
});

Deno.test('should parse extension data', () => {
  const parsed = parseAuthenticatorData(authDataWithED);

  const { extensionsData } = parsed;
  assertEquals(
    extensionsData,
    {
      'example.extension':
        'This is an example extension! If you read this message, you probably successfully passing conformance tests. Good job!',
    } as AuthenticationExtensionsAuthenticatorOutputs,
  );
});