feat(AuthClientTests): Added GetpublicKey_ShouldReturnExpectedPublicKey to test GetPublicKeyAsync method of AuthHub
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using DigitalData.Auth.Abstractions;
|
using DigitalData.Auth.Abstractions;
|
||||||
using DigitalData.Auth.API.Hubs;
|
using DigitalData.Auth.API.Hubs;
|
||||||
using DigitalData.Auth.Client;
|
using DigitalData.Auth.Client;
|
||||||
|
using DigitalData.Core.Abstractions.Security;
|
||||||
using DigitalData.Core.Security;
|
using DigitalData.Core.Security;
|
||||||
using DigitalData.Core.Security.Config;
|
using DigitalData.Core.Security.Config;
|
||||||
using DigitalData.Core.Security.RSAKey;
|
using DigitalData.Core.Security.RSAKey;
|
||||||
@@ -34,6 +35,17 @@ public class AuthClientTests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private readonly IEnumerable<RSATokenDescriptor> _tokenDescriptors =
|
||||||
|
[
|
||||||
|
new()
|
||||||
|
{
|
||||||
|
Issuer = "Foo",
|
||||||
|
Audience = "Bar",
|
||||||
|
Lifetime = new TimeSpan(1, 0, 0),
|
||||||
|
Content = Instance.RSAFactory.CreatePrivateKeyPem()
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
@@ -55,7 +67,8 @@ public class AuthClientTests
|
|||||||
builder.Services.AddCryptoFactory(new CryptoFactoryParams()
|
builder.Services.AddCryptoFactory(new CryptoFactoryParams()
|
||||||
{
|
{
|
||||||
PemDirectory = "/",
|
PemDirectory = "/",
|
||||||
Decryptors = [new RSADecryptor()]
|
Decryptors = [new RSADecryptor()],
|
||||||
|
TokenDescriptors = _tokenDescriptors
|
||||||
});
|
});
|
||||||
builder.Services.AddMemoryCache();
|
builder.Services.AddMemoryCache();
|
||||||
|
|
||||||
@@ -149,4 +162,32 @@ public class AuthClientTests
|
|||||||
Assert.That(rcv_key, Is.EqualTo(key));
|
Assert.That(rcv_key, Is.EqualTo(key));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task GetpublicKey_ShouldReturnExpectedPublicKey()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
string? publicKey = null;
|
||||||
|
var provider = Build(opt =>
|
||||||
|
{
|
||||||
|
opt.Url = _hubUrl;
|
||||||
|
opt.Events.OnMessageReceived = (issuer, audience, key, logger) => publicKey = key;
|
||||||
|
});
|
||||||
|
var client = provider.GetRequiredService<IAuthClient>();
|
||||||
|
await client.StartAsync();
|
||||||
|
var expectedPublicKey = _tokenDescriptors.Get("Foo", "Bar").PublicKey.Content;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await client.GetPublicKeyAsync("Foo", "Bar");
|
||||||
|
|
||||||
|
// wait for network
|
||||||
|
await Task.Delay(2000);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(publicKey, Is.Not.Null);
|
||||||
|
Assert.That(publicKey, Is.EqualTo(expectedPublicKey));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user