private void Directory_CreateDirectory_WithDirectorySecurity(bool isNetwork) { UnitTestConstants.PrintUnitTestHeader(isNetwork); Console.WriteLine(); var tempPath = System.IO.Path.GetTempPath(); if (isNetwork) { tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath); } using (var rootDir = new TemporaryDirectory(tempPath, MethodBase.GetCurrentMethod().Name)) { var folder = rootDir.RandomDirectoryFullPath; Console.WriteLine("\tInput Directory Path: [{0}]", folder); Console.WriteLine(); var pathExpected = rootDir.RandomDirectoryFullPath; var pathActual = rootDir.RandomDirectoryFullPath; var sid = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.WorldSid, null); var expectedDirectorySecurity = new System.Security.AccessControl.DirectorySecurity(); expectedDirectorySecurity.AddAccessRule(new System.Security.AccessControl.FileSystemAccessRule(sid, System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.AccessControlType.Allow)); expectedDirectorySecurity.AddAuditRule(new System.Security.AccessControl.FileSystemAuditRule(sid, System.Security.AccessControl.FileSystemRights.Read, System.Security.AccessControl.AuditFlags.Success)); using (new Alphaleonis.Win32.Security.PrivilegeEnabler(Alphaleonis.Win32.Security.Privilege.Security)) { var s1 = System.IO.Directory.CreateDirectory(pathExpected, expectedDirectorySecurity); var s2 = Alphaleonis.Win32.Filesystem.Directory.CreateDirectory(pathActual, expectedDirectorySecurity); var expected = s1.GetAccessControl().GetSecurityDescriptorSddlForm(System.Security.AccessControl.AccessControlSections.All); var actual = s2.GetAccessControl().GetSecurityDescriptorSddlForm(System.Security.AccessControl.AccessControlSections.All); Console.WriteLine("\tSystem.IO: {0}", expected); Console.WriteLine("\tAlphaFS : {0}", actual); Assert.AreEqual(expected, actual); } } Console.WriteLine(); }
private void Directory_CreateDirectory_WithDirectorySecurity(bool isNetwork) { using (var tempRoot = new TemporaryDirectory(isNetwork)) { var folder = tempRoot.RandomDirectoryFullPath; Console.WriteLine("Input Directory Path: [{0}]\n", folder); var pathExpected = tempRoot.RandomDirectoryFullPath; var pathActual = tempRoot.RandomDirectoryFullPath; var sid = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.WorldSid, null); var expectedDirectorySecurity = new System.Security.AccessControl.DirectorySecurity(); expectedDirectorySecurity.AddAccessRule(new System.Security.AccessControl.FileSystemAccessRule(sid, System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.AccessControlType.Allow)); expectedDirectorySecurity.AddAuditRule(new System.Security.AccessControl.FileSystemAuditRule(sid, System.Security.AccessControl.FileSystemRights.Read, System.Security.AccessControl.AuditFlags.Success)); using (new Alphaleonis.Win32.Security.PrivilegeEnabler(Alphaleonis.Win32.Security.Privilege.Security)) { var s1 = System.IO.Directory.CreateDirectory(pathExpected, expectedDirectorySecurity); var s2 = Alphaleonis.Win32.Filesystem.Directory.CreateDirectory(pathActual, expectedDirectorySecurity); var expected = s1.GetAccessControl().GetSecurityDescriptorSddlForm(System.Security.AccessControl.AccessControlSections.All); var actual = s2.GetAccessControl().GetSecurityDescriptorSddlForm(System.Security.AccessControl.AccessControlSections.All); Console.WriteLine("\tSystem.IO: {0}", expected); Console.WriteLine("\tAlphaFS : {0}", actual); Assert.AreEqual(expected, actual); } } Console.WriteLine(); }