Tests na de rebase: echte login voor de beheer-pipelinetests en OpenAPI-document bijgewerkt

De host controleert nu elk toegangstoken tegen een bestaande, actieve gebruiker met dezelfde security stamp, dus de pipelinetests maken een echte gebruiker met rol aan en loggen in via de authenticatieservice. Het OpenAPI-document is opnieuw gegenereerd met de routes van de gemergede master.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-10 13:25:57 +01:00
co-authored by Claude Sonnet 5.5
parent b39fc5b6ea
commit daa1bac312
2 changed files with 313 additions and 19 deletions
+274
View File
@@ -73,6 +73,12 @@
},
"CompleteSetupRequest": {
"properties": {
"name": {
"type": [
"null",
"string"
]
},
"password": {
"type": "string"
},
@@ -449,11 +455,28 @@
],
"type": "object"
},
"ForgotPasswordRequest": {
"properties": {
"email": {
"type": "string"
}
},
"required": [
"email"
],
"type": "object"
},
"InviteUserRequest": {
"properties": {
"email": {
"type": "string"
},
"language": {
"type": [
"null",
"string"
]
},
"role": {
"type": "string"
}
@@ -573,6 +596,15 @@
],
"type": "object"
},
"RegenerateInviteRequest": {
"properties": {
"sendEmail": {
"default": false,
"type": "boolean"
}
},
"type": "object"
},
"RegisterMasterRequest": {
"properties": {
"masterUrl": {
@@ -599,6 +631,26 @@
],
"type": "object"
},
"ResetPasswordRequest": {
"properties": {
"newPassword": {
"type": "string"
},
"token": {
"type": "string"
},
"userId": {
"format": "uuid",
"type": "string"
}
},
"required": [
"userId",
"token",
"newPassword"
],
"type": "object"
},
"SetUserActiveRequest": {
"properties": {
"isActive": {
@@ -638,6 +690,27 @@
],
"type": "object"
},
"UpdateMailSettingsRequest": {
"properties": {
"fromAddress": {
"type": [
"null",
"string"
]
},
"fromName": {
"type": [
"null",
"string"
]
}
},
"required": [
"fromAddress",
"fromName"
],
"type": "object"
},
"UpdateOfferingRequest": {
"properties": {
"categoryId": {
@@ -694,6 +767,12 @@
"email": {
"type": "string"
},
"language": {
"type": [
"null",
"string"
]
},
"name": {
"type": "string"
}
@@ -1110,6 +1189,48 @@
]
}
},
"/api/v1/SiteSettings/mail": {
"get": {
"responses": {
"200": {
"description": "OK"
}
},
"tags": [
"SiteSettings"
]
},
"put": {
"requestBody": {
"content": {
"application/*+json": {
"schema": {
"$ref": "#/components/schemas/UpdateMailSettingsRequest"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/UpdateMailSettingsRequest"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/UpdateMailSettingsRequest"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK"
}
},
"tags": [
"SiteSettings"
]
}
},
"/api/v1/SlaveStatus": {
"get": {
"responses": {
@@ -1210,6 +1331,92 @@
]
}
},
"/api/v1/Users/{invitationId}/regenerate-invite": {
"post": {
"parameters": [
{
"in": "path",
"name": "invitationId",
"required": true,
"schema": {
"format": "uuid",
"type": "string"
}
}
],
"requestBody": {
"content": {
"application/*+json": {
"schema": {
"oneOf": [
{
"type": "null"
},
{
"$ref": "#/components/schemas/RegenerateInviteRequest"
}
]
}
},
"application/json": {
"schema": {
"oneOf": [
{
"type": "null"
},
{
"$ref": "#/components/schemas/RegenerateInviteRequest"
}
]
}
},
"text/json": {
"schema": {
"oneOf": [
{
"type": "null"
},
{
"$ref": "#/components/schemas/RegenerateInviteRequest"
}
]
}
}
}
},
"responses": {
"200": {
"description": "OK"
}
},
"tags": [
"Users"
]
}
},
"/api/v1/Users/{invitationId}/resend-invite": {
"post": {
"parameters": [
{
"in": "path",
"name": "invitationId",
"required": true,
"schema": {
"format": "uuid",
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK"
}
},
"tags": [
"Users"
]
}
},
"/api/v1/Users/{userId}": {
"delete": {
"parameters": [
@@ -1351,6 +1558,38 @@
]
}
},
"/api/v1/auth/forgot-password": {
"post": {
"requestBody": {
"content": {
"application/*+json": {
"schema": {
"$ref": "#/components/schemas/ForgotPasswordRequest"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/ForgotPasswordRequest"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/ForgotPasswordRequest"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK"
}
},
"tags": [
"Auth"
]
}
},
"/api/v1/auth/login": {
"post": {
"requestBody": {
@@ -1395,6 +1634,38 @@
]
}
},
"/api/v1/auth/reset-password": {
"post": {
"requestBody": {
"content": {
"application/*+json": {
"schema": {
"$ref": "#/components/schemas/ResetPasswordRequest"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/ResetPasswordRequest"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/ResetPasswordRequest"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK"
}
},
"tags": [
"Auth"
]
}
},
"/api/v1/auth/revoke": {
"post": {
"responses": {
@@ -2089,6 +2360,9 @@
{
"name": "Setup"
},
{
"name": "SiteSettings"
},
{
"name": "Users"
},
@@ -1,39 +1,59 @@
using System.IdentityModel.Tokens.Jwt;
using System.Net;
using System.Net.Http.Headers;
using System.Security.Claims;
using System.Text;
using System.Text.Json;
using FluentAssertions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
using SlpModularCms.Core.Identity.Entities;
using SlpModularCms.Core.Identity.Services;
using SlpModularCms.Modules.Contact.Data.Entities;
namespace SlpModularCms.Modules.Contact.Tests.Pipeline;
/// <summary>Mints access tokens the way the host itself does (same settings, same claims).</summary>
/// <summary>
/// Logs in the way the host itself does: a real, active user with the given role is created and
/// the host's own authentication service issues the access token. (The host checks every access
/// token against its user, so a hand-made token for a user that does not exist is refused.)
/// </summary>
internal static class Jwt
{
private const string Password = "Password1!";
public static HttpClient ClientWithRole(ContactHostFactory factory, string role, Guid? userId = null)
=> ClientWithRoleAsync(factory, role, userId).GetAwaiter().GetResult();
public static async Task<HttpClient> ClientWithRoleAsync(ContactHostFactory factory, string role, Guid? userId = null)
{
var settings = factory.Services.GetRequiredService<IConfiguration>().GetSection("JwtSettings");
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(settings["Secret"]!));
var token = new JwtSecurityToken(
issuer: settings["Issuer"],
audience: settings["Audience"],
claims:
[
new Claim(ClaimTypes.NameIdentifier, (userId ?? Guid.NewGuid()).ToString()),
new Claim(ClaimTypes.Role, role),
],
expires: DateTime.UtcNow.AddHours(1),
signingCredentials: new SigningCredentials(key, SecurityAlgorithms.HmacSha256));
var id = userId ?? Guid.NewGuid();
var email = $"pipeline-{id:N}@example.test";
string accessToken;
await using (var scope = factory.Services.CreateAsyncScope())
{
var users = scope.ServiceProvider.GetRequiredService<UserManager<ApplicationUser>>();
var roles = scope.ServiceProvider.GetRequiredService<RoleManager<ApplicationRole>>();
if (!await roles.RoleExistsAsync(role))
{
// Roles normally appear with the first-run setup; a test host starts without one.
(await roles.CreateAsync(new ApplicationRole { Name = role })).Succeeded.Should().BeTrue();
}
if (await users.FindByIdAsync(id.ToString()) is null)
{
var user = new ApplicationUser { Id = id, UserName = email, Email = email, IsActive = true, DisplayName = email };
(await users.CreateAsync(user, Password)).Succeeded.Should().BeTrue();
(await users.AddToRoleAsync(user, role)).Succeeded.Should().BeTrue();
}
accessToken = (await scope.ServiceProvider.GetRequiredService<IAuthService>().AuthenticateAsync(email, Password)).AccessToken;
}
var client = factory.CreateClient();
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", new JwtSecurityTokenHandler().WriteToken(token));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
return client;
}