You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have role based authorization, my claims would look like this;
{
"role": [
"Employee",
"Admin",
...
]
}
In a test i'd like to remove this role so i can test that asp.net correctly returns Forbidden, but i can't seem to get that to work becuase i can only remove a claim by key;
await Host.Scenario(c =>{ c.RemoveClaim("Role");// Would remove all roles, not a specific role. c.Get.Url(url); c.StatusCodeShouldBe(HttpStatusCode.Forbidden);});
Could Alba support configuring the claim values on a per test basis?
In my case i'd like to only remove the 'Employee' role.
For the sake of completeness, the Host is setup in a base class, using MsTest :
publicabstractclassIntegrationTestBase{protectedstaticIAlbaHostHost{get;set;}=null!;[ClassInitialize(InheritanceBehavior.BeforeEachDerivedClass)]publicstaticasync Task ClassInitialize(TestContextcontext){varjwtSecurityStub=new JwtSecurityStub().With(JwtRegisteredClaimNames.Email,"runner@webapi.tests");varclaimsByRole= RoleManagerExtensions.GetRoleClaims();foreach(var(role, claims)in claimsByRole){jwtSecurityStub= jwtSecurityStub.With("role", role);foreach(var claim in claims){jwtSecurityStub= jwtSecurityStub.With(claim);}}Host=await AlbaHost.For<Program>(x =>{ x.ConfigureServices((_,services)=>{for(vari= services.Count -1;i >= 0;i--){varservice= services[i]; Type[]implementationTypesToRemove=[// Hosted services that do stuff on startuptypeof(VersionHostedService),typeof(DbContextWarmUpHostedService),typeof(YarpConfiguratorHostedService),// Remove auth so the stub can pick this uptypeof(ConfigureJwtBearerOptions)];if(implementationTypesToRemove.Contains(service.ImplementationType)){ services.RemoveAt(i);}} services.ConfigureOptions<ConfigureJwtBearerOptionsMock>();});}, jwtSecurityStub);}[ClassCleanup]publicvoidClassCleanup(){
Host.Dispose();}}
I may be able to push out a PR, if you'd like me to do that, please provide me some steps on how you want this to work.
The text was updated successfully, but these errors were encountered:
Sorry, I missed this issue when you first posted it. This is unsupportable, claims don't have a type once created, they're just strings. I'd recommend writing an extension that removes the claim and adds the change you want (claims can be removed & added as part of the same scenario).
Hi,
I have role based authorization, my claims would look like this;
In a test i'd like to remove this role so i can test that asp.net correctly returns Forbidden, but i can't seem to get that to work becuase i can only remove a claim by key;
Could Alba support configuring the claim values on a per test basis?
In my case i'd like to only remove the 'Employee' role.
For the sake of completeness, the Host is setup in a base class, using MsTest :
I may be able to push out a PR, if you'd like me to do that, please provide me some steps on how you want this to work.
The text was updated successfully, but these errors were encountered: