Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add user registration log entry and include auth log E2E tests (#199)
Leendert de Borst5a1649586445
diff --git a/src/AliasVault.Api/Controllers/AuthController.cs b/src/AliasVault.Api/Controllers/AuthController.csindex b8fe5f61d..1809c2210 100644--- a/src/AliasVault.Api/Controllers/AuthController.cs+++ b/src/AliasVault.Api/Controllers/AuthController.cs@@ -313,6 +313,8 @@ public class AuthController(IDbContextFactory<AliasServerDbContext> dbContextFacif (result.Succeeded){+ await authLoggingService.LogAuthEventSuccessAsync(model.Username, AuthEventType.Register);+// When a user is registered, they are automatically signed in.await signInManager.SignInAsync(user, isPersistent: false);diff --git a/src/AliasVault.Shared/Models/Enums/AuthEventType.cs b/src/AliasVault.Shared/Models/Enums/AuthEventType.csindex bf86f018b..4c1782fdf 100644--- a/src/AliasVault.Shared/Models/Enums/AuthEventType.cs+++ b/src/AliasVault.Shared/Models/Enums/AuthEventType.cs@@ -51,4 +51,9 @@ public enum AuthEventType/// Represents disabling two-factor authentication in settings./// </summary>TwoFactorAuthDisable = 23,++ /// <summary>+ /// Represents a user registration event.+ /// </summary>+ Register = 30,}diff --git a/src/Tests/AliasVault.E2ETests/Tests/Client/AuthTests.cs b/src/Tests/AliasVault.E2ETests/Tests/Client/AuthTests.csindex 841bc6ffc..876c80ae8 100644--- a/src/Tests/AliasVault.E2ETests/Tests/Client/AuthTests.cs+++ b/src/Tests/AliasVault.E2ETests/Tests/Client/AuthTests.cs@@ -7,6 +7,9 @@namespace AliasVault.E2ETests.Tests.Client;+using AliasVault.Shared.Models.Enums;+using Microsoft.EntityFrameworkCore;+/// <summary>/// End-to-end tests for authentication./// </summary>@@ -16,11 +19,25 @@ namespace AliasVault.E2ETests.Tests.Client;public class AuthTests : ClientPlaywrightTest{/// <summary>- /// Test if logging out and logging in works.+ /// Test if initial registration has created an auth log entry./// </summary>/// <returns>Async task.</returns>[Test][Order(1)]+ public async Task RegistrationAuthLog()+ {+ // Check if the registration executed by the test setup method has+ // lead to the creation of an auth log entry in the database.+ var authLogEntry = await ApiDbContext.AuthLogs.FirstOrDefaultAsync(x => x.Username == TestUserUsername && x.EventType == AuthEventType.Register);+ Assert.That(authLogEntry, Is.Not.Null, "Auth log entry not found in database after registration.");+ }++ /// <summary>+ /// Test if logging out and logging in works.+ /// </summary>+ /// <returns>Async task.</returns>+ [Test]+ [Order(2)]public async Task LogoutAndLoginTest(){// Logout.@@ -31,6 +48,10 @@ public class AuthTests : ClientPlaywrightTestawait WaitForUrlAsync("user/login");await Login();++ // Check if login has created an auth log entry.+ var authLogEntry = await ApiDbContext.AuthLogs.FirstOrDefaultAsync(x => x.Username == TestUserUsername && x.EventType == AuthEventType.Login);+ Assert.That(authLogEntry, Is.Not.Null, "Auth log entry not found in database after login.");}/// <summary>@@ -38,7 +59,7 @@ public class AuthTests : ClientPlaywrightTest/// </summary>/// <returns>Async task.</returns>[Test]- [Order(2)]+ [Order(3)]public async Task RegisterFormWarningTest(){// Logout.@@ -78,7 +99,7 @@ public class AuthTests : ClientPlaywrightTest/// </summary>/// <returns>Async task.</returns>[Test]- [Order(3)]+ [Order(4)]public async Task PasswordAuthLockoutTest(){// Logout.@@ -106,6 +127,10 @@ public class AuthTests : ClientPlaywrightTestawait WaitForUrlAsync("user/login**", "Invalid username or password.");}+ // Check if the correct amount of auth failure log entries were created.+ var authLogEntryFailureCount = await ApiDbContext.AuthLogs.CountAsync(x => x.Username == TestUserUsername && x.EventType == AuthEventType.Login && !x.IsSuccess);+ Assert.That(authLogEntryFailureCount, Is.EqualTo(10), "10 failed login attempts did not result in 10 failed auth log records.");+// Wait for account lockout message.await WaitForUrlAsync("user/login**", "locked out");var pageContent = await Page.TextContentAsync("body");