예제 #1
0
            public void FailureWithNullAccount()
            {
                var action = new TestableActionRequiringEntityPermissions(PermissionsRequirement.Unsatisfiable, (a, e) => PermissionsCheckResult.Allowed);

                Assert.Equal(PermissionsCheckResult.AccountFailure, action.CheckPermissionsOnBehalfOfAnyAccount(null, null));
                Assert.Equal(PermissionsCheckResult.AccountFailure, action.CheckPermissionsOnBehalfOfAnyAccount(null, null, out var accountsAllowedOnBehalfOf));
                Assert.Empty(accountsAllowedOnBehalfOf);
            }
예제 #2
0
            public void SuccessWithNullAccount()
            {
                var action = new TestableActionRequiringEntityPermissions(PermissionsRequirement.None, (account, entity) => PermissionsCheckResult.Allowed);

                Assert.Equal(PermissionsCheckResult.Allowed, action.CheckPermissionsOnBehalfOfAnyAccount(null, null));
                Assert.Equal(PermissionsCheckResult.Allowed, action.CheckPermissionsOnBehalfOfAnyAccount(null, null, out var accountsAllowedOnBehalfOf));
                Assert.True(accountsAllowedOnBehalfOf.SequenceEqual(new User[] { null }));
            }
예제 #3
0
            public void OrganizationsOfCurrentUserArePossibleAccounts()
            {
                CreateOrganizationWithUser(out var organization, out var user);

                var action = new TestableActionRequiringEntityPermissions(PermissionsRequirement.None, (a, e) => PermissionsCheckResult.Allowed);

                Assert.Equal(PermissionsCheckResult.Allowed, action.CheckPermissionsOnBehalfOfAnyAccount(user, null));
                Assert.Equal(PermissionsCheckResult.Allowed, action.CheckPermissionsOnBehalfOfAnyAccount(user, null, out var accountsAllowedOnBehalfOf));
                Assert.True(accountsAllowedOnBehalfOf.SequenceEqual(new[] { user, organization }));
            }
예제 #4
0
            public void OwnersOfEntityArePossibleAccounts()
            {
                CreateEntityWithOwner(out var entity, out var entityOwner);

                var action = new TestableActionRequiringEntityPermissions(PermissionsRequirement.None, (a, e) => PermissionsCheckResult.Allowed);

                Assert.Equal(PermissionsCheckResult.Allowed, action.CheckPermissionsOnBehalfOfAnyAccount(null, entity));
                Assert.Equal(PermissionsCheckResult.Allowed, action.CheckPermissionsOnBehalfOfAnyAccount(null, entity, out var accountsAllowedOnBehalfOf));
                Assert.True(accountsAllowedOnBehalfOf.SequenceEqual(new[] { null, entityOwner }));
            }
예제 #5
0
            public void FailureWithNullEntity()
            {
                var failureResult = (PermissionsCheckResult)99;
                var user          = new User {
                    Key = 1
                };

                var action = new TestableActionRequiringEntityPermissions(PermissionsRequirement.None, (a, e) => (PermissionsCheckResult)99);

                Assert.Equal(failureResult, action.CheckPermissionsOnBehalfOfAnyAccount(user, null));
                Assert.Equal(failureResult, action.CheckPermissionsOnBehalfOfAnyAccount(user, null, out var accountsAllowedOnBehalfOf));
                Assert.Empty(accountsAllowedOnBehalfOf);
            }
예제 #6
0
            public void AccountsAllowedOnBehalfOfIsPopulatedWithExpectedAccounts(int expectedAccounts)
            {
                CreateOrganizationWithUser(out var organization, out var user);
                CreateEntityWithOwner(out var entity, out var entityOwner);

                var expectedAccountsList = new[] { user, entityOwner, organization }.Where(a => ((int)Math.Pow(2, a.Key - 1) & expectedAccounts) > 0);

                var action = new TestableActionRequiringEntityPermissions(PermissionsRequirement.None,
                                                                          (a, e) => expectedAccountsList.Any(u => u.MatchesUser(a)) ? PermissionsCheckResult.Allowed : (PermissionsCheckResult)99);

                Assert.Equal(PermissionsCheckResult.Allowed, action.CheckPermissionsOnBehalfOfAnyAccount(user, entity));
                Assert.Equal(PermissionsCheckResult.Allowed, action.CheckPermissionsOnBehalfOfAnyAccount(user, entity, out var accountsAllowedOnBehalfOf));
                Assert.True(accountsAllowedOnBehalfOf.SequenceEqual(expectedAccountsList));
            }