forked from ChromeDevTools/chrome-devtools-mcp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebauthn.test.ts
More file actions
86 lines (75 loc) · 2.46 KB
/
webauthn.test.ts
File metadata and controls
86 lines (75 loc) · 2.46 KB
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
/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import assert from 'node:assert';
import {describe, it} from 'node:test';
import sinon from 'sinon';
import {configureWebauthn} from '../../src/tools/webauthn.js';
import {withMcpContext} from '../utils.js';
describe('webauthn', () => {
it('reports status', async () => {
await withMcpContext(async (response, context) => {
const selectedPage = context.getSelectedPptrPage();
const send = sinon.stub().resolves({credentials: []});
sinon
.stub(selectedPage as unknown as Record<string, unknown>, '_client')
.returns({send} as never);
await configureWebauthn.handler(
{
params: {action: 'status'},
page: context.getSelectedMcpPage(),
},
response,
context,
);
assert.ok(response.responseLines.join('\n').includes('WebAuthn status:'));
sinon.assert.calledWith(send, 'WebAuthn.getCredentials', {});
});
});
it('enables WebAuthn and includes action result', async () => {
await withMcpContext(async (response, context) => {
const selectedPage = context.getSelectedPptrPage();
const send = sinon
.stub()
.onFirstCall()
.resolves(undefined)
.onSecondCall()
.resolves({credentials: []});
sinon
.stub(selectedPage as unknown as Record<string, unknown>, '_client')
.returns({send} as never);
await configureWebauthn.handler(
{
params: {action: 'enable'},
page: context.getSelectedMcpPage(),
},
response,
context,
);
sinon.assert.calledWith(send.firstCall, 'WebAuthn.enable');
assert.ok(response.responseLines.join('\n').includes('"result":"enabled"'));
});
});
it('throws if removeAuthenticator is missing authenticatorId', async () => {
await withMcpContext(async (response, context) => {
const selectedPage = context.getSelectedPptrPage();
const send = sinon.stub().resolves({credentials: []});
sinon
.stub(selectedPage as unknown as Record<string, unknown>, '_client')
.returns({send} as never);
await assert.rejects(
configureWebauthn.handler(
{
params: {action: 'removeAuthenticator'},
page: context.getSelectedMcpPage(),
},
response,
context,
),
/authenticatorId is required/,
);
});
});
});