Files
raceplanner/backend/backend.Tests/Utilities/TestUserClaims.cs
T

38 lines
1.2 KiB
C#
Raw Normal View History

2026-04-05 22:16:44 +02:00
using System.Security.Claims;
namespace backend.Tests.Utilities;
public static class TestUserClaims
{
public static ClaimsPrincipal CreateOrganizer(Guid? userId = null, string email = "organizer@example.com")
{
var claims = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier, (userId ?? Guid.NewGuid()).ToString()),
new Claim(ClaimTypes.Email, email),
new Claim(ClaimTypes.Role, "Organizer")
};
var identity = new ClaimsIdentity(claims, "TestAuthType");
return new ClaimsPrincipal(identity);
}
public static ClaimsPrincipal CreateParticipant(Guid? userId = null, string email = "participant@example.com")
{
var claims = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier, (userId ?? Guid.NewGuid()).ToString()),
new Claim(ClaimTypes.Email, email),
new Claim(ClaimTypes.Role, "Participant")
};
var identity = new ClaimsIdentity(claims, "TestAuthType");
return new ClaimsPrincipal(identity);
}
public static ClaimsPrincipal CreateUnauthenticated()
{
return new ClaimsPrincipal(new ClaimsIdentity());
}
}