Happy flow for creating realms works
But needs more validating...
This commit is contained in:
parent
f99c97f392
commit
92b34bd0b5
25 changed files with 437 additions and 12 deletions
22
IdentityShroud.Core.Tests/Services/EncryptionServiceTests.cs
Normal file
22
IdentityShroud.Core.Tests/Services/EncryptionServiceTests.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using System.Security.Cryptography;
|
||||
using IdentityShroud.Core.Services;
|
||||
|
||||
namespace IdentityShroud.Core.Tests.Services;
|
||||
|
||||
public class EncryptionServiceTests
|
||||
{
|
||||
[Fact]
|
||||
public void RoundtripWorks()
|
||||
{
|
||||
// setup
|
||||
string key = Convert.ToBase64String(RandomNumberGenerator.GetBytes(32));
|
||||
EncryptionService sut = new(key);
|
||||
byte[] input = RandomNumberGenerator.GetBytes(16);
|
||||
|
||||
// act
|
||||
var cipher = sut.Encrypt(input);
|
||||
var result = sut.Decrypt(cipher);
|
||||
|
||||
Assert.Equal(input, result);
|
||||
}
|
||||
}
|
||||
52
IdentityShroud.Core.Tests/Services/RealmServiceTests.cs
Normal file
52
IdentityShroud.Core.Tests/Services/RealmServiceTests.cs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
using FluentResults;
|
||||
using IdentityShroud.Core.Services;
|
||||
using IdentityShroud.Core.Tests.Fixtures;
|
||||
using IdentityShroud.Core.Tests.Substitutes;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace IdentityShroud.Core.Tests.Services;
|
||||
|
||||
public class RealmServiceTests : IClassFixture<DbFixture>
|
||||
{
|
||||
private readonly Db _db;
|
||||
|
||||
public RealmServiceTests(DbFixture dbFixture)
|
||||
{
|
||||
_db = dbFixture.CreateDbContext("realmservice");
|
||||
|
||||
if (!_db.Database.EnsureCreated())
|
||||
TruncateTables();
|
||||
}
|
||||
|
||||
private void TruncateTables()
|
||||
{
|
||||
_db.Database.ExecuteSqlRaw("TRUNCATE realm CASCADE;");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("a7c2a39c-3ed9-4790-826e-43bb2e5e480c")]
|
||||
public async Task Create(string? idString)
|
||||
{
|
||||
Guid? realmId = null;
|
||||
if (idString is not null)
|
||||
realmId = new(idString);
|
||||
|
||||
var encryptionService = EncryptionServiceSubstitute.CreatePassthrough();
|
||||
RealmService sut = new(_db, encryptionService);
|
||||
|
||||
var response = await sut.Create(
|
||||
new(realmId, "slug", "New realm"),
|
||||
TestContext.Current.CancellationToken);
|
||||
|
||||
RealmCreateResponse val = ResultAssert.Success(response);
|
||||
if (realmId.HasValue)
|
||||
Assert.Equal(realmId, val.Realm.Id);
|
||||
else
|
||||
Assert.NotEqual(Guid.Empty, val.Realm.Id);
|
||||
|
||||
Assert.Equal("slug", val.Realm.Slug);
|
||||
Assert.Equal("New realm", val.Realm.Name);
|
||||
Assert.NotEmpty(val.Realm.PrivateKeyEncrypted);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue