Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add admin e2e tests for password and 2fa lockout (#80)
Leendert de Borst1564df342a18
diff --git a/src/AliasVault.Admin/Auth/Pages/Lockout.razor b/src/AliasVault.Admin/Auth/Pages/Lockout.razorindex bed1d0f8f..1794ba43f 100644--- a/src/AliasVault.Admin/Auth/Pages/Lockout.razor+++ b/src/AliasVault.Admin/Auth/Pages/Lockout.razor@@ -5,4 +5,4 @@<h2 class="text-2xl font-bold text-gray-900 dark:text-white mb-2">Locked out</h2>-<p>You have entered an incorrect password too many times and your account has now been locked out. Please try again in half an hour.</p>+<p>You have entered an incorrect password too many times and your account has now been locked out. You can try again in 30 minutes.</p>diff --git a/src/Tests/AliasVault.E2ETests/Tests/Admin/PasswordLockoutTests.cs b/src/Tests/AliasVault.E2ETests/Tests/Admin/PasswordLockoutTests.csnew file mode 100644index 000000000..fbaf38ec8--- /dev/null+++ b/src/Tests/AliasVault.E2ETests/Tests/Admin/PasswordLockoutTests.cs@@ -0,0 +1,56 @@+//-----------------------------------------------------------------------+// <copyright file="PasswordLockoutTests.cs" company="lanedirt">+// Copyright (c) lanedirt. All rights reserved.+// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.+// </copyright>+//-----------------------------------------------------------------------++namespace AliasVault.E2ETests.Tests.Admin;++/// <summary>+/// End-to-end tests for password lockout behavior.+/// </summary>+[Parallelizable(ParallelScope.Self)]+[Category("AdminTests")]+[TestFixture]+public class PasswordLockoutTests : AdminPlaywrightTest+{+ /// <summary>+ /// Test if entering a wrong password too many times locks the account.+ /// </summary>+ /// <returns>Async task.</returns>+ [Test]+ public async Task AccountLockoutTestPassword()+ {+ // Logout.+ await NavigateBrowser("user/logout");++ // Wait and check if we get redirected to /user/login.+ await WaitForUrlAsync("user/login**", "Sign in to");++ var pageContent = await Page.TextContentAsync("body");+ Assert.That(pageContent, Does.Contain("Login to your"), "No login page visible after logout.");++ // Try to login with wrong password 10 times. After 10 times, the account should be locked.+ for (var i = 0; i < 10; i++)+ {+ await Page.Locator("input[id='username']").FillAsync(TestUserUsername);+ await Page.Locator("input[id='password']").FillAsync("wrongpassword");+ var submitButton = Page.GetByRole(AriaRole.Button, new() { Name = "Login to your account" });+ await submitButton.ClickAsync();++ // Wait for the text "Error: Invalid login attempt." to appear if we expect not to be locked out yet..+ if (i == 9)+ {+ break;+ }++ await WaitForUrlAsync("user/login**", "Error: Invalid login attempt.");+ }++ // Wait for account lockout message.+ await WaitForUrlAsync("user/lockout**", "Locked out");+ pageContent = await Page.TextContentAsync("body");+ Assert.That(pageContent, Does.Contain("You have entered an incorrect password too many times"), "No account lockout message shown after 10 failed login attempts.");+ }+}diff --git a/src/Tests/AliasVault.E2ETests/Tests/Admin/TwoFactorLockoutTests.cs b/src/Tests/AliasVault.E2ETests/Tests/Admin/TwoFactorLockoutTests.csnew file mode 100644index 000000000..17f31833f--- /dev/null+++ b/src/Tests/AliasVault.E2ETests/Tests/Admin/TwoFactorLockoutTests.cs@@ -0,0 +1,88 @@+//-----------------------------------------------------------------------+// <copyright file="TwoFactorLockoutTests.cs" company="lanedirt">+// Copyright (c) lanedirt. All rights reserved.+// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.+// </copyright>+//-----------------------------------------------------------------------++namespace AliasVault.E2ETests.Tests.Admin;++/// <summary>+/// End-to-end tests for two-factor auth lockout behavior.+/// </summary>+[Parallelizable(ParallelScope.Self)]+[Category("AdminTests")]+[TestFixture]+public class TwoFactorLockoutTests : AdminPlaywrightTest+{+ /// <summary>+ /// Test if entering a wrong two-factor auth code too many times locks the account.+ /// </summary>+ /// <returns>Async task.</returns>+ [Test]+ public async Task AccountLockoutTest2Fa()+ {+ // Enable 2-factor authentication.+ await NavigateBrowser("account/manage/2fa");+ await WaitForUrlAsync("account/manage/2fa", "Authenticator app");++ var enable2FaButton = Page.GetByRole(AriaRole.Link, new() { Name = "Add authenticator app" });+ await enable2FaButton.ClickAsync();++ // Extract secret key from page.+ var secretKey = await Page.TextContentAsync("kbd");++ // Generate verification code with TotpHelper.+ var totp = TotpGenerator.TotpGenerator.GenerateTotpCode(secretKey!);++ // Fill in the form name="Input.Code".+ await Page.Locator("input[id='code']").FillAsync(totp);++ var submitButton = Page.GetByRole(AriaRole.Button, new() { Name = "Verify" });+ await submitButton.ClickAsync();++ // Wait for current page to refresh and confirm message shows.+ await WaitForUrlAsync("account/manage/enable-authenticator", "Put these codes in a safe place");++ // Logout.+ await NavigateBrowser("user/logout");++ // Wait and check if we get redirected to /user/login.+ await WaitForUrlAsync("user/login**", "Sign in to");++ // Try to login.+ var pageContent = await Page.TextContentAsync("body");+ Assert.That(pageContent, Does.Contain("Sign in to"), "No login page visible after logout.");++ // Login with username and password.+ await Page.Locator("input[id='username']").FillAsync(TestUserUsername);+ await Page.Locator("input[id='password']").FillAsync(TestUserPassword);++ submitButton = Page.GetByRole(AriaRole.Button, new() { Name = "Login to your account" });+ await submitButton.ClickAsync();++ // Wait for 2FA page.+ await WaitForUrlAsync("user/loginWith2fa**", "Authenticator code");++ // Try to login with wrong 2FA code 10 times. After 10 times, the account should be locked.+ for (var i = 0; i < 10; i++)+ {+ await Page.Locator("input[id='two-factor-code']").FillAsync("000000");+ submitButton = Page.GetByRole(AriaRole.Button, new() { Name = "Log in" });+ await submitButton.ClickAsync();++ // Wait for the text "Error: Invalid login attempt." to appear if we expect not to be locked out yet..+ if (i == 9)+ {+ break;+ }++ await WaitForUrlAsync("user/loginWith2fa**", "Error: Invalid authenticator code.");+ }++ // Wait for account lockout message.+ await WaitForUrlAsync("user/lockout**", "Locked out");+ pageContent = await Page.TextContentAsync("body");+ Assert.That(pageContent, Does.Contain("You have entered an incorrect password too many times"), "No account lockout message shown after 10 failed login attempts.");+ }+}