mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 18:21:10 +00:00
Implements authorization caching and check in the web client
This commit is contained in:
1 parent
7bca5b1ba3
commit
8eb1b9f13c
108 files changed
+5931
-73
No files matched your search
+41
@@ -0,0 +1,41 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.IntegrationTests.Common.Converters;
|
||||
|
||||
/// <summary>
|
||||
/// Custom JSON converter for readonly collections.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ReadOnlySetConverter<T> : JsonConverter<IReadOnlySet<T>>
|
||||
{
|
||||
/// <summary>
|
||||
/// Reads and converts JSON to a <see cref="IReadOnlySet{T}"/> object.
|
||||
/// </summary>
|
||||
/// <param name="reader">The JSON reader.</param>
|
||||
/// <param name="typeToConvert">The type of the object to convert.</param>
|
||||
/// <param name="options">The serializer options.</param>
|
||||
/// <returns>The converted readonly collection.</returns>
|
||||
public override IReadOnlySet<T> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
HashSet<T>? list = JsonSerializer.Deserialize<HashSet<T>>(ref reader, options);
|
||||
return list ?? [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a readonly collection object to JSON. This method is not implemented.
|
||||
/// </summary>
|
||||
/// <param name="writer">The JSON writer.</param>
|
||||
/// <param name="value">The <see cref="IReadOnlySet{T}"/> object to write.</param>
|
||||
/// <param name="options">The serializer options.</param>
|
||||
public override void Write(Utf8JsonWriter writer, IReadOnlySet<T> value, JsonSerializerOptions options)
|
||||
{
|
||||
JsonSerializer.Serialize(writer, value.ToList(), options);
|
||||
}
|
||||
}
|
||||
+1
@@ -73,6 +73,7 @@ public class AuthenticatedLuminaApiFactory : LuminaApiFactory, IDisposable
|
||||
// create test user
|
||||
UserEntity user = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Username = TestUsername!,
|
||||
Password = _hashService.HashString("TestPass123!"),
|
||||
Libraries = [],
|
||||
|
||||
+22
-1
@@ -14,6 +14,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.IntegrationTests.Common.Setup;
|
||||
@@ -98,7 +99,27 @@ public class LuminaApiFactory : WebApplicationFactory<Program>, IDisposable
|
||||
dbContext.Database.Migrate();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the in-memory SQLite database to its original state.
|
||||
/// </summary>
|
||||
public async Task ResetDatabaseAsync()
|
||||
{
|
||||
using IServiceScope scope = Services.CreateScope();
|
||||
LuminaDbContext context = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
||||
|
||||
context.Books.RemoveRange(context.Books);
|
||||
context.Libraries.RemoveRange(context.Libraries);
|
||||
context.RolePermissions.RemoveRange(context.RolePermissions);
|
||||
context.UserRoles.RemoveRange(context.UserRoles);
|
||||
context.Roles.RemoveRange(context.Roles);
|
||||
context.Permissions.RemoveRange(context.Permissions);
|
||||
context.Users.RemoveRange(context.Users);
|
||||
context.UserPermissions.RemoveRange(context.UserPermissions);
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the connection to the database.
|
||||
|
||||
Reference in new issue
Block a user