[英]Spring Security login for 2FA - First check username and password, and then ask for 2FA code if required
[英]Integration Test WebAuthN as an 2FA option
我想將 WebAuthN 作為多因素身份驗證的選項添加到 Angular 和 Spring 應用程序。 我使用 Yubico 的 WebAuthN java-webauthn-server庫。
在沒有硬件客戶端的情況下,集成測試我的 WebAuthN 服務器的最佳方法是什么? 有沒有可以在自動化測試中處理密碼學的軟件? 我想在 CI/CD 管道 (GitLab) 中自動運行這些測試。
在最好的情況下,我希望能夠測試整個過程,創建憑據以及登錄。另一種情況可能是我在后端使用已知憑據並僅使用這些憑據登錄。
我的 API 是基於 REST/JSON 的,具有依賴方、用戶、挑戰、pubKey 等...
我的集成測試是基於 Java 的(spring boot starter test)
我主要對如何在沒有客戶端的情況下集成測試服務器感興趣。 是否有實用程序或庫可以處理身份驗證器並返回正確的數據/json 對象?
我已經通過 REST 工具查看了測試 WebAuthn ,但是,我對測試規范不感興趣,因為我使用的是庫,我只想確保我將庫正確應用於我的代碼。
如果您只對測試服務器端感興趣,您可以編寫一個帶有按鈕的簡單網頁,這些按鈕可以鍛煉您的端點並調用navigator.credentials.(create|get)
。 然后,您可以使用Selenium 4+ 檢測瀏覽器,設置Virtual Authenticators並針對該網頁運行測試。 以selenium 測試為例。 設置驗證器的代碼在 java 中如下所示:
VirtualAuthenticatorOptions options = new VirtualAuthenticatorOptions();
options.setTransport(Transport.INTERNAL)
.hasUserVerification(true)
.isUserVerified(true);
VirtualAuthenticator authenticator =
((HasVirtualAuthenticator) driver).addVirtualAuthenticator(options);
請注意使用正確的設置設置身份驗證器以匹配您的 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);
如果您還沒有將它用於集成測試,那么運行 selenium 測試可能需要一些工作。 然而,這個實現將非常接近現實。 從瀏覽器的角度來看,虛擬身份驗證器是真實的硬件。 來自身份驗證器的響應將由瀏覽器處理,就好像它是真實的一樣。
目前,只有基於 chromium 的瀏覽器支持虛擬身份驗證器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.