## What & why S-15a, the first of the S-15 (#16) split. A new **beheer** portal (medewerker realm, like behandel) shows the ZTC catalogus — the published zaaktypen — **read-only**. A beheerder logs in and sees the seeded BIG-REGISTRATIE zaaktype. Closes #130 ### The vertical portal → BFF `GET /beheer/catalogi/zaaktypen` (medewerker realm + `beheerder` role) → ACL `GET /catalogi/zaaktypen` → ZGW Catalogi API. - **ACL**: new read-only `GET /catalogi/zaaktypen` listing published zaaktypen (reuses the ADR-0021 Catalogi client; public-safe `identificatie`/`omschrijving`). - **BFF**: new typed `IAclClient` + `Downstream:Acl:BaseUrl`, and `GET /beheer/catalogi/zaaktypen` behind a new `beheerder` policy (reuses the medewerker bearer scheme + realm-role lifting). OpenAPI spec + generated Angular client regenerated. - **Keycloak**: `beheerder` realm role + `bram-beheerder` test user in the medewerker realm. - **Frontend**: new `apps/beheer` Angular app (copied from behandel) with a read-only catalogus page; `SECURE_API_ROUTES=['/beheer/']`. - **Infra**: `beheer` compose service (port 8143), added to `WAIT_SVCS` + CI log-dump; a Playwright e2e (beheerder login → catalogus shows BIG-REGISTRATIE). ### New boundary → ADR-0025 The BFF now reaches the **ACL directly** for the catalogus read — a new service-to-service edge (§14). The catalogus is neither a domain nor a projection concern, and §8.1 means only the ACL may read ZGW; routing through the domain would pollute it with a non-domain passthrough. §8.1/§8.3 stay intact. Recorded in **ADR-0025**. ## Definition of Done - [x] Failing test committed before each implementation (red→green per layer: ACL, BFF, frontend). - [x] Conventional Commits referencing #130. - [ ] CI green — pending Gitea Actions run. - [x] `docker compose up` brings up `beheer` (health-gated in `WAIT_SVCS`). - [x] Docs — ADR-0025 + demo-script S-15a note. - [x] Demo note in `docs/demo-script.md`. ## Verified locally lint (`dotnet format`) ✓ · .NET unit (Acl 57 / Big 152 / EventSubscriber 19 / Bff 40) ✓ · frontend lint+test (8 projects) ✓ · frontend build (4 apps) ✓. Mutation ratchet: added a gateway unit test for the new `ListZaaktypenAsync` mapping so the ACL score holds. verify-stack (compose smoke + e2e) runs in CI. ## Notes for reviewers - The BFF drops the ZGW URL from `BeheerZaaktype` (public-safe: identificatie + omschrijving only). - The catalogus e2e asserts on the stable seeded `BIG-REGISTRATIE` (not a per-test reference), safe on the shared verify stack. - Follow-ups: **S-15b** (#131) default-fill CRUD, **S-15c** (#132) medewerker-realm MFA. 🤖 Generated with [Claude Code](https://claude.com/claude-code)Reviewed-on: #133
153 lines
6.9 KiB
C#
153 lines
6.9 KiB
C#
using System.Text;
|
|
using Bff.Api;
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Mvc.Testing;
|
|
using Microsoft.AspNetCore.TestHost;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.IdentityModel.Protocols;
|
|
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
|
using Microsoft.IdentityModel.Tokens;
|
|
|
|
namespace Bff.Tests;
|
|
|
|
/// <summary>
|
|
/// Test host for the BFF. It swaps the downstream clients for in-memory fakes and reconfigures the
|
|
/// JWT bearer to validate against a local test key (no live Keycloak) — so token validation is
|
|
/// exercised in-process with tokens the tests mint (ADR-0010).
|
|
/// </summary>
|
|
internal sealed class BffFactory : WebApplicationFactory<Program>
|
|
{
|
|
public static readonly SymmetricSecurityKey TestSigningKey =
|
|
new(Encoding.UTF8.GetBytes("bff-test-signing-key-that-is-at-least-256-bits-long!"));
|
|
|
|
public FakeDomainClient Domain { get; } = new();
|
|
public FakeProjectionClient Projection { get; } = new();
|
|
public FakeAclClient Acl { get; } = new();
|
|
|
|
private static void ValidateWithTestKey(IServiceCollection services, string scheme) =>
|
|
services.Configure<JwtBearerOptions>(scheme, options =>
|
|
{
|
|
// Validate locally against the test key and NEVER reach out for OIDC metadata. A static
|
|
// configuration manager guarantees this regardless of Configure/PostConfigure ordering —
|
|
// clearing Authority alone left the medewerker scheme fetching metadata under CI timing
|
|
// (2s hang → 401), because JwtBearer's PostConfigure could still build a ConfigurationManager.
|
|
options.Authority = null;
|
|
options.MetadataAddress = null!;
|
|
options.RequireHttpsMetadata = false;
|
|
options.Configuration = new OpenIdConnectConfiguration();
|
|
options.ConfigurationManager =
|
|
new StaticConfigurationManager<OpenIdConnectConfiguration>(new OpenIdConnectConfiguration());
|
|
options.TokenValidationParameters = new TokenValidationParameters
|
|
{
|
|
ValidateIssuer = false,
|
|
ValidateAudience = false,
|
|
ValidateLifetime = true,
|
|
ValidateIssuerSigningKey = true,
|
|
IssuerSigningKey = TestSigningKey,
|
|
ClockSkew = TimeSpan.Zero,
|
|
};
|
|
});
|
|
|
|
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
|
{
|
|
builder.UseSetting("Keycloak:Authority", "https://keycloak.invalid/realms/digid");
|
|
builder.UseSetting("Keycloak:MedewerkerAuthority", "https://keycloak.invalid/realms/medewerker");
|
|
builder.UseSetting("Downstream:Domain:BaseUrl", "http://domain.invalid/");
|
|
builder.UseSetting("Downstream:Projection:BaseUrl", "http://projection.invalid/");
|
|
builder.UseSetting("Downstream:Acl:BaseUrl", "http://acl.invalid/");
|
|
|
|
builder.ConfigureTestServices(services =>
|
|
{
|
|
services.AddSingleton<IDomainClient>(Domain);
|
|
services.AddSingleton<IProjectionClient>(Projection);
|
|
services.AddSingleton<IAclClient>(Acl);
|
|
|
|
// Both realms validate locally against the test key (no live Keycloak). The medewerker
|
|
// scheme keeps its OnTokenValidated role-lifting from Program.cs — only the validation
|
|
// parameters are swapped here.
|
|
ValidateWithTestKey(services, JwtBearerDefaults.AuthenticationScheme);
|
|
ValidateWithTestKey(services, "medewerker");
|
|
});
|
|
}
|
|
}
|
|
|
|
/// <summary>Captures the bsn the BFF forwarded and returns a canned acceptance.</summary>
|
|
internal sealed class FakeDomainClient : IDomainClient
|
|
{
|
|
public string? SubmittedBsn { get; private set; }
|
|
public SubmitAccepted Result { get; set; } = new("reg-123", "Ingediend");
|
|
public List<WerkbakItem> Werkbak { get; } = [];
|
|
|
|
public Task<SubmitAccepted> SubmitRegistrationAsync(string bsn, CancellationToken ct = default)
|
|
{
|
|
SubmittedBsn = bsn;
|
|
return Task.FromResult(Result);
|
|
}
|
|
|
|
public string? CurrentQueriedBsn { get; private set; }
|
|
|
|
/// <summary>The current open registration the fake domain returns (null → the citizen has none in
|
|
/// flight, so the BFF replies 204). Tests set this to exercise resume.</summary>
|
|
public CurrentRegistration? Current { get; set; }
|
|
|
|
public Task<CurrentRegistration?> GetCurrentRegistrationAsync(string bsn, CancellationToken ct = default)
|
|
{
|
|
CurrentQueriedBsn = bsn;
|
|
return Task.FromResult(Current);
|
|
}
|
|
|
|
public (string RegistrationId, string Bsn)? Withdrawn { get; private set; }
|
|
|
|
/// <summary>Whether the fake domain reports the withdrawal as done (true → 204) or not-found/not-owned
|
|
/// (false → 404). Tests set this to exercise the relay.</summary>
|
|
public bool WithdrawSucceeds { get; set; } = true;
|
|
|
|
public Task<bool> WithdrawRegistrationAsync(string registrationId, string bsn, CancellationToken ct = default)
|
|
{
|
|
Withdrawn = (registrationId, bsn);
|
|
return Task.FromResult(WithdrawSucceeds);
|
|
}
|
|
|
|
public (string RegistrationId, string Bsn, string ContentBase64, string? FileName, string? ContentType)? DocumentsProvidedFor { get; private set; }
|
|
|
|
/// <summary>Whether the fake domain reports the provide-documents as done (true → 204) or
|
|
/// not-found/not-owned (false → 404). Tests set this to exercise the relay.</summary>
|
|
public bool ProvideDocumentsSucceeds { get; set; } = true;
|
|
|
|
public Task<bool> ProvideDocumentsAsync(string registrationId, string bsn, string contentBase64, string? fileName, string? contentType, CancellationToken ct = default)
|
|
{
|
|
DocumentsProvidedFor = (registrationId, bsn, contentBase64, fileName, contentType);
|
|
return Task.FromResult(ProvideDocumentsSucceeds);
|
|
}
|
|
|
|
public (string RegistrationId, string Besluit)? Decided { get; private set; }
|
|
|
|
public Task<IReadOnlyList<WerkbakItem>> GetWerkbakAsync(CancellationToken ct = default)
|
|
=> Task.FromResult<IReadOnlyList<WerkbakItem>>(Werkbak);
|
|
|
|
public Task DecideAsync(string registrationId, string besluit, CancellationToken ct = default)
|
|
{
|
|
Decided = (registrationId, besluit);
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
/// <summary>Serves a configurable set of projection rows.</summary>
|
|
internal sealed class FakeProjectionClient : IProjectionClient
|
|
{
|
|
public List<ProjectionEntry> Entries { get; } = [];
|
|
|
|
public Task<IReadOnlyList<ProjectionEntry>> GetRegisterAsync(CancellationToken ct = default)
|
|
=> Task.FromResult<IReadOnlyList<ProjectionEntry>>(Entries);
|
|
}
|
|
|
|
/// <summary>Serves a configurable set of catalogus zaaktypen (beheer viewer, S-15a).</summary>
|
|
internal sealed class FakeAclClient : IAclClient
|
|
{
|
|
public List<BeheerZaaktype> Zaaktypen { get; } = [];
|
|
|
|
public Task<IReadOnlyList<BeheerZaaktype>> GetZaaktypenAsync(CancellationToken ct = default)
|
|
=> Task.FromResult<IReadOnlyList<BeheerZaaktype>>(Zaaktypen);
|
|
}
|