mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 21:01:10 +00:00
50 lines
1.7 KiB
C#
50 lines
1.7 KiB
C#
#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();
|
|
}
|
|
}
|