Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add reset vault E2E test, fix delete all scope (#1007)
Leendert de Borst5204726beccd
diff --git a/apps/server/AliasVault.Client/Services/CredentialService.cs b/apps/server/AliasVault.Client/Services/CredentialService.csindex ee058f5a7..0d3424db1 100644--- a/apps/server/AliasVault.Client/Services/CredentialService.cs+++ b/apps/server/AliasVault.Client/Services/CredentialService.cs@@ -373,16 +373,15 @@ public sealed class CredentialService(HttpClient httpClient, DbService dbServicepublic async Task<bool> HardDeleteAllCredentialsAsync(){var context = await dbService.GetDbContextAsync();- var allCredentials = await context.Credentials.ToListAsync();- if (allCredentials.Any())- {- // Hard delete all credentials (cascade will handle related records)- context.Credentials.RemoveRange(allCredentials);+ // Hard delete all attachments, aliases, services and credentials.+ context.Attachments.RemoveRange(context.Attachments);+ context.Aliases.RemoveRange(context.Aliases);+ context.Services.RemoveRange(context.Services);+ context.Credentials.RemoveRange(context.Credentials);- // Save changes locally- await context.SaveChangesAsync();- }+ // Save changes locally+ await context.SaveChangesAsync();// Save the database to serverreturn await dbService.SaveDatabaseAsync();diff --git a/apps/server/Tests/AliasVault.E2ETests/Common/ClientPlaywrightTest.cs b/apps/server/Tests/AliasVault.E2ETests/Common/ClientPlaywrightTest.csindex 50cdb6721..f8c2659ae 100644--- a/apps/server/Tests/AliasVault.E2ETests/Common/ClientPlaywrightTest.cs+++ b/apps/server/Tests/AliasVault.E2ETests/Common/ClientPlaywrightTest.cs@@ -405,4 +405,36 @@ public class ClientPlaywrightTest : PlaywrightTestawait WaitForUrlAsync("welcome**", WelcomeMessage);}}++ /// <summary>+ /// Complete the tutorial shown after registration. This is required for certain tests that rely on the tutorial being completed+ /// so it shows the empty credential list instead of redirecting to the tutorial welcome page.+ /// </summary>+ /// <returns>Async task.</returns>+ protected async Task CompleteTutorial()+ {+ // Wait for "Welcome to AliasVault" message to appear.+ await WaitForUrlAsync("welcome**", WelcomeMessage);++ // Click the "Continue" button.+ var continueButton = Page.Locator("text=Continue");+ await continueButton.ClickAsync();++ // Wait for "How AliasVault works" message to appear.+ await WaitForUrlAsync("welcome**", "How AliasVault works");++ // Click the "Continue" button.+ var continueButton2 = Page.Locator("text=Continue");+ await continueButton2.ClickAsync();++ // Wait for "Tips" message to appear.+ await WaitForUrlAsync("welcome**", "Tips");++ // Click the "Get Started" button.+ var getStartedButton = Page.Locator("text=Get Started");+ await getStartedButton.ClickAsync();++ // Wait for "Find all of your credentials below" message to appear.+ await WaitForUrlAsync("welcome**", "Find all of your credentials below");+ }}diff --git a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard5/ResetVaultTests.cs b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard5/ResetVaultTests.csnew file mode 100644index 000000000..edc4a8830--- /dev/null+++ b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard5/ResetVaultTests.cs@@ -0,0 +1,93 @@+//-----------------------------------------------------------------------+// <copyright file="ResetVaultTests.cs" company="lanedirt">+// Copyright (c) lanedirt. All rights reserved.+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.+// </copyright>+//-----------------------------------------------------------------------++namespace AliasVault.E2ETests.Tests.Client.Shard5;++using Microsoft.EntityFrameworkCore;++/// <summary>+/// End-to-end tests for authentication.+/// </summary>+[Parallelizable(ParallelScope.Self)]+[Category("ClientTests")]++[TestFixture]+public class ResetVaultTests : ClientPlaywrightTest+{+ /// <summary>+ /// Test if changing password works correctly.+ /// </summary>+ /// <returns>Async task.</returns>+ [Test]+ [Order(1)]+ public async Task ResetVaultTest()+ {+ await CompleteTutorial();++ // Create three random credential entries.+ for (var i = 0; i < 3; i++)+ {+ // Advance time by 1 second manually to ensure the new vault is created in the future.+ ApiTimeProvider.AdvanceBy(TimeSpan.FromSeconds(1));++ var randomServiceName = $"Credential service {i}";+ await CreateCredentialEntry(new Dictionary<string, string>+ {+ { "service-name", randomServiceName },+ });++ // Check that the service names are present in the content.+ var pageContent = await Page.TextContentAsync("body");+ Assert.That(pageContent, Does.Contain(randomServiceName), "Created credential service name does not appear after creation.");+ }++ // Attempt to reset vault.+ ApiTimeProvider.AdvanceBy(TimeSpan.FromSeconds(1));++ // Attempt to change password.+ await NavigateUsingBlazorRouter("settings/import-export/reset-vault");+ await WaitForUrlAsync("settings/import-export/reset-vault", "Reset Vault");++ // Fill in the username field.+ var usernameField = await WaitForAndGetElement("input[id='username']");+ await usernameField.FillAsync(TestUserUsername);++ // Press continue button input+ var continueButton = Page.Locator("button[type='submit']");+ await continueButton.ClickAsync();++ // Fill in the password field.+ var passwordField = await WaitForAndGetElement("input[id='password']");+ await passwordField.FillAsync(TestUserPassword);++ // Press reset vault button input+ var resetVaultButton = Page.Locator("button[type='submit']");+ await resetVaultButton.ClickAsync();++ // Wait for success message.+ await WaitForUrlAsync("credentials", "successfully reset");++ // Check API that the latest vault has no credentials.+ var latestVault = await ApiDbContext.Vaults.Where(x => x.User.UserName == TestUserUsername).OrderByDescending(x => x.CreatedAt).FirstAsync();+ Assert.That(latestVault.CredentialsCount, Is.EqualTo(0), "Latest vault should have no credentials after reset.");++ // Create a new credential entry.+ var serviceName = "Credential service after reset";+ await CreateCredentialEntry(new Dictionary<string, string>+ {+ { "service-name", serviceName },+ });++ // Check that the now latest vault has one credential, and only one active claimed alias.+ latestVault = await ApiDbContext.Vaults.Where(x => x.User.UserName == TestUserUsername).OrderByDescending(x => x.CreatedAt).FirstAsync();+ Assert.Multiple(() =>+ {+ Assert.That(latestVault.CredentialsCount, Is.EqualTo(1), "Latest vault should have one credential after reset.");+ Assert.That(latestVault.EmailClaimsCount, Is.EqualTo(1), "Latest vault should have (only) one active claimed alias after reset.");+ });+ }+}