feat: implement static key provider

This commit is contained in:
Stevan Freeborn
2026-04-01 12:45:57 -05:00
parent 25d13bb24b
commit f69317efe5
2 changed files with 76 additions and 0 deletions
@@ -0,0 +1,39 @@
using StevanFreeborn.Extensions.Configuration.Secure.Cryptography;
namespace StevanFreeborn.Extensions.Configuration.Secure.Tests.Unit.Cryptography;
public class StaticKeyProviderTests
{
[Fact]
public void Constructor_ShouldThrowArgumentNullException_WhenKeyIsNull()
{
var act = () => new StaticKeyProvider(null!);
act.Should().Throw<ArgumentNullException>();
}
[Fact]
public void Constructor_WhenCalledAndKeyIsNot32Bytes_ItShouldThrowArgumentException()
{
var shortKey = Convert.ToBase64String(new byte[16]);
var act = () => new StaticKeyProvider(shortKey);
act.Should().Throw<ArgumentException>().WithMessage("*must be exactly 32 bytes*");
}
[Fact]
public void GetKey_WhenCalled_ItShouldReturnValid32ByteArray()
{
var expectedBytes = new byte[32];
Random.Shared.NextBytes(expectedBytes);
var base64Key = Convert.ToBase64String(expectedBytes);
var provider = new StaticKeyProvider(base64Key);
var result = provider.GetKey();
result.Should().BeEquivalentTo(expectedBytes);
result.Length.Should().Be(32);
}
}