You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by me...@apache.org on 2014/11/13 03:04:36 UTC

[1/2] mesos git commit: Updated CRAMMD5Authentication tests to additionally run against test authenticator module.

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 <to...@me.com>
Authored: Wed Nov 12 17:34:20 2014 -0800
Committer: Adam B <ad...@mesosphere.io>
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 {


[2/2] mesos git commit: Updated CRAMMD5Authentication tests to additionally run against test authenticatee module.

Posted by me...@apache.org.
Updated CRAMMD5Authentication tests to additionally run against test authenticatee module.

CRAMMD5Authentication tests now cover all default and modularized
authenticator/authenticatee combinations.
Also adds a test for missing credential for the authenticatee.

Review: https://reviews.apache.org/r/27651


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/6d1c34d8
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/6d1c34d8
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/6d1c34d8

Branch: refs/heads/master
Commit: 6d1c34d8c5564d93123a7a59255bc6a415266a0e
Parents: 06fda88
Author: Till Toenshoff <to...@me.com>
Authored: Wed Nov 12 17:49:30 2014 -0800
Committer: Adam B <ad...@mesosphere.io>
Committed: Wed Nov 12 17:49:30 2014 -0800

----------------------------------------------------------------------
 src/tests/cram_md5_authentication_tests.cpp | 71 ++++++++++++++++++------
 src/tests/module.cpp                        | 13 +++--
 src/tests/module.hpp                        |  1 +
 3 files changed, 63 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/6d1c34d8/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 d21157d..a356aa1 100644
--- a/src/tests/cram_md5_authentication_tests.cpp
+++ b/src/tests/cram_md5_authentication_tests.cpp
@@ -25,11 +25,13 @@
 
 #include <stout/gtest.hpp>
 
+#include "authentication/authenticatee.hpp"
 #include "authentication/authenticator.hpp"
 
 #include "authentication/cram_md5/authenticatee.hpp"
 #include "authentication/cram_md5/authenticator.hpp"
 
+#include "module/authenticatee.hpp"
 #include "module/authenticator.hpp"
 
 #include "tests/mesos.hpp"
@@ -51,11 +53,30 @@ namespace cram_md5 {
 template <typename T>
 class CRAMMD5Authentication : public MesosTest {};
 
-typedef ::testing::Types<CRAMMD5Authenticator,
-                         tests::Module<Authenticator, TestCRAMMD5Authenticator>>
-  AuthenticatorTypes;
-
-TYPED_TEST_CASE(CRAMMD5Authentication, AuthenticatorTypes);
+template <typename T, typename U>
+class Authentication
+{
+public:
+  typedef T TypeAuthenticatee;
+  typedef U TypeAuthenticator;
+};
+
+// Test all authentication variants against each other.
+// default authenticatee      <> default authenticator
+// modularized authenticatee  <> default authenticator
+// default authenticatee      <> modularized authenticator
+// modularized authenticatee  <> modularized authenticator
+typedef ::testing::Types<
+  Authentication<CRAMMD5Authenticatee, CRAMMD5Authenticator>,
+  Authentication<tests::Module<Authenticatee, TestCRAMMD5Authenticatee>,
+                 CRAMMD5Authenticator>,
+  Authentication<CRAMMD5Authenticatee,
+                 tests::Module<Authenticator, TestCRAMMD5Authenticator>>,
+  Authentication<tests::Module<Authenticatee, TestCRAMMD5Authenticatee>,
+                 tests::Module<Authenticator, TestCRAMMD5Authenticator>>>
+  AuthenticationTypes;
+
+TYPED_TEST_CASE(CRAMMD5Authentication, AuthenticationTypes);
 
 TYPED_TEST(CRAMMD5Authentication, success)
 {
@@ -76,12 +97,15 @@ TYPED_TEST(CRAMMD5Authentication, success)
   Future<Message> message =
     FUTURE_MESSAGE(Eq(AuthenticateMessage().GetTypeName()), _, _);
 
-  CRAMMD5Authenticatee authenticatee;
-  Future<bool> client = authenticatee.authenticate(pid, UPID(), credential1);
+  Try<Authenticatee*> authenticatee = TypeParam::TypeAuthenticatee::create();
+  CHECK_SOME(authenticatee);
+
+  Future<bool> client =
+    authenticatee.get()->authenticate(pid, UPID(), credential1);
 
   AWAIT_READY(message);
 
-  Try<Authenticator*> authenticator = TypeParam::create();
+  Try<Authenticator*> authenticator = TypeParam::TypeAuthenticator::create();
   CHECK_SOME(authenticator);
 
   authenticator.get()->initialize(message.get().from);
@@ -94,6 +118,7 @@ TYPED_TEST(CRAMMD5Authentication, success)
 
   terminate(pid);
   delete authenticator.get();
+  delete authenticatee.get();
 }
 
 
@@ -117,12 +142,15 @@ TYPED_TEST(CRAMMD5Authentication, failed1)
   Future<Message> message =
     FUTURE_MESSAGE(Eq(AuthenticateMessage().GetTypeName()), _, _);
 
-  CRAMMD5Authenticatee authenticatee;
-  Future<bool> client = authenticatee.authenticate(pid, UPID(), credential1);
+  Try<Authenticatee*> authenticatee = TypeParam::TypeAuthenticatee::create();
+  CHECK_SOME(authenticatee);
+
+  Future<bool> client =
+    authenticatee.get()->authenticate(pid, UPID(), credential1);
 
   AWAIT_READY(message);
 
-  Try<Authenticator*> authenticator = TypeParam::create();
+  Try<Authenticator*> authenticator = TypeParam::TypeAuthenticator::create();
   CHECK_SOME(authenticator);
 
   authenticator.get()->initialize(message.get().from);
@@ -135,6 +163,7 @@ TYPED_TEST(CRAMMD5Authentication, failed1)
 
   terminate(pid);
   delete authenticator.get();
+  delete authenticatee.get();
 }
 
 
@@ -158,12 +187,15 @@ TYPED_TEST(CRAMMD5Authentication, failed2)
   Future<Message> message =
     FUTURE_MESSAGE(Eq(AuthenticateMessage().GetTypeName()), _, _);
 
-  CRAMMD5Authenticatee authenticatee;
-  Future<bool> client = authenticatee.authenticate(pid, UPID(), credential1);
+  Try<Authenticatee*> authenticatee = TypeParam::TypeAuthenticatee::create();
+  CHECK_SOME(authenticatee);
+
+  Future<bool> client =
+    authenticatee.get()->authenticate(pid, UPID(), credential1);
 
   AWAIT_READY(message);
 
-  Try<Authenticator*> authenticator = TypeParam::create();
+  Try<Authenticator*> authenticator = TypeParam::TypeAuthenticator::create();
   CHECK_SOME(authenticator);
 
   authenticator.get()->initialize(message.get().from);
@@ -176,6 +208,7 @@ TYPED_TEST(CRAMMD5Authentication, failed2)
 
   terminate(pid);
   delete authenticator.get();
+  delete authenticatee.get();
 }
 
 
