public static int TestStartWithUserName() { using (ProcessTests testObject = new ProcessTests()) { string realUserName; if (geteuid() == 0) { realUserName = Environment.GetEnvironmentVariable("SUDO_USER"); } else { realUserName = Environment.UserName; } Assert.NotNull(realUserName); Assert.NotEqual("root", realUserName); using (Process p = testObject.CreateProcessPortable(GetCurrentEffectiveUserId)) { p.StartInfo.UserName = realUserName; Assert.True(p.Start()); p.WaitForExit(); // since the process was started with the current real user, even if this test // was run with 'sudo', the child process will be run as the normal real user. // Assert that the effective user of the child process was never 'root' // and was the real user of this process. Assert.NotEqual(0, p.ExitCode); } return(0); } }
public static int TestStartWithUserNameCannotElevate(string realUserName) { Assert.NotNull(realUserName); Assert.NotEqual("root", realUserName); using (ProcessTests testObject = new ProcessTests()) { using (Process p = testObject.CreateProcessPortable(SetEffectiveUserIdToRoot)) { p.StartInfo.UserName = realUserName; Assert.True(p.Start()); p.WaitForExit(); // seteuid(0) should not have succeeded, thus the exit code should be non-zero Assert.NotEqual(0, p.ExitCode); } return(0); } }