我正在尝试在 Cypress 测试中调用 Chrome DevTools 协议 WebAuthn.addCredential 方法。
credential = {
credentialId:"myid",
isResidentCredential: true,
rpId:"localhost",
userHandle: "bXl1c2VyaGFuZGxlDQo=",
privateKey: "my_private_key",
signCount: 0,
}
Cypress.automation('remote:debugger:protocol', {
command: 'WebAuthn.addCredential',
params: {
authenticatorId: authenticatorId,
credential,
},
})
但是,这会引发一个非常无用的错误:
Error: An error occurred trying to create the credential
at <embedded>:2262:577727
at _._handleMessage (<embedded>:2262:580030)
at A.<anonymous> (<embedded>:2262:579669)
at A.emit (node:events:514:28)
at f.U (<embedded>:2262:564853)
at f.emit (node:events:514:28)
at f.dataMessage (<embedded>:2262:545228)
at f.getData (<embedded>:2262:544410)
at f.startLoop (<embedded>:2262:541117)
at f._write (<embedded>:2262:540472)
at writeOrBuffer (node:internal/streams/writable:392:12)
at _write (node:internal/streams/writable:333:10)
at f.write (node:internal/streams/writable:337:10)
at Socket.W (<embedded>:2262:565539)
at Socket.emit (node:events:514:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Socket.push (node:internal/streams/readable:234:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
From previous event:
at Promise.longStackTracesCaptureStackTrace [as _captureStackTrace] (http://localhost:5172/__cypress/runner/cypress_runner.js:3486:19)
at Promise._then (http://localhost:5172/__cypress/runner/cypress_runner.js:1239:17)
at Promise.then (http://localhost:5172/__cypress/runner/cypress_runner.js:1132:17)
at next (http://localhost:5172/__cypress/runner/cypress_runner.js:144101:64)
at http://localhost:5172/__cypress/runner/cypress_runner.js:144122:16
at tryCatcher (http://localhost:5172/__cypress/runner/cypress_runner.js:1807:23)
at Promise._settlePromiseFromHandler (http://localhost:5172/__cypress/runner/cypress_runner.js:1519:31)
at Promise._settlePromise (http://localhost:5172/__cypress/runner/cypress_runner.js:1576:18)
at Promise._settlePromise0 (http://localhost:5172/__cypress/runner/cypress_runner.js:1621:10)
at Promise._settlePromises (http://localhost:5172/__cypress/runner/cypress_runner.js:1701:18)
at http://localhost:5172/__cypress/runner/cypress_runner.js:2392:25
有什么想法可能是错的吗?我按照here
给出的说明创建了私钥弄清楚出了什么问题,是私钥出了问题,尽管我不知道是什么。在尝试通过互联网创建一对可用的私钥-公钥并失败后,这就是我所做的:
使用我的 Cypress 测试进行 WebAuthn 注册(我已经完成并且正在工作),我使用
navigator.credentials.create()
创建了凭证。然后我添加了一个额外的测试步骤,使用 Chrome DevTools Protocol WebAuthn.getCredentials
命令获取虚拟 Web 身份验证器凭据,并打印结果。这给了我私钥。然后,完成测试后,我进入测试数据库并检查为注册测试的用户创建的 webauthn 记录。这给了我公钥。