Skip to content

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

Add dedicated test pages to webapi and wasm for E2E tests (#63)

Leendert de Borstc5fc5c0e81f9
diff --git a/src/AliasVault.Api/Controllers/TestController.cs b/src/AliasVault.Api/Controllers/TestController.cs
new file mode 100644
index 000000000..a4535b7d5
--- /dev/null
+++ b/src/AliasVault.Api/Controllers/TestController.cs
@@ -0,0 +1,31 @@
+//-----------------------------------------------------------------------
+// <copyright file="TestController.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.Api.Controllers;
+
+using AliasServerDb;
+using Asp.Versioning;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Mvc;
+
+/// <summary>
+/// Test controller that contains test endpoints called by pages on the client for E2E testing purposes.
+/// </summary>
+/// <param name="userManager">UserManager instance.</param>
+[ApiVersion("1")]
+public class TestController(UserManager<AliasVaultUser> userManager) : AuthenticatedRequestController(userManager)
+{
+ /// <summary>
+ /// Authenticated test request.
+ /// </summary>
+ /// <returns>List of aliases in JSON format.</returns>
+ [HttpGet("")]
+ public IActionResult TestCall()
+ {
+ return Ok();
+ }
+}
diff --git a/src/AliasVault.Api/Controllers/VaultController.cs b/src/AliasVault.Api/Controllers/VaultController.cs
index ef763515e..1f43127d2 100644
--- a/src/AliasVault.Api/Controllers/VaultController.cs
+++ b/src/AliasVault.Api/Controllers/VaultController.cs
@@ -8,8 +8,8 @@
namespace AliasVault.Api.Controllers;
using AliasServerDb;
-using AliasVault.Api.Controllers.Vault;
-using AliasVault.Api.Controllers.Vault.RetentionRules;
+using AliasVault.Api.Vault;
+using AliasVault.Api.Vault.RetentionRules;
using AliasVault.Shared.Providers;
using Asp.Versioning;
using Microsoft.AspNetCore.Identity;
diff --git a/src/AliasVault.Api/Controllers/Vault/RetentionPolicy.cs b/src/AliasVault.Api/Vault/RetentionPolicy.cs
similarity index 87%
rename from src/AliasVault.Api/Controllers/Vault/RetentionPolicy.cs
rename to src/AliasVault.Api/Vault/RetentionPolicy.cs
index 1091f212d..4799fcd67 100644
--- a/src/AliasVault.Api/Controllers/Vault/RetentionPolicy.cs
+++ b/src/AliasVault.Api/Vault/RetentionPolicy.cs
@@ -5,9 +5,9 @@
// </copyright>
//-----------------------------------------------------------------------
-namespace AliasVault.Api.Controllers.Vault;
+namespace AliasVault.Api.Vault;
-using AliasVault.Api.Controllers.Vault.RetentionRules;
+using AliasVault.Api.Vault.RetentionRules;
/// <summary>
/// The retention policy that contains one or more retention rules.
diff --git a/src/AliasVault.Api/Controllers/Vault/RetentionRules/DailyRetentionRule.cs b/src/AliasVault.Api/Vault/RetentionRules/DailyRetentionRule.cs
similarity index 94%
rename from src/AliasVault.Api/Controllers/Vault/RetentionRules/DailyRetentionRule.cs
rename to src/AliasVault.Api/Vault/RetentionRules/DailyRetentionRule.cs
index 886584ac0..f0364ef2d 100644
--- a/src/AliasVault.Api/Controllers/Vault/RetentionRules/DailyRetentionRule.cs
+++ b/src/AliasVault.Api/Vault/RetentionRules/DailyRetentionRule.cs
@@ -5,7 +5,7 @@
// </copyright>
//-----------------------------------------------------------------------
-namespace AliasVault.Api.Controllers.Vault.RetentionRules;
+namespace AliasVault.Api.Vault.RetentionRules;
using AliasServerDb;
diff --git a/src/AliasVault.Api/Controllers/Vault/RetentionRules/IRetentionRule.cs b/src/AliasVault.Api/Vault/RetentionRules/IRetentionRule.cs
similarity index 93%
rename from src/AliasVault.Api/Controllers/Vault/RetentionRules/IRetentionRule.cs
rename to src/AliasVault.Api/Vault/RetentionRules/IRetentionRule.cs
index f47679c48..24ab14513 100644
--- a/src/AliasVault.Api/Controllers/Vault/RetentionRules/IRetentionRule.cs
+++ b/src/AliasVault.Api/Vault/RetentionRules/IRetentionRule.cs
@@ -5,7 +5,7 @@
// </copyright>
//-----------------------------------------------------------------------
-namespace AliasVault.Api.Controllers.Vault.RetentionRules;
+namespace AliasVault.Api.Vault.RetentionRules;
using AliasServerDb;
diff --git a/src/AliasVault.Api/Controllers/Vault/RetentionRules/MonthlyRetentionRule.cs b/src/AliasVault.Api/Vault/RetentionRules/MonthlyRetentionRule.cs
similarity index 94%
rename from src/AliasVault.Api/Controllers/Vault/RetentionRules/MonthlyRetentionRule.cs
rename to src/AliasVault.Api/Vault/RetentionRules/MonthlyRetentionRule.cs
index 8cb124342..631be2ee1 100644
--- a/src/AliasVault.Api/Controllers/Vault/RetentionRules/MonthlyRetentionRule.cs
+++ b/src/AliasVault.Api/Vault/RetentionRules/MonthlyRetentionRule.cs
@@ -5,7 +5,7 @@
// </copyright>
//-----------------------------------------------------------------------
-namespace AliasVault.Api.Controllers.Vault.RetentionRules;
+namespace AliasVault.Api.Vault.RetentionRules;
using AliasServerDb;
diff --git a/src/AliasVault.Api/Controllers/Vault/RetentionRules/WeeklyRetentionRule.cs b/src/AliasVault.Api/Vault/RetentionRules/WeeklyRetentionRule.cs
similarity index 95%
rename from src/AliasVault.Api/Controllers/Vault/RetentionRules/WeeklyRetentionRule.cs
rename to src/AliasVault.Api/Vault/RetentionRules/WeeklyRetentionRule.cs
index e03d2c030..7ce82d44a 100644
--- a/src/AliasVault.Api/Controllers/Vault/RetentionRules/WeeklyRetentionRule.cs
+++ b/src/AliasVault.Api/Vault/RetentionRules/WeeklyRetentionRule.cs
@@ -5,7 +5,7 @@
// </copyright>
//-----------------------------------------------------------------------
-namespace AliasVault.Api.Controllers.Vault.RetentionRules;
+namespace AliasVault.Api.Vault.RetentionRules;
using AliasServerDb;
diff --git a/src/AliasVault.Api/Controllers/Vault/VaultRetentionManager.cs b/src/AliasVault.Api/Vault/VaultRetentionManager.cs
similarity index 98%
rename from src/AliasVault.Api/Controllers/Vault/VaultRetentionManager.cs
rename to src/AliasVault.Api/Vault/VaultRetentionManager.cs
index 1ce90153a..f8ae0cb58 100644
--- a/src/AliasVault.Api/Controllers/Vault/VaultRetentionManager.cs
+++ b/src/AliasVault.Api/Vault/VaultRetentionManager.cs
@@ -5,7 +5,7 @@
// </copyright>
//-----------------------------------------------------------------------
-namespace AliasVault.Api.Controllers.Vault;
+namespace AliasVault.Api.Vault;
using System;
using System.Collections.Generic;
diff --git a/src/AliasVault.WebApp/Pages/Test/Test1.razor b/src/AliasVault.WebApp/Pages/Test/Test1.razor
new file mode 100644
index 000000000..42fabeeb8
--- /dev/null
+++ b/src/AliasVault.WebApp/Pages/Test/Test1.razor
@@ -0,0 +1,43 @@
+@page "/test/1"
+@inherits PageBase
+@inject HttpClient HttpClient
+
+<LayoutPageTitle>Test webapi call 1</LayoutPageTitle>
+
+<div class="grid grid-cols-1 px-4 pt-6 xl:grid-cols-3 xl:gap-4 dark:bg-gray-900">
+ <div class="mb-4 col-span-full xl:mb-2">
+ <Breadcrumb BreadcrumbItems="BreadcrumbItems" />
+ <div class="flex items-center justify-between">
+ <h1 class="text-xl font-semibold text-gray-900 sm:text-2xl dark:text-white">Test webapi call 1</h1>
+ </div>
+ <p>Test webapi call 1.</p>
+ </div>
+</div>
+
+@if (IsLoading)
+{
+ <LoadingIndicator />
+}
+
+@code {
+ private bool IsLoading { get; set; } = true;
+
+ /// <inheritdoc />
+ protected override async Task OnAfterRenderAsync(bool firstRender)
+ {
+ await base.OnAfterRenderAsync(firstRender);
+
+ if (firstRender)
+ {
+ await MakeWebApiCall();
+ }
+ }
+
+ private async Task MakeWebApiCall()
+ {
+ await HttpClient.GetAsync("api/v1/Test");
+
+ IsLoading = false;
+ StateHasChanged();
+ }
+}
diff --git a/src/AliasVault.WebApp/Pages/Test/Test2.razor b/src/AliasVault.WebApp/Pages/Test/Test2.razor
new file mode 100644
index 000000000..ed2b44c28
--- /dev/null
+++ b/src/AliasVault.WebApp/Pages/Test/Test2.razor
@@ -0,0 +1,43 @@
+@page "/test/2"
+@inherits PageBase
+@inject HttpClient HttpClient
+
+<LayoutPageTitle>Test webapi call 2</LayoutPageTitle>
+
+<div class="grid grid-cols-1 px-4 pt-6 xl:grid-cols-3 xl:gap-4 dark:bg-gray-900">
+ <div class="mb-4 col-span-full xl:mb-2">
+ <Breadcrumb BreadcrumbItems="BreadcrumbItems" />
+ <div class="flex items-center justify-between">
+ <h1 class="text-xl font-semibold text-gray-900 sm:text-2xl dark:text-white">Test webapi call 2</h1>
+ </div>
+ <p>Test webapi call 2.</p>
+ </div>
+</div>
+
+@if (IsLoading)
+{
+ <LoadingIndicator />
+}
+
+@code {
+ private bool IsLoading { get; set; } = true;
+
+ /// <inheritdoc />
+ protected override async Task OnAfterRenderAsync(bool firstRender)
+ {
+ await base.OnAfterRenderAsync(firstRender);
+
+ if (firstRender)
+ {
+ await MakeWebApiCall();
+ }
+ }
+
+ private async Task MakeWebApiCall()
+ {
+ await HttpClient.GetAsync("api/v1/Test");
+
+ IsLoading = false;
+ StateHasChanged();
+ }
+}
diff --git a/src/Tests/AliasVault.E2ETests/Tests/JwtTokenTests.cs b/src/Tests/AliasVault.E2ETests/Tests/JwtTokenTests.cs
index 80868cccc..77ea25c6d 100644
--- a/src/Tests/AliasVault.E2ETests/Tests/JwtTokenTests.cs
+++ b/src/Tests/AliasVault.E2ETests/Tests/JwtTokenTests.cs
@@ -22,20 +22,20 @@ public class JwtTokenTests : PlaywrightTest
[Test]
public async Task RefreshTokenTest()
{
- // Soft navigate to "aliases" page to verify that it works.
- await NavigateUsingBlazorRouter("aliases");
- await WaitForURLAsync("**/aliases", "Find all of your aliases below");
+ // Soft navigate to verify that we are logged in.
+ await NavigateUsingBlazorRouter("test/1");
+ await WaitForURLAsync("**/test/1", "Test webapi call 1.");
// Increase the time by 1 hour to make the JWT token expire.
ApiTimeProvider.AdvanceBy(TimeSpan.FromHours(1));
// Soft navigate to another page to trigger the JWT token refresh
// and check if the page is loaded successfully.
- await NavigateUsingBlazorRouter("dbtest");
- await WaitForURLAsync("**/dbtest", "Find all of your aliases below.");
+ await NavigateUsingBlazorRouter("test/2");
+ await WaitForURLAsync("**/test/2", "Test webapi call 2.");
var pageContent = await Page.TextContentAsync("body");
- Assert.That(pageContent, Does.Contain("Find all of your aliases below"), "No index content after unlocking database.");
+ Assert.That(pageContent, Does.Contain("Test webapi call 2."), "No page content after refreshing access token.");
}
/// <summary>
@@ -47,10 +47,10 @@ public class JwtTokenTests : PlaywrightTest
[Test]
public async Task RefreshTokenUnlockPageTest()
{
- // Soft navigate to "aliases" page to verify that it works.
- var startUrl = "dbtest";
+ // Soft navigate to verify that we are logged in.
+ var startUrl = "test/1";
await NavigateUsingBlazorRouter(startUrl);
- await WaitForURLAsync("**/" + startUrl, "Find all of your aliases below");
+ await WaitForURLAsync("**/" + startUrl, "Test webapi call 1.");
// Hard reload the page to trigger the unlock page to show up.
await Page.ReloadAsync();
@@ -73,7 +73,7 @@ public class JwtTokenTests : PlaywrightTest
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 with a expired JWT token.");
+ Assert.That(pageContent, Does.Contain("Test webapi call 1."), "No index content after unlocking database with a expired JWT token.");
}
/// <summary>
@@ -84,9 +84,9 @@ public class JwtTokenTests : PlaywrightTest
[Test]
public async Task RefreshTokenExpiredTest()
{
- // Soft navigate to "aliases" page to verify that it works.
- await NavigateUsingBlazorRouter("aliases");
- await WaitForURLAsync("**/aliases", "Find all of your aliases below");
+ // Soft navigate to verify that we are logged in.
+ await NavigateUsingBlazorRouter("test/1");
+ await WaitForURLAsync("**/test/1", "Test webapi call 1.");
// Increase the time by 1 year to make the JWT token AND refresh token expire.
ApiTimeProvider.AdvanceBy(TimeSpan.FromDays(365));
@@ -94,9 +94,7 @@ public class JwtTokenTests : PlaywrightTest
// Soft navigate to another page to trigger the JWT token refresh
// and check if the page is loaded successfully.
// Not all pages do a webapi call on load everytime so we need to navigate to a page that does.
- await NavigateUsingBlazorRouter("dbtest");
- await NavigateUsingBlazorRouter("aliases");
- await NavigateUsingBlazorRouter("dbtest");
+ await NavigateUsingBlazorRouter("test/2");
await WaitForURLAsync("**/user/login", "Login");
diff --git a/src/Tests/AliasVault.E2ETests/Tests/UnlockTests.cs b/src/Tests/AliasVault.E2ETests/Tests/UnlockTests.cs
index f5cb928ee..c69870585 100644
--- a/src/Tests/AliasVault.E2ETests/Tests/UnlockTests.cs
+++ b/src/Tests/AliasVault.E2ETests/Tests/UnlockTests.cs
@@ -23,7 +23,7 @@ public class UnlockTests : PlaywrightTest
public async Task UnlockPageTest()
{
// Soft navigate to "aliases" page to test the unlock redirect.
- var startUrl = "aliases";
+ var startUrl = "test/1";
await NavigateUsingBlazorRouter(startUrl);
// Hard refresh the page.
@@ -42,10 +42,10 @@ public class UnlockTests : PlaywrightTest
await submitButton.ClickAsync();
// Check if we get redirected back to the page we were trying to access.
- await WaitForURLAsync("**/" + startUrl, "AliasVault");
+ await WaitForURLAsync("**/" + startUrl, "Test webapi call 1.");
var pageContent = await Page.TextContentAsync("body");
- Assert.That(pageContent, Does.Contain("Find all of your aliases below"), "No index content after unlocking database.");
+ Assert.That(pageContent, Does.Contain("Test webapi call 1."), "No index content after unlocking database.");
}
/// <summary>
@@ -56,7 +56,7 @@ public class UnlockTests : PlaywrightTest
public async Task UnlockPageRedirect()
{
// Soft navigate to "aliases" page to test the unlock redirect.
- var startUrl = "aliases";
+ var startUrl = "test/1";
await NavigateUsingBlazorRouter(startUrl);
// Hard refresh the page.
@@ -81,9 +81,9 @@ public class UnlockTests : PlaywrightTest
await submitButton.ClickAsync();
// Check if we get redirected back to the page we were trying to access.
- await WaitForURLAsync("**/" + startUrl, "AliasVault");
+ await WaitForURLAsync("**/" + startUrl, "Test webapi call 1.");
var pageContent = await Page.TextContentAsync("body");
- Assert.That(pageContent, Does.Contain("Find all of your aliases below"), "No index content after unlocking database.");
+ Assert.That(pageContent, Does.Contain("Test webapi call 1."), "No index content after unlocking database.");
}
}