Still working on getting client credential flow complete, most of the request works but still working on generating the JWT.
This commit is contained in:
parent
1a8c63808a
commit
8782ef39c6
80 changed files with 1331 additions and 414 deletions
|
|
@ -1,10 +1,13 @@
|
|||
using FluentResults;
|
||||
using IdentityShroud.Core.Contracts;
|
||||
using IdentityShroud.Core.EFCore;
|
||||
using IdentityShroud.Core.Model;
|
||||
using IdentityShroud.Core.Security;
|
||||
using IdentityShroud.Core.Security.Keys;
|
||||
using IdentityShroud.Core.Services;
|
||||
using IdentityShroud.Core.Tests.Fixtures;
|
||||
using IdentityShroud.TestUtils.Substitutes;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Shouldly;
|
||||
|
||||
namespace IdentityShroud.Core.Tests.Services;
|
||||
|
||||
|
|
@ -12,6 +15,7 @@ public class RealmServiceTests : IClassFixture<DbFixture>
|
|||
{
|
||||
private readonly DbFixture _dbFixture;
|
||||
private readonly IKeyService _keyService = Substitute.For<IKeyService>();
|
||||
private readonly IDekEncryptionService _dekCryptor = new NullDekEncryptionService();
|
||||
|
||||
public RealmServiceTests(DbFixture dbFixture)
|
||||
{
|
||||
|
|
@ -25,6 +29,9 @@ public class RealmServiceTests : IClassFixture<DbFixture>
|
|||
{
|
||||
db.Database.ExecuteSqlRaw("TRUNCATE realm CASCADE;");
|
||||
}
|
||||
|
||||
private RealmService CreateSut(Db db) => new(db, _keyService, _dekCryptor, new ClockService());
|
||||
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
|
|
@ -36,20 +43,14 @@ public class RealmServiceTests : IClassFixture<DbFixture>
|
|||
if (idString is not null)
|
||||
realmId = new(idString);
|
||||
|
||||
RealmCreateResponse? val;
|
||||
Realm? val;
|
||||
await using (var db = _dbFixture.CreateDbContext())
|
||||
{
|
||||
_keyService.CreateKey(Arg.Any<KeyPolicy>())
|
||||
.Returns(new RealmKey()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
KeyType = "TST",
|
||||
Key = new(KekId.NewId(), [21]),
|
||||
CreatedAt = DateTime.UtcNow
|
||||
});
|
||||
.Returns(new CreateKeyResponse(KeyType.AES, new KeyData([21])));
|
||||
// Act
|
||||
RealmService sut = new(db, _keyService);
|
||||
var response = await sut.Create(
|
||||
RealmService sut = CreateSut(db);
|
||||
Result<Realm> response = await sut.Create(
|
||||
new(realmId, "slug", "New realm"),
|
||||
TestContext.Current.CancellationToken);
|
||||
|
||||
|
|
@ -60,8 +61,12 @@ public class RealmServiceTests : IClassFixture<DbFixture>
|
|||
else
|
||||
Assert.NotEqual(Guid.Empty, val.Id);
|
||||
|
||||
Assert.Equal("slug", val.Slug);
|
||||
Assert.Equal("New realm", val.Name);
|
||||
Assert.Multiple(
|
||||
() => val.Slug.ShouldBe("slug"),
|
||||
() => val.Name.ShouldBe("New realm"),
|
||||
() => val.DataEncryptionKeys.ShouldContain(d => d.Active),
|
||||
() => val.TokenSigningKeys.ShouldContain(d => !d.RevokedAt.HasValue)
|
||||
);
|
||||
|
||||
_keyService.Received().CreateKey(Arg.Any<KeyPolicy>());
|
||||
}
|
||||
|
|
@ -69,9 +74,9 @@ public class RealmServiceTests : IClassFixture<DbFixture>
|
|||
await using (var db = _dbFixture.CreateDbContext())
|
||||
{
|
||||
var dbRecord = await db.Realms
|
||||
.Include(e => e.Keys)
|
||||
.Include(e => e.TokenSigningKeys)
|
||||
.SingleAsync(e => e.Id == val.Id, TestContext.Current.CancellationToken);
|
||||
Assert.Equal("TST", dbRecord.Keys[0].KeyType);
|
||||
Assert.Equal(KeyType.AES, dbRecord.TokenSigningKeys[0].KeyType);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -98,7 +103,7 @@ public class RealmServiceTests : IClassFixture<DbFixture>
|
|||
|
||||
await using var actContext = _dbFixture.CreateDbContext();
|
||||
// Act
|
||||
RealmService sut = new(actContext, _keyService);
|
||||
RealmService sut = CreateSut(actContext);
|
||||
var result = await sut.FindBySlug(slug, TestContext.Current.CancellationToken);
|
||||
|
||||
// Verify
|
||||
|
|
@ -131,7 +136,7 @@ public class RealmServiceTests : IClassFixture<DbFixture>
|
|||
|
||||
await using var actContext = _dbFixture.CreateDbContext();
|
||||
// Act
|
||||
RealmService sut = new(actContext, _keyService);
|
||||
RealmService sut = CreateSut(actContext);
|
||||
Realm? result = await sut.FindById(id, TestContext.Current.CancellationToken);
|
||||
|
||||
// Verify
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue