You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by an...@apache.org on 2018/09/04 21:36:21 UTC

[mesos] 02/03: Added regression test for `http::internal::encode(Request)`.

This is an automated email from the ASF dual-hosted git repository.

andschwa pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit dafb03e4194624e3148200a7f919bfb150b6afb7
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
AuthorDate: Fri Aug 17 13:54:45 2018 -0700

    Added regression test for `http::internal::encode(Request)`.
    
    This function is supposed to be encoding the query parameters, but
    currently fails to do so, resulting in:
    
    ```
    libprocess\src\tests\http_tests.cpp(655): error: Value of: read.get()
    Expected: starts with "GET /?path=C%3A%5Cfoo%5Cbar%253Abaz"
      Actual: "GET /?path=C:\\foo\\bar%3Abaz HTTP/1.1\r\nConnection:
               close\r\nHost: mesos.apache.org\r\nContent-Length: 0\r\n\r\n"
    ```
    
    The query parameter is going over the wire unencoded.
    
    Review: https://reviews.apache.org/r/68422
---
 3rdparty/libprocess/src/tests/http_tests.cpp | 34 ++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/3rdparty/libprocess/src/tests/http_tests.cpp b/3rdparty/libprocess/src/tests/http_tests.cpp
index 89d3bb2..97aaf3e 100644
--- a/3rdparty/libprocess/src/tests/http_tests.cpp
+++ b/3rdparty/libprocess/src/tests/http_tests.cpp
@@ -94,6 +94,7 @@ using testing::DoAll;
 using testing::EndsWith;
 using testing::Invoke;
 using testing::Return;
+using testing::StartsWith;
 using testing::WithParamInterface;
 
 namespace process {
@@ -105,6 +106,16 @@ void reinitialize(
     const Option<string>& readonlyAuthenticationRealm,
     const Option<string>& readwriteAuthenticationRealm);
 
+namespace http {
+namespace internal {
+
+// TODO(bmahler): The client's encoding logic is currently not exposed
+// in headers, so we declare it here to test it. This should be
+// exposed in headers as a library.
+Pipe::Reader encode(const Request& request);
+
+} // namespace internal {
+} // namespace http {
 } // namespace process {
 
 class HttpProcess : public Process<HttpProcess>
@@ -627,6 +638,29 @@ TEST_P(HTTPTest, EncodeAdditionalChars)
 }
 
 
+TEST_P(HTTPTest, QueryEncoding)
+{
+  // This query tests a literal ASCII encoding. The special characters
+  // `:`, `\`, and `%` should each be encoded over the wire, and when
+  // decoded should literally be `C:\foo\bar%3Abaz`.
+  hashmap<string, string> query = {{"path", "C:\\foo\\bar%3Abaz"}};
+  http::URL url = http::URL("http", "mesos.apache.org", 80, "/", query);
+  EXPECT_EQ(
+      stringify(url),
+      "http://mesos.apache.org:80/?path=C%3A%5Cfoo%5Cbar%253Abaz");
+
+  http::Request request;
+  request.method = "GET";
+  request.url = url;
+
+  // This should remain fully encoded.
+  http::Pipe::Reader reader = http::internal::encode(request);
+  Future<string> read = reader.readAll();
+  AWAIT_READY(read);
+  EXPECT_THAT(read.get(), StartsWith("GET /?path=C%3A%5Cfoo%5Cbar%253Abaz"));
+}
+
+
 TEST_P(HTTPTest, PathParse)
 {
   const string pattern = "/books/{isbn}/chapters/{chapter}";