From 5a3b8f9fce960704f347db338dda5746738dd6d0 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 2 Jul 2013 16:32:40 +0200 Subject: [PATCH] test: fix spawn_setgid_fails and spawn_setuid_fails Don't try to set a bogus UID or GID and expect to get a meaningful error. The test expected EPERM but SunOS returns EINVAL because the id is outside of the range of valid user/group ids. Try to switch to UID/GID 0. Give up privileges first if we're root, else the setuid/setgid system call will succeed when it's expected to fail. --- test/test-spawn.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/test-spawn.c b/test/test-spawn.c index afa8d918..ab71f551 100644 --- a/test/test-spawn.c +++ b/test/test-spawn.c @@ -815,14 +815,14 @@ TEST_IMPL(spawn_setuid_fails) { struct passwd* pw; pw = getpwnam("nobody"); ASSERT(pw != NULL); - r = setuid(pw->pw_uid); - ASSERT(r == 0); + ASSERT(0 == setgid(pw->pw_gid)); + ASSERT(0 == setuid(pw->pw_uid)); } init_process_options("spawn_helper1", exit_cb_failure_expected); options.flags |= UV_PROCESS_SETUID; - options.uid = (uv_uid_t) -42424242; + options.uid = 0; r = uv_spawn(uv_default_loop(), &process, options); ASSERT(r == 0); @@ -847,14 +847,14 @@ TEST_IMPL(spawn_setgid_fails) { struct passwd* pw; pw = getpwnam("nobody"); ASSERT(pw != NULL); - r = setuid(pw->pw_uid); - ASSERT(r == 0); + ASSERT(0 == setgid(pw->pw_gid)); + ASSERT(0 == setuid(pw->pw_uid)); } init_process_options("spawn_helper1", exit_cb_failure_expected); options.flags |= UV_PROCESS_SETGID; - options.gid = (uv_gid_t) -42424242; + options.gid = 0; r = uv_spawn(uv_default_loop(), &process, options); ASSERT(r == 0);