Skip to content

Commit 629672c

Browse files
authored
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.
1 parent c6f1ace commit 629672c

2 files changed

Lines changed: 616 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System.Reflection;
2+
using System.Security.Claims;
3+
using AutoFixture;
4+
using AutoFixture.Xunit2;
5+
using Bit.Core.Auth.Identity;
6+
using Duende.IdentityServer.Models;
7+
using Duende.IdentityServer.Validation;
8+
9+
namespace Bit.Identity.Test.AutoFixture;
10+
11+
internal class ProfileDataRequestContextCustomization : ICustomization
12+
{
13+
public void Customize(IFixture fixture)
14+
{
15+
fixture.Customize<ProfileDataRequestContext>(composer => composer
16+
.With(o => o.Subject, new ClaimsPrincipal(new ClaimsIdentity([
17+
new Claim("sub", Guid.NewGuid().ToString()),
18+
new Claim("name", "Test User"),
19+
new Claim("email", "test@example.com")
20+
])))
21+
.With(o => o.Client, new Client { ClientId = "web" })
22+
.With(o => o.ValidatedRequest, () => null)
23+
.With(o => o.RequestedResources, new ResourceValidationResult())
24+
.With(o => o.IssuedClaims, [])
25+
.Without(o => o.Caller));
26+
}
27+
}
28+
29+
public class ProfileDataRequestContextAttribute : CustomizeAttribute
30+
{
31+
public override ICustomization GetCustomization(ParameterInfo parameter)
32+
{
33+
return new ProfileDataRequestContextCustomization();
34+
}
35+
}
36+
37+
internal class IsActiveContextCustomization : ICustomization
38+
{
39+
public void Customize(IFixture fixture)
40+
{
41+
fixture.Customize<IsActiveContext>(composer => composer
42+
.With(o => o.Subject, new ClaimsPrincipal(new ClaimsIdentity([
43+
new Claim("sub", Guid.NewGuid().ToString()),
44+
new Claim(Claims.SecurityStamp, "test-security-stamp")
45+
])))
46+
.With(o => o.Client, new Client { ClientId = "web" })
47+
.With(o => o.IsActive, false)
48+
.Without(o => o.Caller));
49+
}
50+
}
51+
52+
public class IsActiveContextAttribute : CustomizeAttribute
53+
{
54+
public override ICustomization GetCustomization(ParameterInfo parameter)
55+
{
56+
return new IsActiveContextCustomization();
57+
}
58+
}

0 commit comments

Comments
 (0)