Implements Authorization system

This commit is contained in:
BinaryAlley committed 2024-11-22 18:02:42 +02:00
1 parent 5bfb2ca212
commit 2c9c210e43
68 files changed
+2734 -336

No files matched your search

@@ -76,7 +76,10 @@ public class AuthenticatedLuminaApiFactory : LuminaApiFactory, IDisposable
Username = TestUsername!,
Password = _hashService.HashString("TestPass123!"),
Libraries = [],
Created = DateTime.UtcNow
UserPermissions = [],
UserRoles = [],
CreatedBy = Guid.NewGuid(),
CreatedOnUtc = DateTime.UtcNow
};
dbContext.Users.Add(user);
@@ -1,4 +1,5 @@
#region ========================================================================= USING =====================================================================================
using Lumina.DataAccess.Common.Interceptors;
using Lumina.DataAccess.Core.UoW;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Hosting;
@@ -69,7 +70,11 @@ public class LuminaApiFactory : WebApplicationFactory<Program>, IDisposable
if (descriptor is not null)
services.Remove(descriptor);
// add SQLite DbContext configuration
services.AddDbContext<LuminaDbContext>(options => options.UseSqlite(_connection));
services.AddDbContext<LuminaDbContext>((serviceProvider, options) =>
{
options.UseSqlite(_connection);
options.AddInterceptors(serviceProvider.GetRequiredService<UpdateAuditableEntitiesInterceptor>());
});
// configure JWT authentication for testing
services.PostConfigure<JwtBearerOptions>(JwtBearerDefaults.AuthenticationScheme, options =>
{
@@ -119,7 +119,10 @@ public class CheckInitializationEndpointTests : IClassFixture<AuthenticatedLumin
Username = _testUsername,
Password = new HashService().HashString("TestPass123!"),
Libraries = [],
Created = DateTime.UtcNow
UserPermissions = [],
UserRoles = [],
CreatedBy = Guid.NewGuid(),
CreatedOnUtc = DateTime.UtcNow
};
dbContext.Users.Add(user);
@@ -173,7 +173,10 @@ public class SetupApplicationEndpointTests : IClassFixture<AuthenticatedLuminaAp
Username = _testUsername,
Password = new HashService().HashString("TestPass123!"),
Libraries = [],
Created = DateTime.UtcNow
UserPermissions = [],
UserRoles = [], // TODO: test default role and permissions?
CreatedBy = Guid.NewGuid(),
CreatedOnUtc = DateTime.UtcNow
};
dbContext.Users.Add(user);
@@ -245,7 +245,10 @@ public class LoginEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>,
Username = _testUsername,
Password = _hashService.HashString("TestPass123!"),
Libraries = [],
Created = DateTime.UtcNow
UserPermissions = [],
UserRoles = [],
CreatedBy = Guid.NewGuid(),
CreatedOnUtc = DateTime.UtcNow
};
dbContext.Users.Add(user);
@@ -265,7 +268,10 @@ public class LoginEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>,
Password = _hashService.HashString("TestPass123!"),
TotpSecret = _cryptographyService.Encrypt(Convert.ToBase64String(totpSecret)),
Libraries = [],
Created = DateTime.UtcNow
UserPermissions = [],
UserRoles = [],
CreatedBy = Guid.NewGuid(),
CreatedOnUtc = DateTime.UtcNow
};
dbContext.Users.Add(user);
@@ -285,7 +291,10 @@ public class LoginEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>,
TempPassword = Uri.EscapeDataString(_hashService.HashString("TempPass123!")),
TempPasswordCreated = DateTime.UtcNow,
Libraries = [],
Created = DateTime.UtcNow
UserPermissions = [],
UserRoles = [],
CreatedBy = Guid.NewGuid(),
CreatedOnUtc = DateTime.UtcNow
};
dbContext.Users.Add(user);
@@ -305,7 +314,10 @@ public class LoginEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>,
TempPassword = Uri.EscapeDataString(_hashService.HashString("TempPass123!")),
TempPasswordCreated = DateTime.UtcNow.AddMinutes(-16), // expired (> 15 minutes old)
Libraries = [],
Created = DateTime.UtcNow
UserPermissions = [],
UserRoles = [],
CreatedBy = Guid.NewGuid(),
CreatedOnUtc = DateTime.UtcNow
};
dbContext.Users.Add(user);
@@ -242,7 +242,10 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
Password = _hashService.HashString("OldPass123!"),
TotpSecret = null, // No TOTP configured
Libraries = [],
Created = DateTime.UtcNow
UserPermissions = [],
UserRoles = [],
CreatedBy = Guid.NewGuid(),
CreatedOnUtc = DateTime.UtcNow
};
dbContext.Users.Add(userWithoutTotp);
await dbContext.SaveChangesAsync();
@@ -306,7 +309,10 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
Password = _hashService.HashString("OldPass123!"),
TotpSecret = _cryptographyService.Encrypt(Convert.ToBase64String(totpSecret)),
Libraries = [],
Created = DateTime.UtcNow
UserPermissions = [],
UserRoles = [],
CreatedBy = Guid.NewGuid(),
CreatedOnUtc = DateTime.UtcNow
};
dbContext.Users.Add(user);
@@ -325,7 +331,10 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
Password = _hashService.HashString("OldPass123!"),
TotpSecret = null,
Libraries = [],
Created = DateTime.UtcNow
UserPermissions = [],
UserRoles = [],
CreatedBy = Guid.NewGuid(),
CreatedOnUtc = DateTime.UtcNow
};
dbContext.Users.Add(user);
@@ -191,7 +191,10 @@ public class RegisterEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
Username = _testUsername,
Password = new HashService().HashString("TestPass123!"),
Libraries = [],
Created = DateTime.UtcNow
UserPermissions = [],
UserRoles = [],
CreatedBy = Guid.NewGuid(),
CreatedOnUtc = DateTime.UtcNow
};
dbContext.Users.Add(user);