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:
@@ -73,6 +73,12 @@
|
|||||||
},
|
},
|
||||||
"CompleteSetupRequest": {
|
"CompleteSetupRequest": {
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"name": {
|
||||||
|
"type": [
|
||||||
|
"null",
|
||||||
|
"string"
|
||||||
|
]
|
||||||
|
},
|
||||||
"password": {
|
"password": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
@@ -449,11 +455,28 @@
|
|||||||
],
|
],
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
|
"ForgotPasswordRequest": {
|
||||||
|
"properties": {
|
||||||
|
"email": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"email"
|
||||||
|
],
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
"InviteUserRequest": {
|
"InviteUserRequest": {
|
||||||
"properties": {
|
"properties": {
|
||||||
"email": {
|
"email": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"language": {
|
||||||
|
"type": [
|
||||||
|
"null",
|
||||||
|
"string"
|
||||||
|
]
|
||||||
|
},
|
||||||
"role": {
|
"role": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
@@ -573,6 +596,15 @@
|
|||||||
],
|
],
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
|
"RegenerateInviteRequest": {
|
||||||
|
"properties": {
|
||||||
|
"sendEmail": {
|
||||||
|
"default": false,
|
||||||
|
"type": "boolean"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
"RegisterMasterRequest": {
|
"RegisterMasterRequest": {
|
||||||
"properties": {
|
"properties": {
|
||||||
"masterUrl": {
|
"masterUrl": {
|
||||||
@@ -599,6 +631,26 @@
|
|||||||
],
|
],
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
|
"ResetPasswordRequest": {
|
||||||
|
"properties": {
|
||||||
|
"newPassword": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"token": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"userId": {
|
||||||
|
"format": "uuid",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"userId",
|
||||||
|
"token",
|
||||||
|
"newPassword"
|
||||||
|
],
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
"SetUserActiveRequest": {
|
"SetUserActiveRequest": {
|
||||||
"properties": {
|
"properties": {
|
||||||
"isActive": {
|
"isActive": {
|
||||||
@@ -638,6 +690,27 @@
|
|||||||
],
|
],
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
|
"UpdateMailSettingsRequest": {
|
||||||
|
"properties": {
|
||||||
|
"fromAddress": {
|
||||||
|
"type": [
|
||||||
|
"null",
|
||||||
|
"string"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"fromName": {
|
||||||
|
"type": [
|
||||||
|
"null",
|
||||||
|
"string"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"fromAddress",
|
||||||
|
"fromName"
|
||||||
|
],
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
"UpdateOfferingRequest": {
|
"UpdateOfferingRequest": {
|
||||||
"properties": {
|
"properties": {
|
||||||
"categoryId": {
|
"categoryId": {
|
||||||
@@ -694,6 +767,12 @@
|
|||||||
"email": {
|
"email": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"language": {
|
||||||
|
"type": [
|
||||||
|
"null",
|
||||||
|
"string"
|
||||||
|
]
|
||||||
|
},
|
||||||
"name": {
|
"name": {
|
||||||
"type": "string"
|
"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": {
|
"/api/v1/SlaveStatus": {
|
||||||
"get": {
|
"get": {
|
||||||
"responses": {
|
"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}": {
|
"/api/v1/Users/{userId}": {
|
||||||
"delete": {
|
"delete": {
|
||||||
"parameters": [
|
"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": {
|
"/api/v1/auth/login": {
|
||||||
"post": {
|
"post": {
|
||||||
"requestBody": {
|
"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": {
|
"/api/v1/auth/revoke": {
|
||||||
"post": {
|
"post": {
|
||||||
"responses": {
|
"responses": {
|
||||||
@@ -2089,6 +2360,9 @@
|
|||||||
{
|
{
|
||||||
"name": "Setup"
|
"name": "Setup"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "SiteSettings"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "Users"
|
"name": "Users"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,39 +1,59 @@
|
|||||||
using System.IdentityModel.Tokens.Jwt;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Security.Claims;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using SlpModularCms.Core.Identity.Entities;
|
||||||
|
using SlpModularCms.Core.Identity.Services;
|
||||||
using SlpModularCms.Modules.Contact.Data.Entities;
|
using SlpModularCms.Modules.Contact.Data.Entities;
|
||||||
|
|
||||||
namespace SlpModularCms.Modules.Contact.Tests.Pipeline;
|
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
|
internal static class Jwt
|
||||||
{
|
{
|
||||||
|
private const string Password = "Password1!";
|
||||||
|
|
||||||
public static HttpClient ClientWithRole(ContactHostFactory factory, string role, Guid? userId = null)
|
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 id = userId ?? Guid.NewGuid();
|
||||||
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(settings["Secret"]!));
|
var email = $"pipeline-{id:N}@example.test";
|
||||||
var token = new JwtSecurityToken(
|
|
||||||
issuer: settings["Issuer"],
|
string accessToken;
|
||||||
audience: settings["Audience"],
|
await using (var scope = factory.Services.CreateAsyncScope())
|
||||||
claims:
|
{
|
||||||
[
|
var users = scope.ServiceProvider.GetRequiredService<UserManager<ApplicationUser>>();
|
||||||
new Claim(ClaimTypes.NameIdentifier, (userId ?? Guid.NewGuid()).ToString()),
|
var roles = scope.ServiceProvider.GetRequiredService<RoleManager<ApplicationRole>>();
|
||||||
new Claim(ClaimTypes.Role, role),
|
if (!await roles.RoleExistsAsync(role))
|
||||||
],
|
{
|
||||||
expires: DateTime.UtcNow.AddHours(1),
|
// Roles normally appear with the first-run setup; a test host starts without one.
|
||||||
signingCredentials: new SigningCredentials(key, SecurityAlgorithms.HmacSha256));
|
(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();
|
var client = factory.CreateClient();
|
||||||
client.DefaultRequestHeaders.Authorization =
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
|
||||||
new AuthenticationHeaderValue("Bearer", new JwtSecurityTokenHandler().WriteToken(token));
|
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user