Browse Source

Fix tests.

pull/724/head
Sebastian 5 years ago
parent
commit
cddd3a7359
  1. 21
      backend/tests/Squidex.Web.Tests/CommandMiddlewares/EnrichWithActorCommandMiddlewareTests.cs

21
backend/tests/Squidex.Web.Tests/CommandMiddlewares/EnrichWithActorCommandMiddlewareTests.cs

@ -54,7 +54,7 @@ namespace Squidex.Web.CommandMiddlewares
[Fact] [Fact]
public async Task Should_assign_actor_from_subject() 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()); var context = await HandleAsync(new CreateContent());
@ -64,7 +64,7 @@ namespace Squidex.Web.CommandMiddlewares
[Fact] [Fact]
public async Task Should_assign_actor_from_client() 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()); var context = await HandleAsync(new CreateContent());
@ -74,7 +74,7 @@ namespace Squidex.Web.CommandMiddlewares
[Fact] [Fact]
public async Task Should_not_override_actor() 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"); var customActor = RefToken.User("me");
@ -92,15 +92,18 @@ namespace Squidex.Web.CommandMiddlewares
return commandContext; 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 identity = new ClaimsIdentity();
var claimsIdentity = new ClaimsIdentity();
claimsIdentity.AddClaim(new Claim(claimType, claimValue)); identity.AddClaim(new Claim(claimType, claimValue));
claimsPrincipal.AddIdentity(claimsIdentity);
return claimsPrincipal; if (name != null)
{
identity.AddClaim(new Claim(OpenIdClaims.Name, name));
}
return new ClaimsPrincipal(identity);
} }
} }
} }

Loading…
Cancel
Save