Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add browser extension password settings test (#167)

Leendert de Borst79cd265c3e36
diff --git a/src/AliasVault.Client/Main/Components/Layout/ModalWrapper.razor b/src/AliasVault.Client/Main/Components/Layout/ModalWrapper.razor
index 97b5145dc..d59660805 100644
--- a/src/AliasVault.Client/Main/Components/Layout/ModalWrapper.razor
+++ b/src/AliasVault.Client/Main/Components/Layout/ModalWrapper.razor
@@ -22,7 +22,7 @@
/// CSS class string to apply to the wrapper div.
/// </summary>
[Parameter]
- public string CssClass { get; set; } = "fixed inset-0 z-50 overflow-auto bg-gray-500 bg-opacity-75 flex items-center justify-center";
+ public string CssClass { get; set; } = "modal-dialog fixed inset-0 z-50 overflow-auto bg-gray-500 bg-opacity-75 flex items-center justify-center";
/// <summary>
/// Determines if the default behavior should be prevented for keyboard events.
@@ -48,4 +48,4 @@
{
return ValueTask.CompletedTask;
}
-}
+}
diff --git a/src/AliasVault.Client/Main/Components/Settings/DefaultPasswordSettings.razor b/src/AliasVault.Client/Main/Components/Settings/DefaultPasswordSettings.razor
index b7f9e380e..658e13d2d 100644
--- a/src/AliasVault.Client/Main/Components/Settings/DefaultPasswordSettings.razor
+++ b/src/AliasVault.Client/Main/Components/Settings/DefaultPasswordSettings.razor
@@ -1,8 +1,8 @@
@inject DbService DbService
<div class="mb-4">
- <label for="defaultEmailDomain" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Default password generator settings</label>
- <button type="button" class="px-4 py-2 bg-primary-600 text-white rounded-md hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 dark:bg-primary-700 dark:hover:bg-primary-600" @onclick="OpenSettings">
+ <label for="password-generator-settings-modal" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Default password generator settings</label>
+ <button type="button" id="password-generator-settings-modal" class="px-4 py-2 bg-primary-600 text-white rounded-md hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 dark:bg-primary-700 dark:hover:bg-primary-600" @onclick="OpenSettings">
Configure
</button>
<span class="block text-sm font-normal text-gray-500 truncate dark:text-gray-400 mt-2">
diff --git a/src/AliasVault.Client/Main/Components/Settings/PasswordSettingsPopup.razor b/src/AliasVault.Client/Main/Components/Settings/PasswordSettingsPopup.razor
index 8b6556c57..82fd3054d 100644
--- a/src/AliasVault.Client/Main/Components/Settings/PasswordSettingsPopup.razor
+++ b/src/AliasVault.Client/Main/Components/Settings/PasswordSettingsPopup.razor
@@ -68,7 +68,7 @@
Use Just Once
</button>
}
- <button type="button" class="px-4 py-2 bg-primary-600 text-white rounded-md hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 dark:bg-primary-700 dark:hover:bg-primary-600" @onclick="OnSaveGlobal">
+ <button type="button" id="save-button" class="px-4 py-2 bg-primary-600 text-white rounded-md hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 dark:bg-primary-700 dark:hover:bg-primary-600" @onclick="OnSaveGlobal">
Save Globally
</button>
</div>
diff --git a/src/Tests/AliasVault.E2ETests/Tests/Extensions/ChromeExtensionTests.cs b/src/Tests/AliasVault.E2ETests/Tests/Extensions/ChromeExtensionTests.cs
index 344a54913..c36af68bc 100644
--- a/src/Tests/AliasVault.E2ETests/Tests/Extensions/ChromeExtensionTests.cs
+++ b/src/Tests/AliasVault.E2ETests/Tests/Extensions/ChromeExtensionTests.cs
@@ -136,4 +136,111 @@ public class ChromeExtensionTests : BrowserExtensionPlaywrightTest
// Clean up the temporary file after the test
File.Delete(tempHtmlPath);
}
+
+ /// <summary>
+ /// Tests if the extension applies custom password settings configured in the client app.
+ /// </summary>
+ /// <returns>Async task.</returns>
+ [Order(3)]
+ [Test]
+ public async Task ExtensionAppliesCustomPasswordSettings()
+ {
+ // First configure password settings in the client app
+ await Page.BringToFrontAsync();
+
+ // Navigate to settings/general
+ await NavigateUsingBlazorRouter("settings/general");
+ await WaitForUrlAsync("settings/general", "General Settings");
+
+ // Click the "Password Generator Settings" button to open the settings popup
+ await Page.ClickAsync("button[id='password-generator-settings-modal']");
+
+ // Wait for the password settings modal to appear
+ await Page.WaitForSelectorAsync("div.modal-dialog");
+
+ // Uncheck all checkboxes except lowercase
+ await Page.UncheckAsync("#use-uppercase");
+ await Page.UncheckAsync("#use-numbers");
+ await Page.UncheckAsync("#use-special-chars");
+ await Page.CheckAsync("#use-lowercase");
+
+ // Set password length to 10
+ await Page.FillAsync("input#password-length", "10");
+
+ // Save the settings
+ await Page.ClickAsync("button[id='save-button']");
+
+ // Wait for settings to be saved (modal to disappear)
+ await Page.WaitForSelectorAsync("div.modal-dialog", new() { State = WaitForSelectorState.Hidden });
+
+ // Login to the extension
+ var extensionPopup = await LoginToExtension();
+
+ // Create a temporary HTML file with the test form
+ var tempHtmlPath = Path.Combine(Path.GetTempPath(), "test-form-password-settings.html");
+ var testFormHtml = @"
+ <html>
+ <head>
+ <title>Password Settings Test</title>
+ </head>
+ <body>
+ <h1>AliasVault browser extension password settings test</h1>
+ <form>
+ <input type='text' id='username' placeholder='Username'>
+ <input type='password' id='password' placeholder='Password'>
+ <button type='submit'>Login</button>
+ </form>
+ </body>
+ </html>
+ ";
+
+ await File.WriteAllTextAsync(tempHtmlPath, testFormHtml);
+
+ // Navigate to the file using the file:// protocol
+ await extensionPopup.GotoAsync($"file://{tempHtmlPath}");
+
+ // Focus the username field which should trigger the AliasVault popup
+ await extensionPopup.FocusAsync("input#username");
+
+ // Wait for the AliasVault popup to appear
+ await extensionPopup.WaitForSelectorAsync("#aliasvault-credential-popup");
+
+ // Click the "New" button in the popup
+ await extensionPopup.ClickAsync("button:has-text('New')");
+
+ // Set the service name for the new credential
+ var serviceName = "Password Settings Test";
+ await extensionPopup.FillAsync("input[id='service-name-input']", serviceName);
+
+ // Click the "Create" button
+ await extensionPopup.ClickAsync("button[id='save-btn']");
+
+ // Wait for the "aliasvault-create-popup" to disappear
+ await extensionPopup.WaitForSelectorAsync("#aliasvault-create-popup", new() { State = WaitForSelectorState.Hidden });
+
+ // Wait for 0.5 second because the password is being typed in char by char
+ await Task.Delay(500);
+
+ // Wait for the credential to be created and the form fields to be filled with values
+ await extensionPopup.WaitForFunctionAsync(
+ @"() => {
+ const username = document.querySelector('input#username');
+ const password = document.querySelector('input#password');
+ return username?.value && password?.value;
+ }",
+ null,
+ new() { Timeout = 10000 });
+
+ // Get the generated password
+ var password = await extensionPopup.InputValueAsync("input#password");
+
+ // Verify the password is 10 characters long
+ Assert.That(password.Length, Is.EqualTo(10), "Password length does not match the configured length of 10");
+
+ // Verify the password only contains lowercase letters (a-z)
+ Assert.That(password, Does.Match("^[a-z]+$"), "Password contains characters other than lowercase letters");
+
+ // Clean up the temporary file after the test
+ File.Delete(tempHtmlPath);
+ }
}