public void DoNotChangeNTFSPermissions_WhenSetExclusivePermissionsIsNotAsk() { // Arrange DirectoryInfo folderToCreate = new DirectoryInfo(@"E:\Pst Backup\Test Files\FolderToCreate"); DirectorySecurity parentSecurity; DirectorySecurity folderSecurity; // Act if (folderToCreate.Exists) { folderToCreate.Delete(true); folderToCreate.Refresh(); Assert.IsFalse(folderToCreate.Exists); } SUT.CreateDestinationFolder(folderToCreate.FullName, false, String.Empty, String.Empty); parentSecurity = new DirectorySecurity(folderToCreate.Parent.FullName, AccessControlSections.All); folderSecurity = new DirectorySecurity(folderToCreate.FullName, AccessControlSections.All); AuthorizationRuleCollection childSecCollection = folderSecurity.GetAccessRules(true, true, typeof(System.Security.Principal.SecurityIdentifier)); AuthorizationRuleCollection parentSecCollection = parentSecurity.GetAccessRules(true, true, typeof(System.Security.Principal.SecurityIdentifier)); // Assert Assert.IsFalse(folderSecurity.AreAccessRulesProtected); Assert.AreEqual(parentSecCollection.Count, childSecCollection.Count); foreach (AuthorizationRule rule in childSecCollection) { Assert.IsTrue(rule.IsInherited); } }
public void CreateTheFolderWithPersonnalizedNtfsPermissions_WhenSetExclusivePermissionsIsAsk() { // Arrange DirectoryInfo folderToCreate = new DirectoryInfo(@"E:\Pst Backup\Test Files\FolderToCreate"); DirectorySecurity folderSecurity; string securityDescriptor; // Act if (folderToCreate.Exists) { folderToCreate.Delete(true); folderToCreate.Refresh(); Assert.IsFalse(folderToCreate.Exists); } SUT.CreateDestinationFolder(folderToCreate.FullName, true, @"MCSA\SConnor", @"MCSA\SVaughan"); folderSecurity = new DirectorySecurity(folderToCreate.FullName, AccessControlSections.All); securityDescriptor = folderSecurity.GetSecurityDescriptorSddlForm(AccessControlSections.All); // Assert Assert.IsTrue(folderSecurity.AreAccessRulesProtected); Assert.IsTrue(securityDescriptor.Contains("(A;OICI;FA;;;SY)")); Assert.IsTrue(securityDescriptor.Contains("(A;OICI;0x1301bf;;;S-1-5-21-2569095476-1252395535-2594552870-1105)")); Assert.IsTrue(securityDescriptor.Contains("(A;OICI;FA;;;S-1-5-21-2569095476-1252395535-2594552870-1608)")); Assert.IsTrue(securityDescriptor.Contains("(A;OICI;0x1301bf;;;S-1-5-21-2569095476-1252395535-2594552870-1609)")); }
public void CreateTheFolder_WhenParentFolderExists() { // Arrange DirectoryInfo folderToCreate = new DirectoryInfo(@"E:\Pst Backup\Test Files\FolderToCreate"); // Act if (folderToCreate.Exists) { folderToCreate.Delete(true); folderToCreate.Refresh(); Assert.IsFalse(folderToCreate.Exists); } SUT.CreateDestinationFolder(folderToCreate.FullName, false, String.Empty, String.Empty); folderToCreate.Refresh(); // Assert Assert.IsTrue(folderToCreate.Exists); }