From 9d0fc082c048f2ba40f077737511f64afda9bee2 Mon Sep 17 00:00:00 2001 From: Leendert de Borst Date: Sat, 14 Sep 2024 21:05:37 +0200 Subject: [PATCH] Refactor (#192) --- src/AliasVault.Api/Controllers/AuthController.cs | 4 +--- src/Tests/AliasVault.E2ETests/Common/PlaywrightTest.cs | 5 ++++- src/Utilities/AliasVault.Auth/IpAddressUtility.cs | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/AliasVault.Api/Controllers/AuthController.cs b/src/AliasVault.Api/Controllers/AuthController.cs index 1b7eda831..468bda242 100644 --- a/src/AliasVault.Api/Controllers/AuthController.cs +++ b/src/AliasVault.Api/Controllers/AuthController.cs @@ -248,7 +248,7 @@ public class AuthController(IDbContextFactory dbContextFac } // Check if the refresh token is valid. - var existingToken = context.AliasVaultUserRefreshTokens.FirstOrDefault(t => t.UserId == user.Id && t.Value == tokenModel.RefreshToken); + var existingToken = await context.AliasVaultUserRefreshTokens.FirstOrDefaultAsync(t => t.UserId == user.Id && t.Value == tokenModel.RefreshToken); if (existingToken == null || existingToken.ExpireDate < timeProvider.UtcNow) { await authLoggingService.LogAuthEventFailAsync(user.UserName!, AuthEventType.TokenRefresh, AuthFailureReason.InvalidRefreshToken); @@ -536,8 +536,6 @@ public class AuthController(IDbContextFactory dbContextFac { await using var context = await dbContextFactory.CreateDbContextAsync(); - var accessToken = GenerateJwtToken(user); - await _semaphore.WaitAsync(); try { diff --git a/src/Tests/AliasVault.E2ETests/Common/PlaywrightTest.cs b/src/Tests/AliasVault.E2ETests/Common/PlaywrightTest.cs index eef1e963a..e0028a333 100644 --- a/src/Tests/AliasVault.E2ETests/Common/PlaywrightTest.cs +++ b/src/Tests/AliasVault.E2ETests/Common/PlaywrightTest.cs @@ -5,7 +5,10 @@ // //----------------------------------------------------------------------- -// Run tests in parallel with a maximum of 2 parallel tests. +// Run tests in parallel with a maximum of 1 parallel tests (= not parallel). +// Increasing the level of parallelism can lead to concurrency issues especially +// when running tests through GitHub Actions where the retry will take +// longer to complete as opposed to running just one test at a time. [assembly: LevelOfParallelism(1)] namespace AliasVault.E2ETests.Common; diff --git a/src/Utilities/AliasVault.Auth/IpAddressUtility.cs b/src/Utilities/AliasVault.Auth/IpAddressUtility.cs index b60af2f09..f62d811bd 100644 --- a/src/Utilities/AliasVault.Auth/IpAddressUtility.cs +++ b/src/Utilities/AliasVault.Auth/IpAddressUtility.cs @@ -12,7 +12,7 @@ using Microsoft.AspNetCore.Http; /// /// Ip address utility class to extract IP address from HttpContext. /// -public class IpAddressUtility +public static class IpAddressUtility { /// /// Extract IP address from HttpContext.