Skip to content

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

Add DbPersist E2E test (#81)

Leendert de Borstc22ba0c2cf7f
diff --git a/src/Tests/AliasVault.E2ETests/Common/PlaywrightTest.cs b/src/Tests/AliasVault.E2ETests/Common/PlaywrightTest.cs
index 9b2012fdd..813118d5d 100644
--- a/src/Tests/AliasVault.E2ETests/Common/PlaywrightTest.cs
+++ b/src/Tests/AliasVault.E2ETests/Common/PlaywrightTest.cs
@@ -196,6 +196,55 @@ public class PlaywrightTest
await Page.WaitForSelectorAsync("text=" + waitForText, new PageWaitForSelectorOptions() { Timeout = TestDefaults.DefaultTimeout });
}
+ /// <summary>
+ /// Refresh the page which will lock the vault, then enter password to unlock the vault again.
+ /// </summary>
+ /// <returns>Async task.</returns>
+ protected async Task RefreshPageAndUnlockVault()
+ {
+ // Hard refresh the page.
+ await Page.ReloadAsync();
+
+ // Check if the unlock page is displayed.
+ await WaitForURLAsync("**/unlock", "unlock");
+
+ // Check if by entering password the unlock page is replaced by the alias listing page.
+ await InputHelper.FillInputFields(new Dictionary<string, string>
+ {
+ { "password", TestUserPassword },
+ });
+
+ var submitButton = Page.GetByRole(AriaRole.Button, new() { Name = "Unlock" });
+ await submitButton.ClickAsync();
+ }
+
+ /// <summary>
+ /// Create new credential entry.
+ /// </summary>
+ /// <param name="formValues">Dictionary with html element ids and values to input as field value.</param>
+ /// <returns>Async task.</returns>
+ protected async Task CreateCredentialEntry(Dictionary<string, string>? formValues = null)
+ {
+ await NavigateUsingBlazorRouter("add-credentials");
+ await WaitForURLAsync("**/add-credentials", "Add credentials");
+
+ // Check if a button with text "Generate Random Identity" appears
+ var generateButton = Page.Locator("text=Generate Random Identity");
+ Assert.That(generateButton, Is.Not.Null, "Generate button not found.");
+
+ // Fill all input fields with specified values and remaining empty fields with random data.
+ await InputHelper.FillInputFields(formValues);
+ await InputHelper.FillEmptyInputFieldsWithRandom();
+
+ var submitButton = Page.Locator("text=Save Credentials").First;
+ await submitButton.ClickAsync();
+ await WaitForURLAsync("**/credentials/**", "Login credentials");
+
+ // Check if the credential was created
+ var pageContent = await Page.TextContentAsync("body");
+ Assert.That(pageContent, Does.Contain("Login credentials"), "Credential not created.");
+ }
+
/// <summary>
/// Register a new random account.
/// </summary>
diff --git a/src/Tests/AliasVault.E2ETests/Tests/CredentialTests.cs b/src/Tests/AliasVault.E2ETests/Tests/CredentialTests.cs
index 9dcb7b617..b1fb3e14c 100644
--- a/src/Tests/AliasVault.E2ETests/Tests/CredentialTests.cs
+++ b/src/Tests/AliasVault.E2ETests/Tests/CredentialTests.cs
@@ -10,7 +10,6 @@ namespace AliasVault.E2ETests.Tests;
/// <summary>
/// End-to-end tests for the credential management.
/// </summary>
-[Parallelizable(ParallelScope.Self)]
[TestFixture]
public class CredentialTests : PlaywrightTest
{
@@ -87,31 +86,4 @@ public class CredentialTests : PlaywrightTest
Assert.That(pageContent, Does.Contain("Credentials updated"), "Credential update confirmation message not shown.");
Assert.That(pageContent, Does.Contain(serviceNameAfter), "Credential not updated correctly.");
}
-
- /// <summary>
- /// Create new credential entry.
- /// </summary>
- /// <param name="formValues">Dictionary with html element ids and values to input as field value.</param>
- /// <returns>Async task.</returns>
- private async Task CreateCredentialEntry(Dictionary<string, string>? formValues = null)
- {
- await NavigateUsingBlazorRouter("add-credentials");
- await WaitForURLAsync("**/add-credentials", "Add credentials");
-
- // Check if a button with text "Generate Random Identity" appears
- var generateButton = Page.Locator("text=Generate Random Identity");
- Assert.That(generateButton, Is.Not.Null, "Generate button not found.");
-
- // Fill all input fields with specified values and remaining empty fields with random data.
- await InputHelper.FillInputFields(formValues);
- await InputHelper.FillEmptyInputFieldsWithRandom();
-
- var submitButton = Page.Locator("text=Save Credentials").First;
- await submitButton.ClickAsync();
- await WaitForURLAsync("**/credentials/**", "Login credentials");
-
- // Check if the credential was created
- var pageContent = await Page.TextContentAsync("body");
- Assert.That(pageContent, Does.Contain("Login credentials"), "Credential not created.");
- }
}
diff --git a/src/Tests/AliasVault.E2ETests/Tests/DbPersistTest.cs b/src/Tests/AliasVault.E2ETests/Tests/DbPersistTest.cs
new file mode 100644
index 000000000..3cb02c0a6
--- /dev/null
+++ b/src/Tests/AliasVault.E2ETests/Tests/DbPersistTest.cs
@@ -0,0 +1,46 @@
+//-----------------------------------------------------------------------
+// <copyright file="DbPersistTest.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;
+
+/// <summary>
+/// End-to-end tests for the credential management.
+/// </summary>
+[TestFixture]
+[NonParallelizable]
+public class DbPersistTest : PlaywrightTest
+{
+ /// <summary>
+ /// Test if a created credential is still present after a hard page refresh which causes
+ /// the database to be loaded fresh from the remote server. This is to ensure that the
+ /// database is correctly persisted and then loaded from the server.
+ /// </summary>
+ /// <returns>Async task.</returns>
+ [Test]
+ public async Task DbPersistCredentialTest()
+ {
+ var serviceNameBefore = "Credential service before";
+ await CreateCredentialEntry(new Dictionary<string, string>
+ {
+ { "service-name", serviceNameBefore },
+ });
+
+ // Check that the service name is present in the content.
+ var pageContent = await Page.TextContentAsync("body");
+ Assert.That(pageContent, Does.Contain(serviceNameBefore), "Created credential service name does not appear on login page.");
+
+ // Refresh page so the database gets dropped then unlock the vault again which will refetch the database from the server.
+ await RefreshPageAndUnlockVault();
+
+ // Wait for the credentials page to load again.
+ await WaitForURLAsync("**/credentials/**", "View credentials entry");
+
+ // Check if the service name is still present in the content.
+ pageContent = await Page.TextContentAsync("body");
+ Assert.That(pageContent, Does.Contain(serviceNameBefore), "Created credential service name does not appear on login page after hard page reload. Check if the database is correctly persisted and then loaded from the server.");
+ }
+}
diff --git a/src/Tests/AliasVault.E2ETests/Tests/UnlockTests.cs b/src/Tests/AliasVault.E2ETests/Tests/UnlockTests.cs
index c69870585..e897cbe26 100644
--- a/src/Tests/AliasVault.E2ETests/Tests/UnlockTests.cs
+++ b/src/Tests/AliasVault.E2ETests/Tests/UnlockTests.cs
@@ -26,20 +26,7 @@ public class UnlockTests : PlaywrightTest
var startUrl = "test/1";
await NavigateUsingBlazorRouter(startUrl);
- // Hard refresh the page.
- await Page.ReloadAsync();
-
- // Check if the unlock page is displayed.
- await WaitForURLAsync("**/unlock", "unlock");
-
- // Check if by entering password the unlock page is replaced by the alias listing page.
- await InputHelper.FillInputFields(new Dictionary<string, string>
- {
- { "password", TestUserPassword },
- });
-
- var submitButton = Page.GetByRole(AriaRole.Button, new() { Name = "Unlock" });
- await submitButton.ClickAsync();
+ await RefreshPageAndUnlockVault();
// Check if we get redirected back to the page we were trying to access.
await WaitForURLAsync("**/" + startUrl, "Test webapi call 1.");