Add tests and fixes to .well-known/openid-configuration and create realm
This commit is contained in:
parent
e07d6e3ea5
commit
d440979451
17 changed files with 642 additions and 45 deletions
|
|
@ -1,65 +0,0 @@
|
|||
using FluentResults;
|
||||
|
||||
namespace IdentityShroud.Core.Tests;
|
||||
|
||||
public static class ResultAssert
|
||||
{
|
||||
public static void Success(Result result)
|
||||
{
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
var errors = string.Join("\n", result.Errors.Select(e => "\t" + e.Message));
|
||||
Assert.True(result.IsSuccess, $"ResultAssert.Success: failed, got errors:\n{errors}");
|
||||
}
|
||||
}
|
||||
|
||||
public static T Success<T>(Result<T> result)
|
||||
{
|
||||
Success(result.ToResult());
|
||||
return result.Value;
|
||||
}
|
||||
|
||||
public static void Failed(Result result, Predicate<IError>? filter = null)
|
||||
{
|
||||
if (!result.IsFailed)
|
||||
{
|
||||
Assert.Fail("ResultAssert.Failed: failed, unexpected success result");
|
||||
}
|
||||
|
||||
if (filter is not null)
|
||||
Assert.Contains(result.Errors, filter);
|
||||
}
|
||||
|
||||
public static void Failed<T>(Result<T> result, Predicate<IError>? filter = null)
|
||||
{
|
||||
Failed(result.ToResult(), filter);
|
||||
}
|
||||
|
||||
public static void FailedWith<TError>(Result result) where TError : IError
|
||||
{
|
||||
if (!result.IsFailed)
|
||||
{
|
||||
Assert.Fail("ResultAssert.Failed: failed, unexpected success result");
|
||||
}
|
||||
|
||||
if (!result.Errors.Any(e => e is TError))
|
||||
{
|
||||
string typeName = typeof(TError).Name;
|
||||
Assert.Fail($"ResultAssert.Failed: failed, no error of the type {typeName} found");
|
||||
}
|
||||
}
|
||||
|
||||
public static void FailedWith<T, TError>(Result<T> result) where TError : IError
|
||||
{
|
||||
if (!result.IsFailed)
|
||||
{
|
||||
Assert.Fail("ResultAssert.Failed: failed, unexpected success result");
|
||||
}
|
||||
|
||||
if (!result.Errors.Any(e => e is TError))
|
||||
{
|
||||
string typeName = typeof(TError).Name;
|
||||
Assert.Fail($"ResultAssert.Failed: failed, no error of the type {typeName} found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\IdentityShroud.Core\IdentityShroud.Core.csproj" />
|
||||
<ProjectReference Include="..\IdentityShroud.TestUtils\IdentityShroud.TestUtils.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -3,7 +3,7 @@ using IdentityShroud.Core.Model;
|
|||
|
||||
namespace IdentityShroud.Core.Tests.Model;
|
||||
|
||||
public class RealmTests
|
||||
public class KeyTests
|
||||
{
|
||||
[Fact]
|
||||
public void SetNewKey()
|
||||
|
|
@ -16,12 +16,12 @@ public class RealmTests
|
|||
.Encrypt(Arg.Any<byte[]>())
|
||||
.Returns(x => encryptedPrivateKey);
|
||||
|
||||
Realm realm = new();
|
||||
realm.SetPrivateKey(encryptionService, privateKey);
|
||||
Key key = new();
|
||||
key.SetPrivateKey(encryptionService, privateKey);
|
||||
|
||||
// should be able to return original without calling decrypt
|
||||
Assert.Equal(privateKey, realm.GetPrivateKey(encryptionService));
|
||||
Assert.Equal(encryptedPrivateKey, realm.PrivateKeyEncrypted);
|
||||
Assert.Equal(privateKey, key.GetPrivateKey(encryptionService));
|
||||
Assert.Equal(encryptedPrivateKey, key.PrivateKeyEncrypted);
|
||||
|
||||
encryptionService.Received(1).Encrypt(privateKey);
|
||||
encryptionService.DidNotReceive().Decrypt(Arg.Any<byte[]>());
|
||||
|
|
@ -38,12 +38,12 @@ public class RealmTests
|
|||
.Decrypt(encryptedPrivateKey)
|
||||
.Returns(x => privateKey);
|
||||
|
||||
Realm realm = new();
|
||||
realm.PrivateKeyEncrypted = encryptedPrivateKey;
|
||||
Key key = new();
|
||||
key.PrivateKeyEncrypted = encryptedPrivateKey;
|
||||
|
||||
// should be able to return original without calling decrypt
|
||||
Assert.Equal(privateKey, realm.GetPrivateKey(encryptionService));
|
||||
Assert.Equal(encryptedPrivateKey, realm.PrivateKeyEncrypted);
|
||||
Assert.Equal(privateKey, key.GetPrivateKey(encryptionService));
|
||||
Assert.Equal(encryptedPrivateKey, key.PrivateKeyEncrypted);
|
||||
|
||||
encryptionService.Received(1).Decrypt(encryptedPrivateKey);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue