Adds 2 units and docs for unit 3. nfr-requirements plan
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
using FluentAssertions;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using SlpModularCms.Modules.Availability.Services;
|
||||
|
||||
namespace SlpModularCms.Modules.Availability.Tests.Services;
|
||||
|
||||
public class MasterApiKeyProtectorTests
|
||||
{
|
||||
private static MasterApiKeyProtector CreateProtector()
|
||||
{
|
||||
var provider = new EphemeralDataProtectionProvider();
|
||||
return new MasterApiKeyProtector(provider);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Protect_Unprotect_RoundTrip_ReturnsOriginalValue()
|
||||
{
|
||||
var protector = CreateProtector();
|
||||
var plain = "my-secret-api-key";
|
||||
|
||||
var encrypted = protector.Protect(plain);
|
||||
var decrypted = protector.Unprotect(encrypted);
|
||||
|
||||
decrypted.Should().Be(plain);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Protect_ReturnsNonEmptyString_DifferentFromInput()
|
||||
{
|
||||
var protector = CreateProtector();
|
||||
var plain = "my-secret-api-key";
|
||||
|
||||
var encrypted = protector.Protect(plain);
|
||||
|
||||
encrypted.Should().NotBeNullOrEmpty();
|
||||
encrypted.Should().NotBe(plain);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Unprotect_ReturnsNull_WhenGivenInvalidCiphertext()
|
||||
{
|
||||
var protector = CreateProtector();
|
||||
|
||||
var result = protector.Unprotect("this-is-not-valid-ciphertext");
|
||||
|
||||
result.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Unprotect_ReturnsNull_WhenProtectedWithDifferentProvider()
|
||||
{
|
||||
var protector1 = CreateProtector();
|
||||
var protector2 = CreateProtector();
|
||||
var encrypted = protector1.Protect("key");
|
||||
|
||||
var result = protector2.Unprotect(encrypted);
|
||||
|
||||
result.Should().BeNull();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user