Repository: mesos Updated Branches: refs/heads/master fb3a337c2 -> 6d1c34d8c
Updated CRAMMD5Authentication tests to additionally run against test authenticator module. Review: https://reviews.apache.org/r/27619 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/06fda885 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/06fda885 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/06fda885 Branch: refs/heads/master Commit: 06fda88522205cc7441f735be5943e3010c2406d Parents: fb3a337 Author: Till Toenshoff <[email protected]> Authored: Wed Nov 12 17:34:20 2014 -0800 Committer: Adam B <[email protected]> Committed: Wed Nov 12 17:34:20 2014 -0800 ---------------------------------------------------------------------- src/authentication/cram_md5/authenticator.hpp | 12 +++++ src/tests/cram_md5_authentication_tests.cpp | 61 +++++++++++++++------- src/tests/module.cpp | 24 +++++++++ src/tests/module.hpp | 10 +++- 4 files changed, 86 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/06fda885/src/authentication/cram_md5/authenticator.hpp ---------------------------------------------------------------------- diff --git a/src/authentication/cram_md5/authenticator.hpp b/src/authentication/cram_md5/authenticator.hpp index a23bf5d..d739a02 100644 --- a/src/authentication/cram_md5/authenticator.hpp +++ b/src/authentication/cram_md5/authenticator.hpp @@ -53,7 +53,11 @@ class CRAMMD5AuthenticatorProcess; class CRAMMD5Authenticator : public Authenticator { public: + // Factory to allow for typed tests. + static Try<Authenticator*> create(); + CRAMMD5Authenticator(); + virtual ~CRAMMD5Authenticator(); virtual void initialize(const process::UPID& clientPid); @@ -435,6 +439,7 @@ private: Option<std::string> principal; }; + namespace secrets { // Loads secrets (principal -> secret) into the in-memory auxiliary @@ -465,6 +470,13 @@ void load(const Credentials& credentials) } // namespace secrets { + +Try<Authenticator*> CRAMMD5Authenticator::create() +{ + return new CRAMMD5Authenticator(); +} + + CRAMMD5Authenticator::CRAMMD5Authenticator() : process(NULL) {} http://git-wip-us.apache.org/repos/asf/mesos/blob/06fda885/src/tests/cram_md5_authentication_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/cram_md5_authentication_tests.cpp b/src/tests/cram_md5_authentication_tests.cpp index f91f1f9..d21157d 100644 --- a/src/tests/cram_md5_authentication_tests.cpp +++ b/src/tests/cram_md5_authentication_tests.cpp @@ -16,7 +16,6 @@ * limitations under the License. */ -#include <map> #include <string> #include <process/gmock.hpp> @@ -26,16 +25,20 @@ #include <stout/gtest.hpp> +#include "authentication/authenticator.hpp" + #include "authentication/cram_md5/authenticatee.hpp" #include "authentication/cram_md5/authenticator.hpp" +#include "module/authenticator.hpp" + #include "tests/mesos.hpp" +#include "tests/module.hpp" using namespace mesos::internal::tests; using namespace process; -using std::map; using std::string; using testing::_; @@ -45,7 +48,16 @@ namespace mesos { namespace internal { namespace cram_md5 { -TEST(CRAMMD5Authentication, success) +template <typename T> +class CRAMMD5Authentication : public MesosTest {}; + +typedef ::testing::Types<CRAMMD5Authenticator, + tests::Module<Authenticator, TestCRAMMD5Authenticator>> + AuthenticatorTypes; + +TYPED_TEST_CASE(CRAMMD5Authentication, AuthenticatorTypes); + +TYPED_TEST(CRAMMD5Authentication, success) { // Launch a dummy process (somebody to send the AuthenticateMessage). UPID pid = spawn(new ProcessBase(), true); @@ -69,21 +81,24 @@ TEST(CRAMMD5Authentication, success) AWAIT_READY(message); - CRAMMD5Authenticator authenticator; - authenticator.initialize(message.get().from); + Try<Authenticator*> authenticator = TypeParam::create(); + CHECK_SOME(authenticator); - Future<Option<string>> principal = authenticator.authenticate(); + authenticator.get()->initialize(message.get().from); + + Future<Option<string>> principal = authenticator.get()->authenticate(); AWAIT_EQ(true, client); AWAIT_READY(principal); EXPECT_SOME_EQ("benh", principal.get()); terminate(pid); + delete authenticator.get(); } // Bad password should return an authentication failure. -TEST(CRAMMD5Authentication, failed1) +TYPED_TEST(CRAMMD5Authentication, failed1) { // Launch a dummy process (somebody to send the AuthenticateMessage). UPID pid = spawn(new ProcessBase(), true); @@ -107,21 +122,24 @@ TEST(CRAMMD5Authentication, failed1) AWAIT_READY(message); - CRAMMD5Authenticator authenticator; - authenticator.initialize(message.get().from); + Try<Authenticator*> authenticator = TypeParam::create(); + CHECK_SOME(authenticator); + + authenticator.get()->initialize(message.get().from); - Future<Option<string>> server = authenticator.authenticate(); + Future<Option<string>> server = authenticator.get()->authenticate(); AWAIT_EQ(false, client); AWAIT_READY(server); EXPECT_NONE(server.get()); terminate(pid); + delete authenticator.get(); } // No user should return an authentication failure. -TEST(CRAMMD5Authentication, failed2) +TYPED_TEST(CRAMMD5Authentication, failed2) { // Launch a dummy process (somebody to send the AuthenticateMessage). UPID pid = spawn(new ProcessBase(), true); @@ -145,23 +163,26 @@ TEST(CRAMMD5Authentication, failed2) AWAIT_READY(message); - CRAMMD5Authenticator authenticator; - authenticator.initialize(message.get().from); + Try<Authenticator*> authenticator = TypeParam::create(); + CHECK_SOME(authenticator); - Future<Option<string>> server = authenticator.authenticate(); + authenticator.get()->initialize(message.get().from); + + Future<Option<string>> server = authenticator.get()->authenticate(); AWAIT_EQ(false, client); AWAIT_READY(server); EXPECT_NONE(server.get()); terminate(pid); + delete authenticator.get(); } // This test verifies that the pending future returned by // 'Authenticator::authenticate()' is properly failed when the Authenticator is // destructed in the middle of authentication. -TEST(CRAMMD5Authentication, AuthenticatorDestructionRace) +TYPED_TEST(CRAMMD5Authentication, AuthenticatorDestructionRace) { // Launch a dummy process (somebody to send the AuthenticateMessage). UPID pid = spawn(new ProcessBase(), true); @@ -185,15 +206,17 @@ TEST(CRAMMD5Authentication, AuthenticatorDestructionRace) AWAIT_READY(message); - CRAMMD5Authenticator* authenticator = new CRAMMD5Authenticator(); - authenticator->initialize(message.get().from); + Try<Authenticator*> authenticator = TypeParam::create(); + CHECK_SOME(authenticator); + + authenticator.get()->initialize(message.get().from); // Drop the AuthenticationStepMessage from authenticator to keep // the authentication from getting completed. Future<AuthenticationStepMessage> authenticationStepMessage = DROP_PROTOBUF(AuthenticationStepMessage(), _, _); - Future<Option<string>> principal = authenticator->authenticate(); + Future<Option<string>> principal = authenticator.get()->authenticate(); AWAIT_READY(authenticationStepMessage); @@ -204,7 +227,7 @@ TEST(CRAMMD5Authentication, AuthenticatorDestructionRace) ASSERT_TRUE(principal.isPending()); // Now delete the authenticator. - delete authenticator; + delete authenticator.get(); // The future should be failed at this point. AWAIT_FAILED(principal); http://git-wip-us.apache.org/repos/asf/mesos/blob/06fda885/src/tests/module.cpp ---------------------------------------------------------------------- diff --git a/src/tests/module.cpp b/src/tests/module.cpp index 482ed22..faba337 100644 --- a/src/tests/module.cpp +++ b/src/tests/module.cpp @@ -69,6 +69,27 @@ static void addIsolatorModules(Modules& modules) } +// Add available Authenticator modules. +static void addAuthenticatorModule(Modules& modules) +{ + const string libraryPath = path::join( + tests::flags.build_dir, + "src", + ".libs", + os::libraries::expandName("testauthentication")); + + // Now add our test authenticator module. + Modules::Library* library = modules.add_libraries(); + library->set_file(libraryPath); + + // To add a new module from this library, create a new ModuleID enum + // and tie it with a module name. + addModule(library, + TestCRAMMD5Authenticator, + "org_apache_mesos_TestCRAMMD5Authenticator"); +} + + Try<Nothing> tests::initModules(const Option<Modules>& modules) { // First get the user provided modules. @@ -80,6 +101,9 @@ Try<Nothing> tests::initModules(const Option<Modules>& modules) // Add isolator modules from testisolator library. addIsolatorModules(mergedModules); + // Add authenticator module from testauthentication library. + addAuthenticatorModule(mergedModules); + return ModuleManager::load(mergedModules); } http://git-wip-us.apache.org/repos/asf/mesos/blob/06fda885/src/tests/module.hpp ---------------------------------------------------------------------- diff --git a/src/tests/module.hpp b/src/tests/module.hpp index 7970c28..fc11adf 100644 --- a/src/tests/module.hpp +++ b/src/tests/module.hpp @@ -40,7 +40,8 @@ namespace tests { enum ModuleID { TestMemIsolator, - TestCpuIsolator + TestCpuIsolator, + TestCRAMMD5Authenticator }; @@ -55,7 +56,7 @@ class Module public: // Create is used by the type_param'ed tests. T here denotes the // module type, whereas N denotes the module name. - static Try<T*> create(logging::Flags flags) + static Try<T*> create() { Try<std::string> moduleName = getModuleName(N); if (moduleName.isError()) { @@ -63,6 +64,11 @@ public: } return mesos::modules::ModuleManager::create<T>(moduleName.get()); } + + static Try<T*> create(logging::Flags flags) + { + return create(); + } }; } // namespace tests {
