public async Task ThenFailsIfProviderUkprnNotInRoute( ProviderUkPrnRequirement requirement, AuthorizationFilterContext contextFilter, ProviderAuthorizationHandler handler) { //Assign var claim = new Claim(ProviderClaims.ProviderUkprn, "1234"); var claimsPrinciple = new ClaimsPrincipal(new[] { new ClaimsIdentity(new[] { claim }) }); var context = new AuthorizationHandlerContext(new[] { requirement }, claimsPrinciple, contextFilter); //Act await handler.HandleAsync(context); //Assert Assert.IsFalse(context.HasSucceeded); }
public void ThenReturnsFalseIfProviderUkprnNotInRoute( ProviderUkPrnRequirement requirement, AuthorizationFilterContext contextFilter, ProviderAuthorizationHandler handler) { //Assign var claim = new Claim(ProviderClaims.ProviderUkprn, "1234"); var claimsPrinciple = new ClaimsPrincipal(new[] { new ClaimsIdentity(new[] { claim }) }); var context = new AuthorizationHandlerContext(new[] { requirement }, claimsPrinciple, contextFilter); //Act var result = handler.IsProviderAuthorised(context); //Assert Assert.IsFalse(result); }
public async Task Then_Fails_If_No_Provider_Ukprn_Claim( int ukprn, ProviderUkPrnRequirement providerRequirement, [Frozen] Mock <IHttpContextAccessor> httpContextAccessor, ProviderAuthorizationHandler authorizationHandler) { //Arrange var claim = new Claim("NotProviderClaim", ukprn.ToString()); var claimsPrinciple = new ClaimsPrincipal(new[] { new ClaimsIdentity(new[] { claim }) }); var context = new AuthorizationHandlerContext(new [] { providerRequirement }, claimsPrinciple, null); //Act await authorizationHandler.HandleAsync(context); //Assert Assert.IsFalse(context.HasSucceeded); Assert.IsTrue(context.HasFailed); }
public async Task ThenFailsIfUserDoesNotHaveClaim( ProviderUkPrnRequirement requirement, AuthorizationFilterContext contextFilter, ProviderAuthorizationHandler handler) { //Assign var claimsPrinciple = new ClaimsPrincipal(new[] { new ClaimsIdentity(new Claim[0]) }); var context = new AuthorizationHandlerContext(new[] { requirement }, claimsPrinciple, contextFilter); var filter = context.Resource as AuthorizationFilterContext; filter.RouteData.Values.Add(RouteValues.UkPrn, 1234); //Act await handler.HandleAsync(context); //Assert Assert.IsFalse(context.HasSucceeded); }
public void ThenReturnsFalseIfUserDoesNotHaveMatchingUkprnInClaim( ProviderUkPrnRequirement requirement, AuthorizationFilterContext contextFilter, ProviderAuthorizationHandler handler) { //Assign var claim = new Claim(ProviderClaims.ProviderUkprn, "5555"); var claimsPrinciple = new ClaimsPrincipal(new[] { new ClaimsIdentity(new[] { claim }) }); var context = new AuthorizationHandlerContext(new[] { requirement }, claimsPrinciple, contextFilter); var filter = context.Resource as AuthorizationFilterContext; filter.RouteData.Values.Add(RouteValues.UkPrn, 1234); //Act var result = handler.IsProviderAuthorised(context); //Assert Assert.IsFalse(result); }
public async Task ThenSucceedsIfProviderIsAuthorised( ProviderUkPrnRequirement requirement, AuthorizationFilterContext contextFilter, ProviderAuthorizationHandler handler) { //Assign var claim = new Claim(ProviderClaims.ProviderUkprn, "1234"); var claimsPrinciple = new ClaimsPrincipal(new[] { new ClaimsIdentity(new[] { claim }) }); var context = new AuthorizationHandlerContext(new[] { requirement }, claimsPrinciple, contextFilter); var filter = context.Resource as AuthorizationFilterContext; filter.RouteData.Values.Add(RouteValues.UkPrn, 1234); //Act await handler.HandleAsync(context); //Assert Assert.IsTrue(context.HasSucceeded); }
public async Task Then_If_There_Is_No_Ukrpn_In_Route_But_Has_Claim_Then_Succeeds( int ukprn, ProviderUkPrnRequirement providerRequirement, [Frozen] Mock <IHttpContextAccessor> httpContextAccessor, ProviderAuthorizationHandler authorizationHandler) { //Arrange var responseMock = new FeatureCollection(); var httpContext = new DefaultHttpContext(responseMock); httpContextAccessor.Setup(_ => _.HttpContext).Returns(httpContext); var claim = new Claim(ProviderClaims.ProviderUkprn, ukprn.ToString()); var claimsPrinciple = new ClaimsPrincipal(new[] { new ClaimsIdentity(new[] { claim }) }); var context = new AuthorizationHandlerContext(new [] { providerRequirement }, claimsPrinciple, null); //Act await authorizationHandler.HandleAsync(context); //Assert Assert.IsTrue(context.HasSucceeded); Assert.IsFalse(context.HasFailed); }