diff --git a/test/test-spawn.c b/test/test-spawn.c index 3ab735f0..0e17892b 100644 --- a/test/test-spawn.c +++ b/test/test-spawn.c @@ -1536,37 +1536,6 @@ TEST_IMPL(spawn_setgids) { } #endif -TEST_IMPL(spawn_setgids_fails) { - int r; - uv_gid_t gids[1] = {0}; - - /* if root, become nobody. */ - uv_uid_t uid = getuid(); - if (uid == 0) { - struct passwd* pw; - pw = getpwnam("nobody"); - ASSERT(pw != NULL); - ASSERT(0 == setgid(pw->pw_gid)); - ASSERT(0 == setuid(pw->pw_uid)); - } - - init_process_options("spawn_helper1", fail_cb); - - options.flags |= UV_PROCESS_SETGROUPS; - options.gids = gids; - options.gids_size = 1; - - r = uv_spawn(uv_default_loop(), &process, &options); - ASSERT(r == UV_EPERM); - - r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); - ASSERT(r == 0); - - ASSERT(close_cb_called == 0); - - MAKE_VALGRIND_HAPPY(uv_default_loop()); - return 0; -} #ifndef _WIN32 TEST_IMPL(spawn_setuid_fails) { @@ -1663,6 +1632,39 @@ TEST_IMPL(spawn_setgid_fails) { MAKE_VALGRIND_HAPPY(uv_default_loop()); return 0; } + + +TEST_IMPL(spawn_setgids_fails) { + int r; + uv_gid_t gids[1] = {0}; + + /* if root, become nobody. */ + uv_uid_t uid = getuid(); + if (uid == 0) { + struct passwd* pw; + pw = getpwnam("nobody"); + ASSERT(pw != NULL); + ASSERT(0 == setgid(pw->pw_gid)); + ASSERT(0 == setuid(pw->pw_uid)); + } + + init_process_options("spawn_helper1", fail_cb); + + options.flags |= UV_PROCESS_SETGROUPS; + options.gids = gids; + options.gids_size = 1; + + r = uv_spawn(uv_default_loop(), &process, &options); + ASSERT(r == UV_EPERM); + + r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); + ASSERT(r == 0); + + ASSERT(close_cb_called == 0); + + MAKE_VALGRIND_HAPPY(uv_default_loop()); + return 0; +} #endif TEST_IMPL(spawn_affinity) { @@ -1826,6 +1828,27 @@ TEST_IMPL(spawn_setgid_fails) { MAKE_VALGRIND_HAPPY(uv_default_loop()); return 0; } + +TEST_IMPL(spawn_setgids_fails) { + int r; + uv_gid_t gids[1] = {0}; + init_process_options("spawn_helper1", exit_cb_unexpected); + + options.flags |= UV_PROCESS_SETGROUPS; + options.gids = gids; + options.gids_size = 1; + + r = uv_spawn(uv_default_loop(), &process, &options); + ASSERT_EQ(r, UV_ENOTSUP); + + r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); + ASSERT_OK(r); + + ASSERT_OK(close_cb_called); + + MAKE_VALGRIND_HAPPY(uv_default_loop()); + return 0; +} #endif