@@ -201,12 +234,15 @@ TYPED_TEST(CRAMMD5Authentication, AuthenticatorDestructionRace)
   Future<Message> message =
     FUTURE_MESSAGE(Eq(AuthenticateMessage().GetTypeName()), _, _);
 
-  CRAMMD5Authenticatee authenticatee;
-  Future<bool> client = authenticatee.authenticate(pid, UPID(), credential1);
+  Try<Authenticatee*> authenticatee = TypeParam::TypeAuthenticatee::create();
+  CHECK_SOME(authenticatee);
+
+  Future<bool> client =
+    authenticatee.get()->authenticate(pid, UPID(), credential1);
 
   AWAIT_READY(message);
 
-  Try<Authenticator*> authenticator = TypeParam::create();
+  Try<Authenticator*> authenticator = TypeParam::TypeAuthenticator::create();
   CHECK_SOME(authenticator);
 
   authenticator.get()->initialize(message.get().from);
@@ -233,6 +269,7 @@ TYPED_TEST(CRAMMD5Authentication, AuthenticatorDestructionRace)
   AWAIT_FAILED(principal);
 
   terminate(pid);
+  delete authenticatee.get();
 }
 
 } // namespace cram_md5 {

http://git-wip-us.apache.org/repos/asf/mesos/blob/6d1c34d8/src/tests/module.cpp
----------------------------------------------------------------------
diff --git a/src/tests/module.cpp b/src/tests/module.cpp
index faba337..6cec1cb 100644
--- a/src/tests/module.cpp
+++ b/src/tests/module.cpp
@@ -69,8 +69,8 @@ static void addIsolatorModules(Modules& modules)
 }
 
 
-// Add available Authenticator modules.
-static void addAuthenticatorModule(Modules& modules)
+// Add available Authentication modules.
+static void addAuthenticationModules(Modules& modules)
 {
   const string libraryPath = path::join(
       tests::flags.build_dir,
@@ -78,13 +78,16 @@ static void addAuthenticatorModule(Modules& modules)
       ".libs",
       os::libraries::expandName("testauthentication"));
 
-  // Now add our test authenticator module.
+  // Now add our test authentication modules.
   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,
+            TestCRAMMD5Authenticatee,
+            "org_apache_mesos_TestCRAMMD5Authenticatee");
+  addModule(library,
             TestCRAMMD5Authenticator,
             "org_apache_mesos_TestCRAMMD5Authenticator");
 }
@@ -101,8 +104,8 @@ Try<Nothing> tests::initModules(const Option<Modules>& modules)
   // Add isolator modules from testisolator library.
   addIsolatorModules(mergedModules);
 
-  // Add authenticator module from testauthentication library.
-  addAuthenticatorModule(mergedModules);
+  // Add authentication modules from testauthentication library.
+  addAuthenticationModules(mergedModules);
 
   return ModuleManager::load(mergedModules);
 }

http://git-wip-us.apache.org/repos/asf/mesos/blob/6d1c34d8/src/tests/module.hpp
----------------------------------------------------------------------
diff --git a/src/tests/module.hpp b/src/tests/module.hpp
index fc11adf..bc1a37d 100644
--- a/src/tests/module.hpp
+++ b/src/tests/module.hpp
@@ -41,6 +41,7 @@ enum ModuleID
 {
   TestMemIsolator,
   TestCpuIsolator,
+  TestCRAMMD5Authenticatee,
   TestCRAMMD5Authenticator
 };