WIP making ClientCreate endpoint
This commit is contained in:
parent
138f335af0
commit
eb872a4f44
28 changed files with 365 additions and 121 deletions
|
|
@ -122,17 +122,16 @@ public class RealmApisTests : IClassFixture<ApplicationFactory>
|
|||
|
||||
using var rsa = RSA.Create(2048);
|
||||
RSAParameters parameters = rsa.ExportParameters(includePrivateParameters: false);
|
||||
|
||||
Key key = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
};
|
||||
key.SetPrivateKey(encryptionService, rsa.ExportPkcs8PrivateKey());
|
||||
|
||||
RealmKey realmKey = new(
|
||||
Guid.NewGuid(),
|
||||
"RSA",
|
||||
encryptionService.Encrypt(rsa.ExportPkcs8PrivateKey()),
|
||||
DateTime.UtcNow);
|
||||
|
||||
await ScopedContextAsync(async db =>
|
||||
{
|
||||
db.Realms.Add(new Realm() { Slug = "foo", Name = "Foo", Keys = [ key ]});
|
||||
db.Realms.Add(new Realm() { Slug = "foo", Name = "Foo", Keys = [ realmKey ]});
|
||||
await db.SaveChangesAsync(TestContext.Current.CancellationToken);
|
||||
});
|
||||
|
||||
|
|
@ -145,7 +144,7 @@ public class RealmApisTests : IClassFixture<ApplicationFactory>
|
|||
JsonObject? payload = await response.Content.ReadFromJsonAsync<JsonObject>(TestContext.Current.CancellationToken);
|
||||
|
||||
Assert.NotNull(payload);
|
||||
JsonObjectAssert.Equal(key.Id.ToString(), payload, "keys[0].kid");
|
||||
JsonObjectAssert.Equal(realmKey.Id.ToString(), payload, "keys[0].kid");
|
||||
JsonObjectAssert.Equal(WebEncoders.Base64UrlEncode(parameters.Modulus!), payload, "keys[0].n");
|
||||
JsonObjectAssert.Equal(WebEncoders.Base64UrlEncode(parameters.Exponent!), payload, "keys[0].e");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,20 +20,20 @@ public class KeyMapperTests
|
|||
|
||||
RSAParameters parameters = rsa.ExportParameters(includePrivateParameters: false);
|
||||
|
||||
Key key = new()
|
||||
RealmKey realmKey = new()
|
||||
{
|
||||
Id = new("60bb79cf-4bac-4521-87f2-ac87cc15541f"),
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
Priority = 10,
|
||||
};
|
||||
key.SetPrivateKey(_encryptionService, rsa.ExportPkcs8PrivateKey());
|
||||
realmKey.SetPrivateKey(_encryptionService, rsa.ExportPkcs8PrivateKey());
|
||||
|
||||
// Act
|
||||
KeyMapper mapper = new(_encryptionService);
|
||||
JsonWebKey jwk = mapper.KeyToJsonWebKey(key);
|
||||
JsonWebKey jwk = mapper.KeyToJsonWebKey(realmKey);
|
||||
|
||||
Assert.Equal("RSA", jwk.KeyType);
|
||||
Assert.Equal(key.Id.ToString(), jwk.KeyId);
|
||||
Assert.Equal(realmKey.Id.ToString(), jwk.KeyId);
|
||||
Assert.Equal("sig", jwk.Use);
|
||||
Assert.Equal(parameters.Exponent, WebEncoders.Base64UrlDecode(jwk.Exponent));
|
||||
Assert.Equal(parameters.Modulus, WebEncoders.Base64UrlDecode(jwk.Modulus));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue