You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ka...@apache.org on 2016/04/26 19:26:58 UTC

[07/13] mesos git commit: Added a LoggingTest with authentication.

Added a LoggingTest with authentication.

The test `LoggingTest.ToggleAuthenticationEnabled`
is added in this patch.

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


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

Branch: refs/heads/master
Commit: 8ff034d3e85cd3109d76212ad5a04ac260526205
Parents: 6a6b999
Author: Greg Mann <gr...@mesosphere.io>
Authored: Tue Apr 26 10:43:18 2016 -0400
Committer: Kapil Arya <ka...@mesosphere.io>
Committed: Tue Apr 26 10:43:18 2016 -0400

----------------------------------------------------------------------
 src/tests/logging_tests.cpp | 70 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 69 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/8ff034d3/src/tests/logging_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/logging_tests.cpp b/src/tests/logging_tests.cpp
index 675a3f8..5412744 100644
--- a/src/tests/logging_tests.cpp
+++ b/src/tests/logging_tests.cpp
@@ -16,6 +16,8 @@
 
 #include <gmock/gmock.h>
 
+#include <mesos/authentication/http/basic_authenticator_factory.hpp>
+
 #include <process/future.hpp>
 #include <process/gtest.hpp>
 #include <process/http.hpp>
@@ -24,16 +26,61 @@
 
 #include "logging/logging.hpp"
 
+#include "tests/mesos.hpp"
+
+namespace authentication = process::http::authentication;
+
+using mesos::http::authentication::BasicAuthenticatorFactory;
+
 using process::http::BadRequest;
 using process::http::OK;
 using process::http::Response;
+using process::http::Unauthorized;
 
 namespace mesos {
 namespace internal {
 namespace tests {
 
+class LoggingTest : public mesos::internal::tests::MesosTest
+{
+protected:
+  void setBasicHttpAuthenticator(
+      const std::string& realm,
+      const Credentials& credentials)
+  {
+    Try<authentication::Authenticator*> authenticator =
+      BasicAuthenticatorFactory::create(realm, credentials);
+
+    ASSERT_SOME(authenticator);
+
+    // Add this realm to the set of realms which will be unset during teardown.
+    realms.insert(realm);
+
+    // Pass ownership of the authenticator to libprocess.
+    AWAIT_READY(authentication::setAuthenticator(
+        realm,
+        process::Owned<authentication::Authenticator>(authenticator.get())));
+  }
+
+  virtual void TearDown()
+  {
+    foreach (const std::string& realm, realms) {
+      // We need to wait in order to ensure that the operation completes before
+      // we leave `TearDown`. Otherwise, we may leak a mock object.
+      AWAIT_READY(authentication::unsetAuthenticator(realm));
+    }
+
+    realms.clear();
+
+    MesosTest::TearDown();
+  }
+
+private:
+  hashset<std::string> realms;
+};
+
 
-TEST(LoggingTest, Toggle)
+TEST_F(LoggingTest, Toggle)
 {
   process::PID<> pid;
   pid.id = "logging";
@@ -79,6 +126,27 @@ TEST(LoggingTest, Toggle)
       response);
 }
 
+
+// Tests that the `/logging/toggle` endpoint rejects unauthenticated requests
+// when HTTP authentication is enabled.
+TEST_F(LoggingTest, ToggleAuthenticationEnabled)
+{
+  Credentials credentials;
+  credentials.add_credentials()->CopyFrom(DEFAULT_CREDENTIAL);
+
+  // Create a basic HTTP authenticator with the specified credentials and set it
+  // as the authenticator for `DEFAULT_HTTP_AUTHENTICATION_REALM`.
+  setBasicHttpAuthenticator(DEFAULT_HTTP_AUTHENTICATION_REALM, credentials);
+
+  process::PID<> pid;
+  pid.id = "logging";
+  pid.address = process::address();
+
+  process::Future<Response> response = process::http::get(pid, "toggle");
+
+  AWAIT_EXPECT_RESPONSE_STATUS_EQ(Unauthorized({}).status, response);
+}
+
 } // namespace tests {
 } // namespace internal {
 } // namespace mesos {