Implement jwks endpoint and add test for it.
This also let to some improvements/cleanups of the other tests and fixtures.
This commit is contained in:
parent
a80c133e2a
commit
ccb06b260c
24 changed files with 353 additions and 107 deletions
|
|
@ -8,23 +8,13 @@ namespace IdentityShroud.Core.Tests.Fixtures;
|
|||
|
||||
public class DbFixture : IAsyncLifetime
|
||||
{
|
||||
private readonly IContainer _postgresqlServer;
|
||||
|
||||
private string ConnectionString =>
|
||||
$"Host={_postgresqlServer.Hostname};" +
|
||||
$"Port={DbPort};" +
|
||||
$"Username={Username};Password={Password}";
|
||||
|
||||
private string Username => "postgres";
|
||||
private string Password => "password";
|
||||
private string DbHostname => _postgresqlServer.Hostname;
|
||||
private int DbPort => _postgresqlServer.GetMappedPublicPort(PostgreSqlBuilder.PostgreSqlPort);
|
||||
private readonly PostgreSqlContainer _postgresqlServer;
|
||||
|
||||
public Db CreateDbContext(string dbName = "testdb")
|
||||
{
|
||||
var db = new Db(Options.Create<DbConfiguration>(new()
|
||||
{
|
||||
ConnectionString = ConnectionString + ";Database=" + dbName,
|
||||
ConnectionString = _postgresqlServer.GetConnectionString(),
|
||||
LogSensitiveData = false,
|
||||
}), new NullLoggerFactory());
|
||||
return db;
|
||||
|
|
@ -33,8 +23,7 @@ public class DbFixture : IAsyncLifetime
|
|||
public DbFixture()
|
||||
{
|
||||
_postgresqlServer = new PostgreSqlBuilder("postgres:18.1")
|
||||
.WithName("KMS-Test-Infra-" + Guid.NewGuid().ToString("D"))
|
||||
.WithPassword(Password)
|
||||
.WithName("is-dbfixture-" + Guid.NewGuid().ToString("D"))
|
||||
.Build();
|
||||
}
|
||||
|
||||
|
|
@ -50,7 +39,7 @@ public class DbFixture : IAsyncLifetime
|
|||
|
||||
public NpgsqlConnection GetConnection(string dbname)
|
||||
{
|
||||
string connString = ConnectionString
|
||||
string connString = _postgresqlServer.GetConnectionString()
|
||||
+ $";Database={dbname}";
|
||||
var connection = new NpgsqlConnection(connString);
|
||||
connection.Open();
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\IdentityShroud.Api\IdentityShroud.Api.csproj" />
|
||||
<ProjectReference Include="..\IdentityShroud.Core\IdentityShroud.Core.csproj" />
|
||||
<ProjectReference Include="..\IdentityShroud.TestUtils\IdentityShroud.TestUtils.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
using FluentResults;
|
||||
using IdentityShroud.Core.Contracts;
|
||||
using IdentityShroud.Core.Services;
|
||||
using IdentityShroud.Core.Tests.Fixtures;
|
||||
using IdentityShroud.Core.Tests.Substitutes;
|
||||
using IdentityShroud.TestUtils.Substitutes;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace IdentityShroud.Core.Tests.Services;
|
||||
|
|
|
|||
|
|
@ -1,18 +0,0 @@
|
|||
using IdentityShroud.Core.Contracts;
|
||||
|
||||
namespace IdentityShroud.Core.Tests.Substitutes;
|
||||
|
||||
public static class EncryptionServiceSubstitute
|
||||
{
|
||||
public static IEncryptionService CreatePassthrough()
|
||||
{
|
||||
var encryptionService = Substitute.For<IEncryptionService>();
|
||||
encryptionService
|
||||
.Encrypt(Arg.Any<byte[]>())
|
||||
.Returns(x => x.ArgAt<byte[]>(0));
|
||||
encryptionService
|
||||
.Decrypt(Arg.Any<byte[]>())
|
||||
.Returns(x => x.ArgAt<byte[]>(0));
|
||||
return encryptionService;
|
||||
}
|
||||
}
|
||||
|
|
@ -95,14 +95,5 @@ public static class RsaKeyLoader
|
|||
string pemContent = System.IO.File.ReadAllText(filePath);
|
||||
return LoadFromPem(pemContent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load RSA private key from PKCS#8 format
|
||||
/// </summary>
|
||||
public static RSA LoadFromPkcs8(byte[] pkcs8Key)
|
||||
{
|
||||
var rsa = RSA.Create();
|
||||
rsa.ImportPkcs8PrivateKey(pkcs8Key, out _);
|
||||
return rsa;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue