Repository: mesos Updated Branches: refs/heads/master 24cb10a2d -> 75bf214e6
Changed RunTaskWithCommandInfoWithUser to not use shell. The 'nobody' user is restricted on some systems from shell access and broke the task.user tests (which have been disabled since then). With the command.shell field, the test can run the command directly. Review: https://reviews.apache.org/r/26894 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/75bf214e Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/75bf214e Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/75bf214e Branch: refs/heads/master Commit: 75bf214e605a5cff813c8992c33cf7bcb9fda0b4 Parents: 24cb10a Author: Niklas Nielsen <[email protected]> Authored: Fri Nov 21 13:30:18 2014 -0800 Committer: Niklas Q. Nielsen <[email protected]> Committed: Fri Nov 21 13:30:18 2014 -0800 ---------------------------------------------------------------------- src/Makefile.am | 5 +++++ src/tests/active_user_test_helper.cpp | 23 +++++++++++++++++++++++ src/tests/slave_tests.cpp | 18 +++++++++++++++--- 3 files changed, 43 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/75bf214e/src/Makefile.am ---------------------------------------------------------------------- diff --git a/src/Makefile.am b/src/Makefile.am index 1d4ba1c..2448db8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1176,6 +1176,11 @@ if OS_LINUX setns_test_helper_LDADD = libmesos.la endif +check_PROGRAMS += active-user-test-helper +active_user_test_helper_SOURCES = tests/active_user_test_helper.cpp +active_user_test_helper_CPPFLAGS = $(MESOS_CPPFLAGS) +active_user_test_helper_LDADD = libmesos.la + check_PROGRAMS += mesos-tests # Library containing an example module. http://git-wip-us.apache.org/repos/asf/mesos/blob/75bf214e/src/tests/active_user_test_helper.cpp ---------------------------------------------------------------------- diff --git a/src/tests/active_user_test_helper.cpp b/src/tests/active_user_test_helper.cpp new file mode 100644 index 0000000..c32d467 --- /dev/null +++ b/src/tests/active_user_test_helper.cpp @@ -0,0 +1,23 @@ +#include <iostream> +#include <string> + +#include <stout/os.hpp> + +// This helper program takes a an expected user. +// Returns 0 if the current username equals the expected username. +// Returns 1 otherwise. +int main(int argc, char **argv) { + if (argc < 2) { + std::cerr << "Usage: " << argv[0] << " <expected username>" << std::endl; + return 1; + } + + const std::string expected(argv[1]); + + Result<std::string> user = os::user(); + if (user.isSome() && user.get() == expected) { + return 0; + } + + return 1; +} http://git-wip-us.apache.org/repos/asf/mesos/blob/75bf214e/src/tests/slave_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/slave_tests.cpp b/src/tests/slave_tests.cpp index e048294..3b80ca9 100644 --- a/src/tests/slave_tests.cpp +++ b/src/tests/slave_tests.cpp @@ -563,9 +563,15 @@ TEST_F(SlaveTest, ROOT_RunTaskWithCommandInfoWithoutUser) CHECK_SOME(user) << "Failed to get current user name" << (user.isError() ? ": " + user.error() : ""); + const string helper = + path::join(tests::flags.build_dir, "src", "active-user-test-helper"); + // Command executor will run as user running test. CommandInfo command; - command.set_value("test `whoami` = " + user.get()); + command.set_shell(false); + command.set_value(helper); + command.add_arguments(helper); + command.add_arguments(user.get()); task.mutable_command()->MergeFrom(command); @@ -598,7 +604,7 @@ TEST_F(SlaveTest, ROOT_RunTaskWithCommandInfoWithoutUser) // specified user. We use (and assume the precense) of the // unprivileged 'nobody' user which should be available on both Linux // and Mac OS X. -TEST_F(SlaveTest, DISABLED_ROOT_RunTaskWithCommandInfoWithUser) +TEST_F(SlaveTest, ROOT_RunTaskWithCommandInfoWithUser) { // TODO(nnielsen): Introduce STOUT abstraction for user verification // instead of flat getpwnam call. @@ -647,9 +653,15 @@ TEST_F(SlaveTest, DISABLED_ROOT_RunTaskWithCommandInfoWithUser) task.mutable_slave_id()->MergeFrom(offers.get()[0].slave_id()); task.mutable_resources()->MergeFrom(offers.get()[0].resources()); + const string helper = + path::join(tests::flags.build_dir, "src", "active-user-test-helper"); + CommandInfo command; - command.set_value("test `whoami` = " + testUser); command.set_user(testUser); + command.set_shell(false); + command.set_value(helper); + command.add_arguments(helper); + command.add_arguments(testUser); task.mutable_command()->MergeFrom(command);
