fiv*_*ree 9 java integration-testing spring-boot webauthn multi-factor-authentication
我想将 WebAuthN 添加为 Angular & Spring 应用程序的多因素身份验证选项。我使用 Yubico 的 WebAuthN java-webauthn-server库。
在没有硬件客户端的情况下,集成测试我的 WebAuthN 服务器的最佳方法是什么?是否有任何软件可以在自动化测试中处理密码学?我想在 CI/CD 管道 (GitLab) 中自动运行这些测试。
在最好的情况下,我希望能够测试整个过程,创建凭据以及登录。另一种情况可能是我在后端使用已知凭据并仅使用这些凭据登录。
我的 API 是基于 REST/JSON 的,具有依赖方、用户、挑战、公钥等......
我的集成测试是基于 Java 的(spring boot starter test)
我主要对如何在没有客户端的情况下集成测试服务器感兴趣。是否有可以处理身份验证器并返回正确数据/json 对象的实用程序或库?
我已经查看了通过 REST 工具测试 WebAuthn,但是,我对测试规范不感兴趣,因为我使用的是库,我只想确保我将库正确应用于我的代码。
如果您只对测试服务器端感兴趣,您可以编写一个简单的网页,其中包含锻炼端点和调用的按钮navigator.credentials.(create|get)。然后,您可以使用Selenium 4+检测浏览器、设置Virtual Authenticators并针对该网页运行测试。以硒测试为例。设置验证器的代码在 java 中如下所示:
VirtualAuthenticatorOptions options = new VirtualAuthenticatorOptions();
options.setTransport(Transport.INTERNAL)
.setHasUserVerification(true)
.setIsUserVerified(true);
VirtualAuthenticator authenticator =
((HasVirtualAuthenticator) driver).addVirtualAuthenticator(options);
Run Code Online (Sandbox Code Playgroud)
请注意使用正确的设置来设置身份验证器以匹配您的 webauthn 调用。您应该选择正确的用户验证支持、驻留密钥支持以及内部(即平台)与 USB/nfc/ble(即跨平台)传输。
如果您使用旧版本的 selenium,则必须自己手动定义命令。代码应该看起来像
browser.driver.getExecutor().defineCommand(
"AddVirtualAuthenticator", "POST", "/session/:sessionId/webauthn/authenticator");
// ...
Command addVirtualAuthCommand = new Command("AddVirtualAuthenticator");
addVirtualAuthCommand.setParameter("protocol", "ctap2");
addVirtualAuthCommand.setParameter("transport", "usb");
browser.driver.getExecutor().execute(addVirtualAuthCommand);
Run Code Online (Sandbox Code Playgroud)
如果您尚未使用 Selenium 进行集成测试,则运行 Selenium 测试可能需要一些工作。然而,这种实现将非常接近现实。从浏览器的角度来看,虚拟验证器是真实的硬件。来自身份验证器的响应将由浏览器处理,就好像它是真实的一样。
目前,只有基于 chromium 的浏览器支持虚拟身份验证器。
| 归档时间: |
|
| 查看次数: |
400 次 |
| 最近记录: |