Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add browser extension vault outdate check, fix db create wait flow (#643)
Leendert de Borst9e478c94f9f2
diff --git a/src/AliasVault.Api/Controllers/VaultController.cs b/src/AliasVault.Api/Controllers/VaultController.csindex c000eeb6b..4296621d5 100644--- a/src/AliasVault.Api/Controllers/VaultController.cs+++ b/src/AliasVault.Api/Controllers/VaultController.cs@@ -76,6 +76,7 @@ public class VaultController(ILogger<VaultController> logger, IAliasServerDbCont}// Logic to retrieve vault for the user.+ var vaults = await context.Vaults.ToListAsync();var vault = await context.Vaults.Where(x => x.UserId == user.Id).OrderByDescending(x => x.RevisionNumber)diff --git a/src/AliasVault.Client/Main/Pages/Sync/StatusMessages/Creating.razor b/src/AliasVault.Client/Main/Pages/Sync/StatusMessages/Creating.razorindex 5c7dd8667..99dbc95ee 100644--- a/src/AliasVault.Client/Main/Pages/Sync/StatusMessages/Creating.razor+++ b/src/AliasVault.Client/Main/Pages/Sync/StatusMessages/Creating.razor@@ -53,7 +53,12 @@if (await DbService.MigrateDatabaseAsync()){// Save the database to the server.- if (!await DbService.SaveDatabaseAsync())+ if (await DbService.SaveDatabaseAsync())+ {+ // Migration successful, update state which will trigger the status message UI to refresh and redirect user.+ DbService.GetState().UpdateState(DbServiceState.DatabaseStatus.Ready);+ }+ else{// Migration failedErrorMessage = "Vault creation successful but failed to save to server. Please refresh the page and try again or contact support.";diff --git a/src/AliasVault.Client/Main/Pages/Sync/StatusMessages/PendingMigrations.razor b/src/AliasVault.Client/Main/Pages/Sync/StatusMessages/PendingMigrations.razorindex bdddc30f3..8f15e0210 100644--- a/src/AliasVault.Client/Main/Pages/Sync/StatusMessages/PendingMigrations.razor+++ b/src/AliasVault.Client/Main/Pages/Sync/StatusMessages/PendingMigrations.razor@@ -76,7 +76,8 @@// Save the database to the server.if (await DbService.SaveDatabaseAsync()){- // Migration successful.+ // Migration successful, update state which will trigger the status message UI to refresh and redirect user.+ DbService.GetState().UpdateState(DbServiceState.DatabaseStatus.Ready);GlobalNotificationService.AddSuccessMessage("Vault upgrade successful.", true);}elsediff --git a/src/AliasVault.Client/Services/Database/DbService.cs b/src/AliasVault.Client/Services/Database/DbService.csindex bdcf0710f..cc76a2d83 100644--- a/src/AliasVault.Client/Services/Database/DbService.cs+++ b/src/AliasVault.Client/Services/Database/DbService.cs@@ -251,8 +251,11 @@ public sealed class DbService : IDisposable/// <returns>Bool which indicates if saving database to server was successful.</returns>public async Task<bool> SaveDatabaseAsync(){- // Set the initial state of the database service.- _state.UpdateState(DbServiceState.DatabaseStatus.SavingToServer);+ if (_state.CurrentState.Status != DbServiceState.DatabaseStatus.Creating)+ {+ // If database is not in the process of being created, update status to saving which is reflected in the UI.+ _state.UpdateState(DbServiceState.DatabaseStatus.SavingToServer);+ }// Make sure a public/private RSA encryption key exists before saving the database.await GetOrCreateEncryptionKeyAsync();@@ -264,7 +267,11 @@ public sealed class DbService : IDisposableif (success){_logger.LogInformation("Database successfully saved to server.");- _state.UpdateState(DbServiceState.DatabaseStatus.Ready);+ if (_state.CurrentState.Status != DbServiceState.DatabaseStatus.Creating)+ {+ // If database is not in the process of being created, update status to ready which is reflected in the UI.+ _state.UpdateState(DbServiceState.DatabaseStatus.Ready);+ }}return success;@@ -306,7 +313,6 @@ public sealed class DbService : IDisposableawait _dbContext.Database.MigrateAsync();_isSuccessfullyInitialized = true;await _settingsService.InitializeAsync(this);- _state.UpdateState(DbServiceState.DatabaseStatus.Ready);}catch (Exception ex){diff --git a/src/Tests/AliasVault.E2ETests/Tests/Extensions/VaultOutdatedTests.cs b/src/Tests/AliasVault.E2ETests/Tests/Extensions/VaultOutdatedTests.csnew file mode 100644index 000000000..2d7f67aa0--- /dev/null+++ b/src/Tests/AliasVault.E2ETests/Tests/Extensions/VaultOutdatedTests.cs@@ -0,0 +1,48 @@+//-----------------------------------------------------------------------+// <copyright file="VaultOutdatedTests.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.Extensions;++using Microsoft.EntityFrameworkCore;++/// <summary>+/// End-to-end tests for the Chrome extension involving simulating an outdated vault+/// to check for expected error messages.+/// </summary>+[Parallelizable(ParallelScope.Self)]+[Category("ExtensionTests")]+[TestFixture]+public class VaultOutdatedTests : BrowserExtensionPlaywrightTest+{+ /// <summary>+ /// Tests if the extension correctly handles an outdated vault version by showing appropriate error message.+ /// </summary>+ /// <returns>Async task.</returns>+ [Order(1)]+ [Test]+ public async Task ExtensionOutdatedVaultTest()+ {+ // Clear any tracked entities from previous operations.+ ApiDbContext.ChangeTracker.Clear();++ // Get the latest vault and modify its version to an outdated one.+ var latestVault = await ApiDbContext.Vaults+ .OrderByDescending(x => x.RevisionNumber)+ .FirstAsync();++ latestVault.Version = "1.0.0";+ await ApiDbContext.SaveChangesAsync();++ // Login to the extension.+ var extensionPopup = await LoginToExtension(waitForLogin: false);++ // Verify that the expected error message is shown.+ await extensionPopup.WaitForSelectorAsync("text=Your vault is outdated");+ var pageContent = await extensionPopup.TextContentAsync("body");+ Assert.That(pageContent, Does.Contain("Your vault is outdated. Please login via the web client to update your vault."));+ }+}