mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.6 KiB
49 lines
1.6 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System.Security.Claims;
|
|
using Squidex.Infrastructure.TestHelpers;
|
|
|
|
namespace Squidex.Infrastructure.Json;
|
|
|
|
public class ClaimsPrincipalConverterTests
|
|
{
|
|
[Fact]
|
|
public void Should_serialize_and_deserialize()
|
|
{
|
|
var value = new ClaimsPrincipal(
|
|
[
|
|
new ClaimsIdentity(
|
|
[
|
|
new Claim("email", "me@email.com"),
|
|
new Claim("username", "me@email.com"),
|
|
],
|
|
"Cookie"),
|
|
new ClaimsIdentity(
|
|
[
|
|
new Claim("user_id", "12345"),
|
|
new Claim("login", "me"),
|
|
],
|
|
"Google"),
|
|
]);
|
|
|
|
var serialized = value.SerializeAndDeserializeJson();
|
|
|
|
Assert.Equal(value.Identities.ElementAt(0).AuthenticationType, serialized.Identities.ElementAt(0).AuthenticationType);
|
|
Assert.Equal(value.Identities.ElementAt(1).AuthenticationType, serialized.Identities.ElementAt(1).AuthenticationType);
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_serialize_and_deserialize_null_principal()
|
|
{
|
|
ClaimsPrincipal? value = null;
|
|
|
|
var serialized = value.SerializeAndDeserializeJson();
|
|
|
|
Assert.Null(serialized);
|
|
}
|
|
}
|
|
|