Esempio n. 1
0
            public void ReturnsPermissionsFailureThrownBySubclass()
            {
                var failureToReturn = (PermissionsCheckResult)99;
                var action          = new TestableActionRequiringEntityPermissions(PermissionsRequirement.None, (account, entity) => failureToReturn);

                AssertIsAllowed(action, failureToReturn);
            }
Esempio n. 2
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);
            }
Esempio n. 3
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 }));
            }
Esempio n. 4
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 }));
            }
Esempio n. 5
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 }));
            }
Esempio n. 6
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);
            }
Esempio n. 7
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));
            }
Esempio n. 8
0
            public void ReturnsAccountPermissionsFailureWhenAccountCheckFails()
            {
                var action = new TestableActionRequiringEntityPermissions(PermissionsRequirement.Unsatisfiable, (account, entity) => PermissionsCheckResult.Allowed);

                AssertIsAllowed(action, PermissionsCheckResult.AccountFailure);
            }