From cddd3a7359a9cb5922253f2643c8292d3943cae4 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 8 Jun 2021 18:36:29 +0200 Subject: [PATCH] Fix tests. --- .../EnrichWithActorCommandMiddlewareTests.cs | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/backend/tests/Squidex.Web.Tests/CommandMiddlewares/EnrichWithActorCommandMiddlewareTests.cs b/backend/tests/Squidex.Web.Tests/CommandMiddlewares/EnrichWithActorCommandMiddlewareTests.cs index 8cfafbce8..53db729e9 100644 --- a/backend/tests/Squidex.Web.Tests/CommandMiddlewares/EnrichWithActorCommandMiddlewareTests.cs +++ b/backend/tests/Squidex.Web.Tests/CommandMiddlewares/EnrichWithActorCommandMiddlewareTests.cs @@ -54,7 +54,7 @@ namespace Squidex.Web.CommandMiddlewares [Fact] public async Task Should_assign_actor_from_subject() { - httpContext.User = CreatePrincipal(OpenIdClaims.Subject, "my-user"); + httpContext.User = CreatePrincipal(OpenIdClaims.Subject, "my-user", "My User"); var context = await HandleAsync(new CreateContent()); @@ -64,7 +64,7 @@ namespace Squidex.Web.CommandMiddlewares [Fact] public async Task Should_assign_actor_from_client() { - httpContext.User = CreatePrincipal(OpenIdClaims.ClientId, "my-client"); + httpContext.User = CreatePrincipal(OpenIdClaims.ClientId, "my-client", null); var context = await HandleAsync(new CreateContent()); @@ -74,7 +74,7 @@ namespace Squidex.Web.CommandMiddlewares [Fact] public async Task Should_not_override_actor() { - httpContext.User = CreatePrincipal(OpenIdClaims.ClientId, "my-client"); + httpContext.User = CreatePrincipal(OpenIdClaims.ClientId, "my-client", null); var customActor = RefToken.User("me"); @@ -92,15 +92,18 @@ namespace Squidex.Web.CommandMiddlewares return commandContext; } - private static ClaimsPrincipal CreatePrincipal(string claimType, string claimValue) + private static ClaimsPrincipal CreatePrincipal(string claimType, string claimValue, string? name) { - var claimsPrincipal = new ClaimsPrincipal(); - var claimsIdentity = new ClaimsIdentity(); + var identity = new ClaimsIdentity(); - claimsIdentity.AddClaim(new Claim(claimType, claimValue)); - claimsPrincipal.AddIdentity(claimsIdentity); + identity.AddClaim(new Claim(claimType, claimValue)); - return claimsPrincipal; + if (name != null) + { + identity.AddClaim(new Claim(OpenIdClaims.Name, name)); + } + + return new ClaimsPrincipal(identity); } } }