Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add unlock page redirect test (#60)
Leendert de Borst9105215dc8c2
diff --git a/src/AliasVault.WebApp/Pages/Base/PageBase.cs b/src/AliasVault.WebApp/Pages/Base/PageBase.csindex 97397afd1..293dcc2ab 100644--- a/src/AliasVault.WebApp/Pages/Base/PageBase.cs+++ b/src/AliasVault.WebApp/Pages/Base/PageBase.cs@@ -83,14 +83,30 @@ public class PageBase : OwningComponentBase// Add base breadcrumbsBreadcrumbItems.Add(new BreadcrumbItem { DisplayName = "Home", Url = NavigationManager.BaseUri });- await RedirectIfNoEncryptionKey();+ bool willRedirect = await RedirectIfNoEncryptionKey();+ if (willRedirect)+ {+ // Keep the page from loading if a redirect is imminent.+ while (true)+ {+ await Task.Delay(200);+ }+ }}/// <inheritdoc />protected override async Task OnAfterRenderAsync(bool firstRender){await base.OnAfterRenderAsync(firstRender);- await RedirectIfNoEncryptionKey();+ bool willRedirect = await RedirectIfNoEncryptionKey();+ if (willRedirect)+ {+ // Keep the page from loading if a redirect is imminent.+ while (true)+ {+ await Task.Delay(200);+ }+ }}/// <summary>@@ -124,21 +140,33 @@ public class PageBase : OwningComponentBase////// This method should be called on every authenticated page load./// </summary>- private async Task RedirectIfNoEncryptionKey()+ private async Task<bool> RedirectIfNoEncryptionKey(){// If not logged in, let the normal login process handle it.var authState = await AuthStateProvider.GetAuthenticationStateAsync();if (!authState.User.Identity?.IsAuthenticated ?? true){- return;+ return true;}// Check that encryption key is set. If not, redirect to unlock screen.if (!AuthService.IsEncryptionKeySet()){- var currentUrl = NavigationManager.Uri;- await LocalStorage.SetItemAsync("returnUrl", currentUrl);+ // If returnUrl is not set and current URL is not unlock page, set it to the current URL.+ var localStorageReturnUrl = await LocalStorage.GetItemAsync<string>("returnUrl");+ if (string.IsNullOrEmpty(localStorageReturnUrl))+ {+ var currentUrl = NavigationManager.Uri;+ if (!currentUrl.Contains("unlock"))+ {+ await LocalStorage.SetItemAsync("returnUrl", currentUrl);+ }+ }+NavigationManager.NavigateTo("/unlock");+ return true;}++ return false;}}diff --git a/src/Tests/AliasVault.E2ETests/Tests/UnlockTests.cs b/src/Tests/AliasVault.E2ETests/Tests/UnlockTests.csindex 3536cdd3d..356608a14 100644--- a/src/Tests/AliasVault.E2ETests/Tests/UnlockTests.cs+++ b/src/Tests/AliasVault.E2ETests/Tests/UnlockTests.cs@@ -49,4 +49,43 @@ public class UnlockTests : PlaywrightTestvar pageContent = await Page.TextContentAsync("body");Assert.That(pageContent, Does.Contain("Find all of your aliases below"), "No index content after unlocking database.");}++ /// <summary>+ /// Test that hard navigating to the unlock page manually does not redirect to the unlock page on entering password.+ /// </summary>+ /// <returns>Async task.</returns>+ [Test]+ public async Task UnlockPageRedirect()+ {+ // Soft navigate to "aliases" page to test the unlock redirect.+ var startUrl = "aliases";+ await NavigateUsingBlazorRouter(startUrl);++ // Hard refresh the page.+ await Page.ReloadAsync();++ // Check if the unlock page is displayed.+ await WaitForURLAsync("**/unlock", "unlock");++ // Hard refresh the page again.+ 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();++ // Check if we get redirected back to the page we were trying to access.+ await WaitForURLAsync("**/" + startUrl, "AliasVault");++ var pageContent = await Page.TextContentAsync("body");+ Assert.That(pageContent, Does.Contain("Find all of your aliases below"), "No index content after unlocking database.");+ }}