public void SecurityServiceBase_Remove_ResourceIDDoesExist_PermissionsRemoved()
        {
            //------------Setup for test--------------------------
            var toBeRemovedID = Guid.NewGuid();
            var resourceID    = toBeRemovedID;
            var permissions   = new List <WindowsGroupPermission>
            {
                new WindowsGroupPermission {
                    ResourceID = Guid.NewGuid(), Permissions = AuthorizationContext.View.ToPermissions()
                },
                new WindowsGroupPermission {
                    ResourceID = resourceID, Permissions = AuthorizationContext.View.ToPermissions()
                },
                new WindowsGroupPermission {
                    ResourceID = resourceID, Permissions = AuthorizationContext.Execute.ToPermissions()
                }
            };

            var securityService = new TestSecurityServiceBase {
                ReadPermissionsResult = permissions
            };

            securityService.Read();

            var comparer = new WindowsGroupPermissionEqualityComparer();

            //------------Execute Test---------------------------
            securityService.Remove(toBeRemovedID);

            //------------Assert Results-------------------------
            Assert.AreEqual(1, securityService.Permissions.Count);
            Assert.IsTrue(comparer.Equals(permissions[0], securityService.Permissions[0]));
        }
Ejemplo n.º 2
0
        public void SettingsRead_Execute_SecurityReadDoesNotThrowException_HasErrorsIsFalseAndSecurityPermissionsAreAssigned()
        {
            //------------Setup for test--------------------------
            var serializer          = new Dev2JsonSerializer();
            var securityPermissions = new List <WindowsGroupPermission>
            {
                new WindowsGroupPermission {
                    IsServer = true, WindowsGroup = "TestGroup", Permissions = AuthorizationContext.DeployFrom.ToPermissions()
                },
                new WindowsGroupPermission {
                    IsServer = true, WindowsGroup = "NETWORK SERVICE", Permissions = AuthorizationContext.DeployTo.ToPermissions()
                }
            };

            var securitySettingsTO = new SecuritySettingsTO(securityPermissions);

            var securityRead = new Func <IEsbManagementEndpoint>(() =>
            {
                var endpoint = new Mock <IEsbManagementEndpoint>();
                endpoint.Setup(e => e.Execute(It.IsAny <Dictionary <string, StringBuilder> >(), It.IsAny <IWorkspace>()))
                .Returns(new Dev2JsonSerializer().SerializeToBuilder(securitySettingsTO));

                return(endpoint.Object);
            });
            var mockPerfCounterRepo = new Mock <IPerformanceCounterRepository>();

            mockPerfCounterRepo.Setup(repository => repository.Counters).Returns(new PerformanceCounterTo());
            CustomContainer.Register(mockPerfCounterRepo.Object);
            var settingsRead = new TestSettingsRead(securityRead);

            //------------Execute Test---------------------------
            var jsonPermissions = settingsRead.Execute(null, null);
            var settings        = serializer.Deserialize <Settings>(jsonPermissions.ToString());

            //------------Assert Results-------------------------
            Assert.IsNotNull(settings);
            Assert.IsNotNull(settings.Security);
            Assert.IsFalse(settings.HasError);

            var comparer = new WindowsGroupPermissionEqualityComparer();

            Assert.AreEqual(2, settings.Security.WindowsGroupPermissions.Count);

            for (var i = 0; i < securityPermissions.Count; i++)
            {
                var result = comparer.Equals(securityPermissions[i], settings.Security.WindowsGroupPermissions[i]);
                Assert.IsTrue(result);
            }
        }
        public void SettingsRead_Execute_SecurityReadDoesNotThrowException_HasErrorsIsFalseAndSecurityPermissionsAreAssigned()
        {
            //------------Setup for test--------------------------
            var securityPermissions = new List<WindowsGroupPermission>
            {
                new WindowsGroupPermission { IsServer = true, WindowsGroup = "TestGroup", Permissions = AuthorizationContext.DeployFrom.ToPermissions() },
                new WindowsGroupPermission { IsServer = true, WindowsGroup = "NETWORK SERVICE", Permissions = AuthorizationContext.DeployTo.ToPermissions() }
            };

            var securitySettingsTO = new SecuritySettingsTO(securityPermissions);

            var securityRead = new Func<IEsbManagementEndpoint>(() =>
            {
                var endpoint = new Mock<IEsbManagementEndpoint>();
                endpoint.Setup(e => e.Execute(It.IsAny<Dictionary<string, StringBuilder>>(), It.IsAny<IWorkspace>()))
                    .Returns(new Dev2JsonSerializer().SerializeToBuilder(securitySettingsTO));

                return endpoint.Object;
            });

            var settingsRead = new TestSettingsRead(securityRead);

            //------------Execute Test---------------------------
            var jsonPermissions = settingsRead.Execute(null, null);
            var settings = JsonConvert.DeserializeObject<Settings>(jsonPermissions.ToString());

            //------------Assert Results-------------------------
            Assert.IsNotNull(settings);
            Assert.IsNotNull(settings.Security);
            Assert.IsFalse(settings.HasError);

            var comparer = new WindowsGroupPermissionEqualityComparer();
            Assert.AreEqual(2, settings.Security.WindowsGroupPermissions.Count);

            for(var i = 0; i < securityPermissions.Count; i++)
            {
                var result = comparer.Equals(securityPermissions[i], settings.Security.WindowsGroupPermissions[i]);
                Assert.IsTrue(result);
            }
        }
Ejemplo n.º 4
0
        public void SecurityServiceBase_Remove_ResourceIDDoesExist_PermissionsRemoved()
        {
            //------------Setup for test--------------------------
            var toBeRemovedID = Guid.NewGuid();
            var resourceID = toBeRemovedID;
            var permissions = new List<WindowsGroupPermission>
            {
                new WindowsGroupPermission { ResourceID = Guid.NewGuid(), Permissions = AuthorizationContext.View.ToPermissions() },
                new WindowsGroupPermission { ResourceID = resourceID, Permissions = AuthorizationContext.View.ToPermissions() },
                new WindowsGroupPermission { ResourceID = resourceID, Permissions = AuthorizationContext.Execute.ToPermissions() }
            };

            var securityService = new TestSecurityServiceBase { ReadPermissionsResult = permissions };
            securityService.Read();

            var comparer = new WindowsGroupPermissionEqualityComparer();

            //------------Execute Test---------------------------
            securityService.Remove(toBeRemovedID);

            //------------Assert Results-------------------------
            Assert.AreEqual(1, securityService.Permissions.Count);
            Assert.IsTrue(comparer.Equals(permissions[0], securityService.Permissions[0]));
        }