Example #1
0
        public void TestGetAccessControlSections()
        {
            var filename = Util.CreateNewFile(longPathDirectory);

            try
            {
                var          fi       = new FileInfo(filename);
                FileSecurity security = fi.GetAccessControl(AccessControlSections.Access);
                Assert.IsNotNull(security);
                Assert.AreEqual(typeof(FileSystemRights), security.AccessRightType);
                Assert.AreEqual(typeof(FileSystemAccessRule), security.AccessRuleType);
                Assert.AreEqual(typeof(FileSystemAuditRule), security.AuditRuleType);
                Assert.IsTrue(security.AreAccessRulesCanonical);
                Assert.IsTrue(security.AreAuditRulesCanonical);
                Assert.IsFalse(security.AreAccessRulesProtected);
                Assert.IsFalse(security.AreAuditRulesProtected);
                var securityGetAccessRules = security.GetAuditRules(true, true, typeof(System.Security.Principal.NTAccount)).Cast <FileSystemAccessRule>();
                Assert.AreEqual(0, securityGetAccessRules.Count());
                AuthorizationRuleCollection perm = security.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));
                var ntAccount             = new System.Security.Principal.NTAccount(System.Security.Principal.WindowsIdentity.GetCurrent().Name);
                FileSystemAccessRule rule = perm.Cast <FileSystemAccessRule>().SingleOrDefault(e => ntAccount == e.IdentityReference);
                Assert.IsNotNull(rule);
                Assert.IsTrue((rule.FileSystemRights & FileSystemRights.FullControl) != 0);
            }
            finally
            {
                File.Delete(filename);
            }
        }
Example #2
0
 public void TestGetAccessControlSections()
 {
     var filename = Util.CreateNewFile(longPathDirectory);
     try
     {
         var fi = new FileInfo(filename);
         FileSecurity security = fi.GetAccessControl(AccessControlSections.Access);
         Assert.IsNotNull(security);
         Assert.AreEqual(typeof(FileSystemRights), security.AccessRightType);
         Assert.AreEqual(typeof(FileSystemAccessRule), security.AccessRuleType);
         Assert.AreEqual(typeof(FileSystemAuditRule), security.AuditRuleType);
         Assert.IsTrue(security.AreAccessRulesCanonical);
         Assert.IsTrue(security.AreAuditRulesCanonical);
         Assert.IsFalse(security.AreAccessRulesProtected);
         Assert.IsFalse(security.AreAuditRulesProtected);
         var securityGetAccessRules = security.GetAuditRules(true, true, typeof(System.Security.Principal.NTAccount)).Cast<FileSystemAccessRule>();
         Assert.AreEqual(0, securityGetAccessRules.Count());
         AuthorizationRuleCollection perm = security.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));
         var ntAccount = new System.Security.Principal.NTAccount(System.Security.Principal.WindowsIdentity.GetCurrent().Name);
         FileSystemAccessRule rule = perm.Cast<FileSystemAccessRule>().SingleOrDefault(e => ntAccount == e.IdentityReference);
         Assert.IsNotNull(rule);
         Assert.IsTrue((rule.FileSystemRights & FileSystemRights.FullControl) != 0);
     }
     finally
     {
         File.Delete(filename);
     }
 }