using BigRegister.Api.Data; using BigRegister.Domain.Authorization; using Microsoft.AspNetCore.Http; namespace BigRegister.Tests; /// WP-53: the dev stub identity provider — role from X-Role (unchanged behaviour), subject BSN /// from the new X-Subject header, defaulting to the single seeded citizen so every existing /// request (none of which send X-Subject) resolves exactly as before this WP. public class StubIdentityProviderTests { private static CallerIdentity Resolve(string? role, string? subject) { var ctx = new DefaultHttpContext(); if (role is not null) ctx.Request.Headers["X-Role"] = role; if (subject is not null) ctx.Request.Headers["X-Subject"] = subject; return new StubIdentityProvider().Resolve(ctx); } [Fact] public void No_headers_resolves_to_the_seeded_citizen_as_a_drafter() { var caller = Resolve(role: null, subject: null); Assert.Equal(DocumentStore.DemoOwner, caller.Bsn); Assert.Equal(PrincipalRole.Drafter, caller.Role); } [Theory] [InlineData("approver", PrincipalRole.Approver)] [InlineData("admin", PrincipalRole.Admin)] [InlineData("something-unknown", PrincipalRole.Drafter)] public void X_role_maps_to_the_principal_role(string header, PrincipalRole expected) { Assert.Equal(expected, Resolve(header, subject: null).Role); } [Fact] public void X_subject_overrides_the_default_bsn() { var caller = Resolve(role: null, subject: "999888777"); Assert.Equal("999888777", caller.Bsn); } }