mirror of
https://github.com/bitwarden/server
synced 2025-12-22 03:03:33 +00:00
Add tests for ProfileService (#6466)
* feat(profile-service) [PM-24621]: Add ProfileService test fixtures. * feat(profile-service) [PM-24621]: Add ProfileService test suite. * feat(profile-servie) [PM-24621]: Re-spell to more consistently use constants across tests.
This commit is contained in:
58
test/Identity.Test/AutoFixture/ProfileServiceFixtures.cs
Normal file
58
test/Identity.Test/AutoFixture/ProfileServiceFixtures.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System.Reflection;
|
||||
using System.Security.Claims;
|
||||
using AutoFixture;
|
||||
using AutoFixture.Xunit2;
|
||||
using Bit.Core.Auth.Identity;
|
||||
using Duende.IdentityServer.Models;
|
||||
using Duende.IdentityServer.Validation;
|
||||
|
||||
namespace Bit.Identity.Test.AutoFixture;
|
||||
|
||||
internal class ProfileDataRequestContextCustomization : ICustomization
|
||||
{
|
||||
public void Customize(IFixture fixture)
|
||||
{
|
||||
fixture.Customize<ProfileDataRequestContext>(composer => composer
|
||||
.With(o => o.Subject, new ClaimsPrincipal(new ClaimsIdentity([
|
||||
new Claim("sub", Guid.NewGuid().ToString()),
|
||||
new Claim("name", "Test User"),
|
||||
new Claim("email", "test@example.com")
|
||||
])))
|
||||
.With(o => o.Client, new Client { ClientId = "web" })
|
||||
.With(o => o.ValidatedRequest, () => null)
|
||||
.With(o => o.RequestedResources, new ResourceValidationResult())
|
||||
.With(o => o.IssuedClaims, [])
|
||||
.Without(o => o.Caller));
|
||||
}
|
||||
}
|
||||
|
||||
public class ProfileDataRequestContextAttribute : CustomizeAttribute
|
||||
{
|
||||
public override ICustomization GetCustomization(ParameterInfo parameter)
|
||||
{
|
||||
return new ProfileDataRequestContextCustomization();
|
||||
}
|
||||
}
|
||||
|
||||
internal class IsActiveContextCustomization : ICustomization
|
||||
{
|
||||
public void Customize(IFixture fixture)
|
||||
{
|
||||
fixture.Customize<IsActiveContext>(composer => composer
|
||||
.With(o => o.Subject, new ClaimsPrincipal(new ClaimsIdentity([
|
||||
new Claim("sub", Guid.NewGuid().ToString()),
|
||||
new Claim(Claims.SecurityStamp, "test-security-stamp")
|
||||
])))
|
||||
.With(o => o.Client, new Client { ClientId = "web" })
|
||||
.With(o => o.IsActive, false)
|
||||
.Without(o => o.Caller));
|
||||
}
|
||||
}
|
||||
|
||||
public class IsActiveContextAttribute : CustomizeAttribute
|
||||
{
|
||||
public override ICustomization GetCustomization(ParameterInfo parameter)
|
||||
{
|
||||
return new IsActiveContextCustomization();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user