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

@@ -1,8 +1,11 @@
#region ========================================================================= USING =====================================================================================
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Repositories.Books;
using Lumina.Application.Common.Infrastructure.Authentication;
using Lumina.Application.Common.Infrastructure.Time;
using Lumina.DataAccess.Common.DependencyInjection;
using Lumina.DataAccess.Core.Repositories.Common.Factory;
using Lumina.DataAccess.UnitTests.Common.Setup;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Diagnostics.CodeAnalysis;
@@ -22,6 +25,9 @@ public class RepositoryFactoryTests
// Arrange
ServiceCollection services = new();
DataAccessLayerServices.AddDataAccessLayerServices(services);
services.AddTransient<ICurrentUserService, TestCurrentUserService>();
services.AddTransient<IDateTimeProvider, TestDateTimeProvider>();
ServiceProvider serviceProvider = services.BuildServiceProvider();
RepositoryFactory repositoryFactory = new(serviceProvider);
@@ -48,4 +54,4 @@ public class RepositoryFactoryTests
}
}
public interface IUnregisteredRepository { }
public interface IUnregisteredRepository { }
@@ -44,12 +44,12 @@ public class UserEntityFixture
.RuleFor(x => x.Password, f => f.Internet.Password(12))
.RuleFor(x => x.TempPassword, f => f.Random.Bool() ? f.Internet.Password(8) : null)
.RuleFor(x => x.TotpSecret, f => f.Random.Bool() ? f.Random.String2(32, "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567") : null)
.RuleFor(x => x.VerificationToken, f => f.Random.Bool() ? f.Random.Guid().ToString() : null)
.RuleFor(x => x.VerificationTokenCreated, (f, u) => u.VerificationToken != null ? f.Date.Past() : null)
.RuleFor(x => x.TempPasswordCreated, (f, u) => u.TempPassword != null ? f.Date.Past() : null)
.RuleFor(x => x.Libraries, _ => CreateLibraries(_faker.Random.Number(1, 3), userId))
.RuleFor(x => x.Created, f => f.Date.Past())
.RuleFor(x => x.Updated, f => f.Random.Bool() ? f.Date.Recent() : null)
.RuleFor(x => x.CreatedOnUtc, f => f.Date.Past())
.RuleFor(x => x.CreatedBy, _ => userId)
.RuleFor(x => x.UpdatedOnUtc, f => f.Random.Bool() ? f.Date.Recent() : null)
.RuleFor(x => x.UpdatedBy, _ => userId)
.Generate();
}
@@ -155,8 +155,11 @@ public class UserRepositoryTests
TempPassword = "TempPass456",
TotpSecret = "NewSecret",
Libraries = [],
Created = existingUser.Created,
Updated = DateTime.UtcNow
UserRoles = [],
UserPermissions = [],
CreatedBy = existingUser.Id,
CreatedOnUtc = existingUser.CreatedOnUtc,
UpdatedOnUtc = DateTime.UtcNow
};
// Act