private void MockAuthorizationService(AuthorizationResult result) { var policyToCall = StartechPolicyHelper.GetPolicyName(Startechs.Dotnet, MustBeLeader: true); AuthorizationService.Setup(x => x.AuthorizeAsync(It.IsAny <ClaimsPrincipal>(), It.IsAny <object>(), It.IsIn <string>(policyToCall))) .Returns(Task.Factory.StartNew(() => result)); }
public async Task when_user_is_leader_and_must_be_leader_is_true_StartechAuthorizationService_should_return_true() { var policy = StartechPolicyHelper.GetPolicyName(Startechs.Agile, false); AuthorizationService.Setup(x => x.AuthorizeAsync(It.IsAny <ClaimsPrincipal>(), It.IsAny <object>(), It.IsIn(policy))) .Returns(Task.Factory.StartNew(() => AuthorizationResult.Success())); var target = Create(); var result = await target.IsMemberOrLeaderOf(Startechs.Agile); result.Should().BeTrue(); }
public async Task StartechAuthorizationService_should_ask_authorization_with_correct_policy() { var policy = StartechPolicyHelper.GetPolicyName(Startechs.Agile, true); AuthorizationService.Setup(x => x.AuthorizeAsync(It.IsAny <ClaimsPrincipal>(), It.IsAny <object>(), It.IsIn(policy))) .Returns(Task.Factory.StartNew(() => AuthorizationResult.Success())); var target = Create(); var result = await target.IsMemberOrLeaderOf(Startechs.Agile); AuthorizationService.Verify(x => x.AuthorizeAsync(It.IsAny <ClaimsPrincipal>(), It.IsAny <object>(), It.IsIn(policy))); }
protected void UnauthorizeMember() { AuthorizationService.Setup(x => x.AuthorizeAsync(It.IsAny <ClaimsPrincipal>(), It.IsAny <object>(), It.IsIn(StartechPolicyHelper.AllStartechLeader))) .Returns(Task.Factory.StartNew(() => AuthorizationResult.Failed())); foreach (var startech in Enum.GetValues(typeof(Startechs)).Cast <Startechs>()) { var ThisLoopPolicy = StartechPolicyHelper.GetPolicyName(startech, MustBeLeader: true); AuthorizationService.Setup(x => x.AuthorizeAsync(It.IsAny <ClaimsPrincipal>(), It.IsAny <object>(), It.IsIn(ThisLoopPolicy))) .Returns(Task.Factory.StartNew(() => AuthorizationResult.Failed())); } }
public async Task <bool> IsMemberOrLeaderOf(Startechs startech, bool mustBeLeader = true) { if (!Enum.IsDefined(typeof(Startechs), startech)) { return(false); } var authentificationState = await authentificationProvider.GetAuthenticationStateAsync(); return((await authorizationService.AuthorizeAsync(authentificationState.User, StartechPolicyHelper.GetPolicyName(startech, mustBeLeader))).Succeeded); }
public async Task a_user_with_startechs_claims_and_value_Member_is_a_startech_member() { var authentificationResult = await AuthorizationService.AuthorizeAsync(StartechMemberUser, StartechPolicyHelper.GetPolicyName(Startechs.Dotnet, MustBeLeader: false)); authentificationResult.Succeeded.Should().BeTrue(); }
public async Task a_user_without_startechs_claims_is_not_a_startech_leader() { var authentificationResult = await AuthorizationService.AuthorizeAsync(NoStartechUser, StartechPolicyHelper.GetPolicyName(Startechs.Dotnet, MustBeLeader: true)); authentificationResult.Succeeded.Should().BeFalse(); }
public async Task Admin_is_a_startech_leader() { var authentificationResult = await AuthorizationService.AuthorizeAsync(AdminUser, StartechPolicyHelper.GetPolicyName(Startechs.Dotnet, MustBeLeader: true)); authentificationResult.Succeeded.Should().BeTrue(); }
private bool IsStartechLeader(Startechs x) { return(authorizationService.AuthorizeAsync(httpContextAccessor.HttpContext.User, StartechPolicyHelper.GetPolicyName(x, MustBeLeader: true)).GetAwaiter().GetResult().Succeeded); }