Beispiel #1
0
        public async Task Demand_MultiplePrivileges_UserWithPrivilege_NoAuthorizationExceptionsThrown()
        {
            // arrange
            Exception exception      = null;
            const int userId         = 1;
            var       repositoryMock = new Mock <IPrivilegesRepository>();

            repositoryMock
            .Setup(m => m.GetInstanceAdminPrivilegesAsync(userId))
            .ReturnsAsync(InstanceAdminPrivileges.AssignAdminRoles);
            var manager = new PrivilegesManager(repositoryMock.Object);

            // act
            try
            {
                await manager.Demand(userId, InstanceAdminPrivileges.ManageUsers | InstanceAdminPrivileges.AssignAdminRoles);
            }
            catch (AuthorizationException ex)
            {
                exception = ex;
            }

            // assert
            Assert.IsNull(exception);
        }
Beispiel #2
0
        public async Task DemandAny_UserWithProjectAdminPrivileges_NoAuthorizationExceptionsThrown()
        {
            // arrange
            Exception exception      = null;
            const int userId         = 1;
            const int projectId      = 1;
            var       repositoryMock = new Mock <IPrivilegesRepository>();

            repositoryMock
            .Setup(m => m.GetInstanceAdminPrivilegesAsync(userId))
            .ReturnsAsync(InstanceAdminPrivileges.ViewUsers);
            repositoryMock
            .Setup(m => m.GetProjectAdminPermissionsAsync(userId, projectId))
            .ReturnsAsync(ProjectAdminPrivileges.ManageGroupsAndRoles);

            var manager = new PrivilegesManager(repositoryMock.Object);

            // act
            try
            {
                await manager.DemandAny(userId, projectId, InstanceAdminPrivileges.AccessAllProjectsAdmin, ProjectAdminPrivileges.ManageGroupsAndRoles);
            }
            catch (AuthorizationException ex)
            {
                exception = ex;
            }

            // assert
            Assert.IsNull(exception);
        }
Beispiel #3
0
        public async Task Demand_MultiplePrivileges_UserWithoutPrivilege_ThrowsAuthorizationException()
        {
            // arrange
            const int userId         = 1;
            var       repositoryMock = new Mock <IPrivilegesRepository>();

            repositoryMock
            .Setup(m => m.GetInstanceAdminPrivilegesAsync(userId))
            .ReturnsAsync(InstanceAdminPrivileges.ManageUsers);
            var manager = new PrivilegesManager(repositoryMock.Object);

            // act
            await manager.Demand(userId, InstanceAdminPrivileges.ManageUsers | InstanceAdminPrivileges.AssignAdminRoles);
        }
Beispiel #4
0
        public async Task DemandAny_UserWithoutAnyPrivilege_ThrowsAuthorizationException()
        {
            // arrange
            const int userId         = 1;
            const int projectId      = 1;
            var       repositoryMock = new Mock <IPrivilegesRepository>();

            repositoryMock
            .Setup(m => m.GetInstanceAdminPrivilegesAsync(userId))
            .ReturnsAsync(InstanceAdminPrivileges.ViewUsers);
            repositoryMock
            .Setup(m => m.GetProjectAdminPermissionsAsync(userId, projectId))
            .ReturnsAsync(ProjectAdminPrivileges.ViewGroupsAndRoles);

            var manager = new PrivilegesManager(repositoryMock.Object);

            // act
            await
            manager.DemandAny(userId, projectId, InstanceAdminPrivileges.AccessAllProjectsAdmin,
                              ProjectAdminPrivileges.ManageGroupsAndRoles);

            // Exception
        }