Repository: mesos
Updated Branches:
  refs/heads/master b3c18d6d6 -> dcdc79aa8


Only accept POST requests for /scheduler endpoint.

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


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

Branch: refs/heads/master
Commit: dcdc79aa8962b32bf5907e3e40de6aa7681d441e
Parents: b3c18d6
Author: Isabel Jimenez <[email protected]>
Authored: Thu Aug 13 12:02:49 2015 -0700
Committer: Benjamin Mahler <[email protected]>
Committed: Thu Aug 13 12:09:21 2015 -0700

----------------------------------------------------------------------
 src/master/http.cpp          |  6 ++++++
 src/tests/http_api_tests.cpp | 17 +++++++++++++++++
 2 files changed, 23 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/dcdc79aa/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index 649aca0..2749871 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -69,6 +69,7 @@ using process::USAGE;
 using process::http::Accepted;
 using process::http::BadRequest;
 using process::http::InternalServerError;
+using process::http::MethodNotAllowed;
 using process::http::NotFound;
 using process::http::NotImplemented;
 using process::http::NotAcceptable;
@@ -333,6 +334,11 @@ Future<Response> Master::Http::scheduler(const Request& 
request) const
         "HTTP schedulers are not supported when authentication is required");
   }
 
+  if (request.method != "POST") {
+    return MethodNotAllowed(
+        "Expecting a 'POST' request, received '" + request.method + "'");
+  }
+
   v1::scheduler::Call v1Call;
 
   // TODO(anand): Content type values are case-insensitive.

http://git-wip-us.apache.org/repos/asf/mesos/blob/dcdc79aa/src/tests/http_api_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/http_api_tests.cpp b/src/tests/http_api_tests.cpp
index 044bca9..66a00a3 100644
--- a/src/tests/http_api_tests.cpp
+++ b/src/tests/http_api_tests.cpp
@@ -54,6 +54,7 @@ using process::Future;
 using process::PID;
 
 using process::http::BadRequest;
+using process::http::MethodNotAllowed;
 using process::http::NotAcceptable;
 using process::http::OK;
 using process::http::Pipe;
@@ -705,6 +706,22 @@ TEST_P(HttpApiTest, DefaultAccept)
 }
 
 
+TEST_F(HttpApiTest, GetRequest)
+{
+  master::Flags flags = CreateMasterFlags();
+  flags.authenticate_frameworks = false;
+
+  Try<PID<Master> > master = StartMaster(flags);
+  ASSERT_SOME(master);
+
+  Future<Response> response = process::http::get(
+      master.get(),
+      "api/v1/scheduler");
+
+  AWAIT_READY(response);
+  AWAIT_EXPECT_RESPONSE_STATUS_EQ(MethodNotAllowed().status, response);
+}
+
 } // namespace tests {
 } // namespace internal {
 } // namespace mesos {

Reply via email to