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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
import { assertEquals, assertRejects } from 'https://deno.land/std@0.198.0/assert/mod.ts';
import { afterEach, beforeEach, describe, it } from 'https://deno.land/std@0.198.0/testing/bdd.ts';
import {
assertSpyCallArg,
assertSpyCalls,
Stub,
stub,
} from 'https://deno.land/std@0.198.0/testing/mock.ts';
import { _fetchInternals } from '../helpers/fetch.ts';
import { BaseMetadataService, MetadataService } from './metadataService.ts';
import type { MetadataStatement } from '../metadata/mdsTypes.ts';
// const _fetch = fetch as unknown as jest.Mock;
let mockFetch: Stub;
describe('Method: initialize()', () => {
beforeEach(() => {
mockFetch = stub(_fetchInternals, 'stubThis');
});
afterEach(() => {
mockFetch.restore();
});
it('should default to querying MDS v3', async () => {
await MetadataService.initialize();
assertSpyCalls(mockFetch, 1);
assertSpyCallArg(mockFetch, 0, 0, 'https://mds.fidoalliance.org/');
});
it('should query provided MDS server URLs', async () => {
const mdsServers = ['https://custom-mds1.com', 'https://custom-mds2.com'];
await MetadataService.initialize({
mdsServers,
});
assertSpyCalls(mockFetch, mdsServers.length);
assertSpyCallArg(mockFetch, 0, 0, mdsServers[0]);
assertSpyCallArg(mockFetch, 1, 0, mdsServers[1]);
});
it('should not query any servers on empty list of URLs', async () => {
await MetadataService.initialize({ mdsServers: [] });
assertSpyCalls(mockFetch, 0);
});
it('should load local statements', async () => {
await MetadataService.initialize({
statements: [localStatement],
});
const statement = await MetadataService.getStatement(localStatementAAGUID);
assertEquals(statement, localStatement);
});
});
describe('Method: getStatement()', () => {
it('should return undefined if service not initialized', async () => {
// For lack of a way to "uninitialize" the singleton, create a new instance
const service = new BaseMetadataService();
const statement = await service.getStatement('not-a-real-aaguid');
assertEquals(statement, undefined);
});
it('should return undefined if aaguid is undefined', async () => {
// TypeScript will prevent you from passing `undefined`, but JS won't so test it
// @ts-ignore 2345
const statement = await MetadataService.getStatement(undefined);
assertEquals(statement, undefined);
});
it('should throw after initialization on AAGUID with no statement', async () => {
await MetadataService.initialize({
mdsServers: [],
statements: [],
});
assertRejects(
() => MetadataService.getStatement('not-a-real-aaguid'),
);
});
it('should return undefined after initialization on AAGUID with no statement and verificationMode is "permissive"', async () => {
await MetadataService.initialize({
mdsServers: [],
statements: [],
verificationMode: 'permissive',
});
const statement = await MetadataService.getStatement('not-a-real-aaguid');
assertEquals(statement, undefined);
});
});
const localStatementAAGUID = '91dfead7-959e-4475-ad26-9b0d482be089';
const localStatement: MetadataStatement = {
legalHeader: 'https://fidoalliance.org/metadata/metadata-statement-legal-header/',
description: 'Virtual FIDO2 EdDSA25519 SHA512 Conformance Testing CTAP2 Authenticator',
aaguid: localStatementAAGUID,
protocolFamily: 'fido2',
authenticatorVersion: 2,
upv: [
{
major: 1,
minor: 0,
},
],
authenticationAlgorithms: ['ed25519_eddsa_sha512_raw'],
publicKeyAlgAndEncodings: ['cose'],
attestationTypes: ['basic_full', 'basic_surrogate'],
schema: 3,
userVerificationDetails: [
[
{
userVerificationMethod: 'none',
},
],
],
keyProtection: ['hardware', 'secure_element'],
matcherProtection: ['on_chip'],
cryptoStrength: 128,
attachmentHint: ['external', 'wired', 'wireless', 'nfc'],
tcDisplay: [],
attestationRootCertificates: [],
supportedExtensions: [
{
id: 'hmac-secret',
fail_if_unknown: false,
},
],
authenticatorGetInfo: {
versions: ['U2F_V2', 'FIDO_2_0'],
extensions: ['credProtect', 'hmac-secret'],
aaguid: '91dfead7959e4475ad269b0d482be089',
options: {
plat: false,
rk: true,
clientPin: true,
up: true,
uv: true,
},
maxMsgSize: 1200,
},
};
|