mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 14:11:10 +00:00
Renames project paths from Lumina to Nemera
This commit is contained in:
1 parent
ce6fddb4c9
commit
0f659a4877
6450 files changed
No files matched your search
+34
@@ -0,0 +1,34 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Infrastructure.Common.Models.DTO.Configuration;
|
||||
using Lumina.Infrastructure.Fixtures.Common.Models.DTO.Configuration;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.Fixtures.Core.Authentication;
|
||||
|
||||
/// <summary>
|
||||
/// Test-support class for JWT token generation tests.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class JwtTokenGeneratorFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a valid JWT settings model for testing.
|
||||
/// </summary>
|
||||
/// <returns>The created settings model.</returns>
|
||||
public static JwtSettingsDto CreateJwtSettings()
|
||||
{
|
||||
return new JwtSettingsDtoFixture().Create();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates test user credentials.
|
||||
/// </summary>
|
||||
/// <returns>A tuple containing the user ID and username.</returns>
|
||||
public static (string Id, string Username) CreateUserCredentials()
|
||||
{
|
||||
return (Guid.NewGuid().ToString(), new Faker().Person.UserName);
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.Fixtures.Core.Authentication;
|
||||
|
||||
/// <summary>
|
||||
/// Test-support class for QR code generation tests.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class QRCodeGeneratorFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates test data for QR code generation.
|
||||
/// </summary>
|
||||
/// <returns>A tuple containing username and secret bytes.</returns>
|
||||
public static (string Username, byte[] Secret) CreateQrCodeTestData()
|
||||
{
|
||||
string username = new Faker().Person.UserName;
|
||||
byte[] secret = new byte[20]; // Standard TOTP secret length.
|
||||
Random.Shared.NextBytes(secret);
|
||||
return (username, secret);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the expected otpauth URI format for validation.
|
||||
/// </summary>
|
||||
/// <param name="username">The username to use in the URI.</param>
|
||||
/// <param name="base32Secret">The Base32 encoded secret.</param>
|
||||
/// <returns>The formatted otpauth URI.</returns>
|
||||
public static string GetExpectedOtpauthUri(string username, string base32Secret)
|
||||
{
|
||||
return $"otpauth://totp/Lumina:{Uri.EscapeDataString(username)}?secret={base32Secret}&issuer=Lumina";
|
||||
}
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
||||
using Lumina.Infrastructure.Core.Authorization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.Fixtures.Core.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Test-support class for the <see cref="AuthorizationService"/> tests.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AuthorizationServiceFixture
|
||||
{
|
||||
private readonly UserEntityFixture _userEntityFixture = new();
|
||||
private readonly RoleEntityFixture _roleEntityFixture = new();
|
||||
private readonly PermissionEntityFixture _permissionEntityFixture = new();
|
||||
private readonly RolePermissionEntityFixture _rolePermissionEntityFixture = new();
|
||||
private readonly UserRoleEntityFixture _userRoleEntityFixture = new();
|
||||
private readonly UserPermissionEntityFixture _userPermissionEntityFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a user entity with specified permissions and roles.
|
||||
/// </summary>
|
||||
/// <param name="directPermissions">Direct permissions to assign to the user.</param>
|
||||
/// <param name="rolePermissions">Permissions to assign through roles.</param>
|
||||
/// <returns>The created user entity.</returns>
|
||||
public UserEntity CreateUserWithPermissions(
|
||||
IEnumerable<AuthorizationPermission>? directPermissions = null,
|
||||
Dictionary<string, IEnumerable<AuthorizationPermission>>? rolePermissions = null)
|
||||
{
|
||||
Guid userId = Guid.NewGuid();
|
||||
DateTime utcNow = DateTime.UtcNow;
|
||||
UserRoleEntity? userRole = null;
|
||||
|
||||
if (rolePermissions is not null)
|
||||
{
|
||||
foreach (KeyValuePair<string, IEnumerable<AuthorizationPermission>> rolePerm in rolePermissions)
|
||||
{
|
||||
Guid roleId = Guid.NewGuid();
|
||||
RoleEntity role = _roleEntityFixture.Create(
|
||||
id: roleId,
|
||||
roleName: rolePerm.Key,
|
||||
createdBy: userId,
|
||||
createdOnUtc: utcNow);
|
||||
|
||||
foreach (AuthorizationPermission permission in rolePerm.Value)
|
||||
{
|
||||
Guid permissionId = Guid.NewGuid();
|
||||
PermissionEntity permissionEntity = _permissionEntityFixture.Create(
|
||||
id: permissionId,
|
||||
permissionName: permission,
|
||||
createdBy: userId,
|
||||
createdOnUtc: utcNow);
|
||||
|
||||
role.RolePermissions.Add(_rolePermissionEntityFixture.Create(
|
||||
role: role,
|
||||
permission: permissionEntity,
|
||||
createdBy: userId,
|
||||
createdOnUtc: utcNow));
|
||||
}
|
||||
|
||||
userRole = _userRoleEntityFixture.Create(
|
||||
userId: userId,
|
||||
roleId: roleId,
|
||||
role: role,
|
||||
includeUser: false,
|
||||
createdBy: userId,
|
||||
createdOnUtc: utcNow);
|
||||
}
|
||||
}
|
||||
|
||||
UserEntity user = _userEntityFixture.Create(
|
||||
username: "test-user",
|
||||
password: "hashed-password",
|
||||
id: userId,
|
||||
userRole: userRole,
|
||||
includeUserRole: true,
|
||||
createdBy: userId,
|
||||
createdOnUtc: utcNow);
|
||||
|
||||
if (directPermissions is not null)
|
||||
{
|
||||
foreach (AuthorizationPermission permission in directPermissions)
|
||||
{
|
||||
Guid permissionId = Guid.NewGuid();
|
||||
PermissionEntity permissionEntity = _permissionEntityFixture.Create(
|
||||
id: permissionId,
|
||||
permissionName: permission,
|
||||
createdBy: userId,
|
||||
createdOnUtc: utcNow);
|
||||
|
||||
user.UserPermissions.Add(_userPermissionEntityFixture.Create(
|
||||
user,
|
||||
permissionEntity,
|
||||
createdOnUtc: utcNow,
|
||||
createdBy: userId));
|
||||
}
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Authorization.Policies.Common.Base;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.Fixtures.Core.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Example concrete policy for testing generic constraint.
|
||||
/// </summary>
|
||||
public interface ITestAuthorizationPolicy : IAuthorizationPolicy { }
|
||||
@@ -0,0 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Authorization.Policies.Common.Base;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.Fixtures.Core.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Test policy interface for unregistered policy scenarios.
|
||||
/// </summary>
|
||||
public interface IUnregisteredPolicy : IAuthorizationPolicy { }
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Authorization.Policies.Common.Base;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.Fixtures.Core.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Test policy implementation for registered policy scenarios.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class TestAuthorizationPolicy : IAuthorizationPolicy
|
||||
{
|
||||
public Task<bool> EvaluateAsync(Guid userId, PolicyContext? context, CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Infrastructure.Common.Models.DTO.Configuration;
|
||||
using Lumina.Infrastructure.Fixtures.Common.Models.DTO.Configuration;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Security.Cryptography;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.Fixtures.Core.Security;
|
||||
|
||||
/// <summary>
|
||||
/// Test-support class for cryptography service tests.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CryptographyServiceFixture
|
||||
{
|
||||
private readonly EncryptionSettingsDtoFixture _encryptionSettingsDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a valid encryption settings model for testing.
|
||||
/// </summary>
|
||||
/// <returns>The configured options.</returns>
|
||||
public IOptions<EncryptionSettingsDto> CreateEncryptionSettings()
|
||||
{
|
||||
// Generate a valid 256-bit (32 byte) key for AES-256.
|
||||
byte[] key = new byte[32];
|
||||
RandomNumberGenerator.Fill(key);
|
||||
string base64Key = Convert.ToBase64String(key);
|
||||
|
||||
EncryptionSettingsDto settings = _encryptionSettingsDtoFixture.Create(secretKey: base64Key);
|
||||
|
||||
IOptions<EncryptionSettingsDto> options = Substitute.For<IOptions<EncryptionSettingsDto>>();
|
||||
options.Value.Returns(settings);
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates test data for encryption/decryption.
|
||||
/// </summary>
|
||||
/// <returns>A string to be encrypted/decrypted.</returns>
|
||||
public string CreateTestData()
|
||||
{
|
||||
return new Faker().Lorem.Sentence();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.Fixtures.Core.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Describes a single entry of a theme pack ZIP archive built by the <see cref="ThemePackFixture"/>.
|
||||
/// </summary>
|
||||
/// <param name="Path">The entry path inside the archive.</param>
|
||||
/// <param name="Content">The text content of the entry.</param>
|
||||
/// <param name="UnixFileType">Optional Unix file type for the entry, used to simulate special file types such as symbolic links.</param>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public sealed record ThemeArchiveEntry(string Path, string Content, int? UnixFileType = null);
|
||||
@@ -0,0 +1,148 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.Fixtures.Core.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating theme pack ZIP archives used by theme tests.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public sealed class ThemePackFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a valid theme pack ZIP archive containing a manifest, the template files referenced by it and a preview asset.
|
||||
/// </summary>
|
||||
/// <param name="themeId">Optional theme id written to the manifest.</param>
|
||||
/// <param name="name">Optional display name written to the manifest.</param>
|
||||
/// <param name="description">Optional description written to the manifest.</param>
|
||||
/// <param name="author">Optional author written to the manifest.</param>
|
||||
/// <param name="version">Optional version written to the manifest.</param>
|
||||
/// <param name="schemaVersion">Optional schema version written to the manifest.</param>
|
||||
/// <param name="templates">Optional template mappings written to the manifest.</param>
|
||||
/// <param name="preview">Optional preview path written to the manifest, or <see langword="null"/> to omit the preview.</param>
|
||||
/// <param name="defaultTemplateContent">Optional content for the default template file.</param>
|
||||
/// <param name="additionalFiles">Optional additional files written into the archive.</param>
|
||||
/// <param name="includePreviewAsset">Whether to include the preview asset file in the archive or not.</param>
|
||||
/// <returns>The created theme pack ZIP archive.</returns>
|
||||
public byte[] Create(
|
||||
string themeId = "test-theme",
|
||||
string? name = null,
|
||||
string? description = null,
|
||||
string? author = null,
|
||||
string? version = null,
|
||||
int? schemaVersion = null,
|
||||
Dictionary<string, string>? templates = null,
|
||||
string? preview = "assets/preview.png",
|
||||
string? defaultTemplateContent = null,
|
||||
IReadOnlyDictionary<string, string>? additionalFiles = null,
|
||||
bool includePreviewAsset = true)
|
||||
{
|
||||
Dictionary<string, string> manifestTemplates = templates ?? new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
["default"] = "templates/default.html"
|
||||
};
|
||||
|
||||
string manifestJson = CreateManifestJson(
|
||||
themeId,
|
||||
name,
|
||||
description,
|
||||
author,
|
||||
version,
|
||||
schemaVersion,
|
||||
manifestTemplates,
|
||||
preview);
|
||||
|
||||
List<ThemeArchiveEntry> entries = [new("theme.json", manifestJson)];
|
||||
foreach ((string key, string templatePath) in manifestTemplates)
|
||||
entries.Add(new(templatePath, defaultTemplateContent ?? $"<html><body>{key} template</body></html>"));
|
||||
|
||||
if (preview is not null && includePreviewAsset)
|
||||
entries.Add(new("assets/preview.png", "preview-image-bytes"));
|
||||
|
||||
if (additionalFiles is not null)
|
||||
entries.AddRange(additionalFiles.Select(file => new ThemeArchiveEntry(file.Key, file.Value)));
|
||||
|
||||
return CreateArchive([.. entries]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the JSON content of a theme manifest with test defaults that can be overridden per field.
|
||||
/// </summary>
|
||||
/// <param name="themeId">Optional theme id written to the manifest.</param>
|
||||
/// <param name="name">Optional display name written to the manifest.</param>
|
||||
/// <param name="description">Optional description written to the manifest.</param>
|
||||
/// <param name="author">Optional author written to the manifest.</param>
|
||||
/// <param name="version">Optional version written to the manifest.</param>
|
||||
/// <param name="schemaVersion">Optional schema version written to the manifest.</param>
|
||||
/// <param name="templates">Optional template mappings written to the manifest.</param>
|
||||
/// <param name="preview">Optional preview path written to the manifest, or <see langword="null"/> to omit the preview.</param>
|
||||
/// <returns>The created manifest JSON content.</returns>
|
||||
public string CreateManifestJson(
|
||||
string themeId = "test-theme",
|
||||
string? name = null,
|
||||
string? description = null,
|
||||
string? author = null,
|
||||
string? version = null,
|
||||
int? schemaVersion = null,
|
||||
Dictionary<string, string>? templates = null,
|
||||
string? preview = "assets/preview.png")
|
||||
{
|
||||
object manifest = new
|
||||
{
|
||||
schemaVersion = schemaVersion ?? 1,
|
||||
id = themeId,
|
||||
name = name ?? "Test Theme",
|
||||
description = description ?? "A theme used for testing.",
|
||||
author = author ?? "Lumina Tests",
|
||||
version = version ?? "1.0.0",
|
||||
preview,
|
||||
templates = templates ?? new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
["default"] = "templates/default.html"
|
||||
}
|
||||
};
|
||||
|
||||
return JsonSerializer.Serialize(manifest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a ZIP archive from the provided entries, allowing tests to build arbitrary valid and invalid theme packs.
|
||||
/// </summary>
|
||||
/// <param name="entries">The entries to write into the archive.</param>
|
||||
/// <returns>The created ZIP archive bytes.</returns>
|
||||
public byte[] CreateArchive(params ThemeArchiveEntry[] entries)
|
||||
{
|
||||
using MemoryStream output = new();
|
||||
using (ZipArchive archive = new(output, ZipArchiveMode.Create, leaveOpen: true))
|
||||
{
|
||||
foreach (ThemeArchiveEntry entry in entries)
|
||||
{
|
||||
ZipArchiveEntry zipEntry = archive.CreateEntry(entry.Path);
|
||||
if (entry.UnixFileType is not null)
|
||||
zipEntry.ExternalAttributes = (entry.UnixFileType.Value << 16) | 0x81A4;
|
||||
|
||||
using StreamWriter writer = new(zipEntry.Open());
|
||||
writer.Write(entry.Content);
|
||||
}
|
||||
}
|
||||
|
||||
return output.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple valid theme pack ZIP archives with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of archives to create.</param>
|
||||
/// <returns>List of configured theme pack ZIP archives.</returns>
|
||||
public List<byte[]> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(index => Create(themeId: $"test-theme-{index}"))];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user