Suspension reason moves to an admin-read column on the membership; the receipt holds no reason
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c1c057b43c
commit
71ba999f9d
11 changed files with 168 additions and 11 deletions
|
|
@ -359,6 +359,11 @@ public sealed class OidcLogoutFactory : OidcWebApplicationFactory
|
|||
|
||||
public FakeMasHandler Mas { get; } = new();
|
||||
|
||||
/// <summary>The raw token response and access token of the last <see cref="GrantAsync"/>.</summary>
|
||||
public string LastTokenResponse { get; private set; } = string.Empty;
|
||||
|
||||
public string LastAccessToken { get; private set; } = string.Empty;
|
||||
|
||||
public ManualClock Time { get; } = new();
|
||||
|
||||
public OidcLogoutReconciler Reconciler => Services.GetServices<IHostedService>().OfType<OidcLogoutReconciler>().Single();
|
||||
|
|
@ -399,7 +404,7 @@ public sealed class OidcLogoutFactory : OidcWebApplicationFactory
|
|||
};
|
||||
|
||||
/// <summary>Registers a member, sets <paramref name="status"/>, and completes one authorization-code flow for them.</summary>
|
||||
public async Task<(string Identity, string IdToken)> GrantAsync(MembershipStatus status = MembershipStatus.Active)
|
||||
public async Task<(string Identity, string IdToken)> GrantAsync(MembershipStatus status = MembershipStatus.Active, string? suspensionReason = null)
|
||||
{
|
||||
using var client = CreateClient(HostClientOptions());
|
||||
var identity = $"member-{Guid.NewGuid():N}";
|
||||
|
|
@ -409,6 +414,14 @@ public sealed class OidcLogoutFactory : OidcWebApplicationFactory
|
|||
}
|
||||
|
||||
await SetMembershipAsync(identity, MembershipStatus.Active);
|
||||
if (suspensionReason is not null)
|
||||
{
|
||||
using var scope = Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<BifrostDbContext>();
|
||||
var account = db.UserAccounts.Single(x => x.NormalizedBifrostIdentity == identity);
|
||||
db.Memberships.Single(x => x.UserAccountId == account.Id).SuspensionReason = suspensionReason;
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
var verifier = Base64UrlEncoder.Encode(RandomNumberGenerator.GetBytes(48));
|
||||
var state = Base64UrlEncoder.Encode(RandomNumberGenerator.GetBytes(24));
|
||||
|
|
@ -444,7 +457,10 @@ public sealed class OidcLogoutFactory : OidcWebApplicationFactory
|
|||
"Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes($"{OidcTestKit.ClientId}:{Kit.ClientSecret}")));
|
||||
using var tokens = await bare.SendAsync(exchange);
|
||||
Assert.Equal(HttpStatusCode.OK, tokens.StatusCode);
|
||||
var idToken = (await tokens.Content.ReadFromJsonAsync<JsonElement>()).GetProperty("id_token").GetString()!;
|
||||
var body = await tokens.Content.ReadFromJsonAsync<JsonElement>();
|
||||
var idToken = body.GetProperty("id_token").GetString()!;
|
||||
LastTokenResponse = body.GetRawText();
|
||||
LastAccessToken = body.GetProperty("access_token").GetString()!;
|
||||
|
||||
if (status != MembershipStatus.Active)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue