From bf06441eadff2748bb720785f4c3ef95245259c2 Mon Sep 17 00:00:00 2001 From: Jay Krell Date: Wed, 20 Jun 2018 03:31:29 -0700 Subject: [PATCH] Ignore GetAttributes_ReadOnly and Create_Path_ReadOnly when running as root. (#8904) root can still write to a file even if the readonly bit is set. --- mcs/class/corlib/Test/System.IO/FileTest.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mcs/class/corlib/Test/System.IO/FileTest.cs b/mcs/class/corlib/Test/System.IO/FileTest.cs index cae81469ae4..943ad91c6b9 100644 --- a/mcs/class/corlib/Test/System.IO/FileTest.cs +++ b/mcs/class/corlib/Test/System.IO/FileTest.cs @@ -146,9 +146,26 @@ namespace MonoTests.System.IO } } + internal const string LIBC = "libc"; + // geteuid(2) + // uid_t geteuid(void); + [DllImport (LIBC, SetLastError=true)] + static extern uint geteuid (); + + static bool RunningAsRoot // FIXME? + { + get { + //return RunningOnUnix && System.Security.WindowsIdentity.GetCurrentToken () == IntPtr.Zero; + return RunningOnUnix && geteuid () == 0; + } + } + [Test] public void Create_Path_ReadOnly () { + if (RunningAsRoot) // FIXME? + Assert.Ignore ("Setting readonly in Mono does not block root writes."); + string path = Path.Combine (tmpFolder, "foo"); File.Create (path).Close (); File.SetAttributes (path, FileAttributes.ReadOnly); @@ -169,6 +186,8 @@ namespace MonoTests.System.IO [Test] public void Create_Path_Whitespace () { + // FIXME? This is valid on Unix and can work on Windows. + // This test and Mono have in mind an incorrect low common denominator. try { File.Create (" "); Assert.Fail ("#1"); @@ -619,6 +638,9 @@ namespace MonoTests.System.IO [Test] public void GetAttributes_ReadOnly () { + if (RunningAsRoot) // FIXME? + Assert.Ignore ("Setting readonly in Mono does not block root writes."); + FileAttributes attrs; string path = Path.Combine (tmpFolder, "GetAttributes.tmp"); -- 2.11.4.GIT