public void ValidClaims_Success_FileSubmission(string role) { var policyhandler = new AuthorizationPolicyHandler(); var claims = new List <Claim>() { new Claim(IdamsClaimTypes.DisplayName, "test"), new Claim(IdamsClaimTypes.Service, role), }; var identity = new ClaimsIdentity(claims, "Idams"); var claimsPrincipal = new ClaimsPrincipal(identity); var authorizationHandlerContext = new AuthorizationHandlerContext( new List <IAuthorizationRequirement> { new FileSubmissionPolicyRequirement(), }, claimsPrincipal, null); var result = policyhandler.HandleAsync(authorizationHandlerContext); authorizationHandlerContext.HasSucceeded.Should().BeTrue(); authorizationHandlerContext.HasFailed.Should().BeFalse(); result.IsCompleted.Should().BeTrue(); }
public void NullClaims_Fail() { var policyhandler = new AuthorizationPolicyHandler(); var authorizationHandlerContext = new AuthorizationHandlerContext( new List <IAuthorizationRequirement> { new FileSubmissionPolicyRequirement(), new HelpDeskAccessPolicyRequirement(), }, null, null); var result = policyhandler.HandleAsync(authorizationHandlerContext); authorizationHandlerContext.HasSucceeded.Should().BeFalse(); authorizationHandlerContext.HasFailed.Should().BeTrue(); result.IsCompleted.Should().BeTrue(); }
public void EmptyClaims_Fail() { var policyhandler = new AuthorizationPolicyHandler(); var identity = new ClaimsIdentity(new List <Claim>(), "TestAuthType"); var claimsPrincipal = new ClaimsPrincipal(identity); var authorizationHandlerContext = new AuthorizationHandlerContext( new List <IAuthorizationRequirement> { new FileSubmissionPolicyRequirement(), new HelpDeskAccessPolicyRequirement(), }, claimsPrincipal, null); var result = policyhandler.HandleAsync(authorizationHandlerContext); authorizationHandlerContext.HasSucceeded.Should().BeFalse(); authorizationHandlerContext.HasFailed.Should().BeTrue(); result.IsCompleted.Should().BeTrue(); }
public async Task ValidClaims_Fail_FileSubmission() { var policyhandler = new AuthorizationPolicyHandler(); var claims = new List <Claim>() { new Claim(IdamsClaimTypes.DisplayName, "test"), new Claim(IdamsClaimTypes.UserType, "LSC"), }; var identity = new ClaimsIdentity(claims, "Idams"); var claimsPrincipal = new ClaimsPrincipal(identity); var authorizationHandlerContext = new AuthorizationHandlerContext( new List <IAuthorizationRequirement> { new FileSubmissionPolicyRequirement(), }, claimsPrincipal, new object()); await policyhandler.HandleAsync(authorizationHandlerContext); authorizationHandlerContext.HasSucceeded.Should().BeFalse(); }