Ignore the FileSecurityTest.EveryoneMayNotBeOwner test when running as
authorNiklas Therning <niklas@therning.org>
Mon, 19 Sep 2016 09:01:41 +0000 (11:01 +0200)
committerNiklas Therning <niklas@therning.org>
Mon, 19 Sep 2016 09:08:27 +0000 (11:08 +0200)
Administrator

This test fails when running as Administrator since Administrator CAN set the
owner to Everyone. This patch ignores the test when running as Administrator.
The check has to be done after the File.SetAccessControl() call that is
expected to fail since when we aren't running as Administrator the IsInRole()
check will trigger UAC which we need to prevent when possible.

mcs/class/corlib/Test/System.Security.AccessControl/FileSecurityTest.cs

index 0e5487efdd22228ca182d2520ef3fb1f0b203802..0723d17161109a03f0d53cf8cc7b7ff7a4527f79 100644 (file)
@@ -98,6 +98,13 @@ namespace MonoTests.System.Security.AccessControl
                                security = File.GetAccessControl (path);
                                security.SetOwner (new SecurityIdentifier ("WD"));
                                File.SetAccessControl (path, security);
+                               // If we don't get an InvalidOperationException it could be that we are running
+                               // with administrator privileges. Don't fail the test if that is the case.
+                               WindowsIdentity identity = WindowsIdentity.GetCurrent ();
+                               WindowsPrincipal principal = new WindowsPrincipal (identity);
+                               if (principal.IsInRole (WindowsBuiltInRole.Administrator)) {
+                                       Assert.Ignore ("Running as Administrator");
+                               }
                        } finally {
                                File.Delete (path);
                        }