You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2014/05/01 06:54:26 UTC

git commit: Decode percent-encoded paths.

Repository: mesos
Updated Branches:
  refs/heads/master 2e28b6919 -> dbebd46f2


Decode percent-encoded paths.

See MESOS-1164.

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


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

Branch: refs/heads/master
Commit: dbebd46f2e71f44a7bcc6b1259fc37ecbb9c47c8
Parents: 2e28b69
Author: Benjamin Hindman <be...@gmail.com>
Authored: Wed Apr 30 11:19:25 2014 -0700
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Wed Apr 30 17:04:09 2014 -0700

----------------------------------------------------------------------
 3rdparty/libprocess/src/process.cpp             | 21 ++++++--
 3rdparty/libprocess/src/tests/process_tests.cpp | 52 ++++++++++++++++++++
 2 files changed, 70 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/dbebd46f/3rdparty/libprocess/src/process.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/process.cpp b/3rdparty/libprocess/src/process.cpp
index 26c16cf..27ca5bb 100644
--- a/3rdparty/libprocess/src/process.cpp
+++ b/3rdparty/libprocess/src/process.cpp
@@ -832,7 +832,16 @@ static Message* parse(Request* request)
     // Now determine 'to'.
     index = request->path.find('/', 1);
     index = index != string::npos ? index - 1 : string::npos;
-    const UPID to(request->path.substr(1, index), __ip__, __port__);
+
+    // Decode possible percent-encoded 'to'.
+    Try<string> decode = http::decode(request->path.substr(1, index));
+
+    if (decode.isError()) {
+      VLOG(2) << "Failed to decode URL path: " << decode.get();
+      return NULL;
+    }
+
+    const UPID to(decode.get(), __ip__, __port__);
 
     // And now determine 'name'.
     index = index != string::npos ? index + 2: request->path.size();
@@ -2428,7 +2437,13 @@ bool ProcessManager::handle(
     request->path = "/" + delegate;
     receiver = use(UPID(delegate, __ip__, __port__));
   } else if (tokens.size() > 0) {
-    receiver = use(UPID(tokens[0], __ip__, __port__));
+    // Decode possible percent-encoded path.
+    Try<string> decode = http::decode(tokens[0]);
+    if (!decode.isError()) {
+      receiver = use(UPID(decode.get(), __ip__, __port__));
+    } else {
+      VLOG(1) << "Failed to decode URL path: " << decode.error();
+    }
   }
 
   if (!receiver && delegate != "") {
@@ -3206,7 +3221,7 @@ void ProcessBase::visit(const HttpEvent& event)
   // Split the path by '/'.
   vector<string> tokens = strings::tokenize(event.request->path, "/");
   CHECK(tokens.size() >= 1);
-  CHECK(tokens[0] == pid.id);
+  CHECK_EQ(pid.id, http::decode(tokens[0]).get());
 
   const string& name = tokens.size() > 1 ? tokens[1] : "";
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/dbebd46f/3rdparty/libprocess/src/tests/process_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/process_tests.cpp b/3rdparty/libprocess/src/tests/process_tests.cpp
index 745c3ad..659b063 100644
--- a/3rdparty/libprocess/src/tests/process_tests.cpp
+++ b/3rdparty/libprocess/src/tests/process_tests.cpp
@@ -27,6 +27,7 @@
 
 #include <stout/duration.hpp>
 #include <stout/gtest.hpp>
+#include <stout/hashmap.hpp>
 #include <stout/lambda.hpp>
 #include <stout/nothing.hpp>
 #include <stout/os.hpp>
@@ -1714,3 +1715,54 @@ TEST(Future, FromTry)
 
   ASSERT_TRUE(future.isFailed());
 }
+
+
+class PercentEncodedIDProcess : public Process<PercentEncodedIDProcess>
+{
+public:
+  PercentEncodedIDProcess()
+    : ProcessBase("id(42)") {}
+
+  virtual void initialize()
+  {
+    install("handler1", &Self::handler1);
+    route("/handler2", None(), &Self::handler2);
+  }
+
+  MOCK_METHOD2(handler1, void(const UPID&, const string&));
+  MOCK_METHOD1(handler2, Future<http::Response>(const http::Request&));
+};
+
+
+TEST(Process, PercentEncodedURLs)
+{
+  PercentEncodedIDProcess process;
+  spawn(process);
+
+  // Construct the PID using percent-encoding.
+  UPID pid("id%2842%29", process.self().ip, process.self().port);
+
+  // Mimic a libprocess message sent to an installed handler.
+  Future<Nothing> handler1;
+  EXPECT_CALL(process, handler1(_, _))
+    .WillOnce(FutureSatisfy(&handler1));
+
+  hashmap<string, string> headers;
+  headers["User-Agent"] = "libprocess/";
+
+  Future<http::Response> response = http::post(pid, "handler1", headers);
+
+  AWAIT_READY(handler1);
+
+  // Now an HTTP request.
+  EXPECT_CALL(process, handler2(_))
+    .WillOnce(Return(http::OK()));
+
+  response = http::get(pid, "handler2");
+
+  AWAIT_READY(response);
+  EXPECT_EQ(http::statuses[200], response.get().status);
+
+  terminate(process);
+  wait(process);
+}