Repository: mesos
Updated Branches:
  refs/heads/master a4c333bb6 -> 4e3e4cadc


Changed fetcher to handle leading whitespace in URLs.

Fixes MESOS-2862.

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


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

Branch: refs/heads/master
Commit: 4e3e4cadc55f443486f7076569d2b4ef9782f7d1
Parents: a4c333b
Author: Artem Harutyunyan <[email protected]>
Authored: Sat Jul 18 13:37:47 2015 -0700
Committer: Benjamin Hindman <[email protected]>
Committed: Sat Jul 18 14:02:49 2015 -0700

----------------------------------------------------------------------
 src/launcher/fetcher.cpp    |  8 +++--
 src/tests/fetcher_tests.cpp | 63 +++++++++++++++++++++++++++++++++++-----
 2 files changed, 62 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/4e3e4cad/src/launcher/fetcher.cpp
----------------------------------------------------------------------
diff --git a/src/launcher/fetcher.cpp b/src/launcher/fetcher.cpp
index 5d3fe9e..f8b46b8 100644
--- a/src/launcher/fetcher.cpp
+++ b/src/launcher/fetcher.cpp
@@ -169,11 +169,15 @@ static Try<string> copyFile(
 
 
 static Try<string> download(
-    const string& sourceUri,
+    const string& _sourceUri,
     const string& destinationPath,
     const Option<string>& frameworksHome)
 {
+  // Trim leading whitespace for 'sourceUri'.
+  const string sourceUri = strings::trim(_sourceUri, strings::PREFIX);
+
   LOG(INFO) << "Fetching URI '" << sourceUri << "'";
+
   Try<Nothing> validation = Fetcher::validateUri(sourceUri);
   if (validation.isError()) {
     return Error(validation.error());
@@ -193,7 +197,7 @@ static Try<string> download(
   // 2. Try to fetch URI using os::net / libcurl implementation.
   // We consider http, https, ftp, ftps compatible with libcurl.
   if (Fetcher::isNetUri(sourceUri)) {
-     return downloadWithNet(sourceUri, destinationPath);
+    return downloadWithNet(sourceUri, destinationPath);
   }
 
   // 3. Try to fetch the URI using hadoop client.

http://git-wip-us.apache.org/repos/asf/mesos/blob/4e3e4cad/src/tests/fetcher_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/fetcher_tests.cpp b/src/tests/fetcher_tests.cpp
index ae10c42..e2a52f7 100644
--- a/src/tests/fetcher_tests.cpp
+++ b/src/tests/fetcher_tests.cpp
@@ -278,13 +278,10 @@ class HttpProcess : public Process<HttpProcess>
 public:
   HttpProcess()
   {
-    route("/help", None(), &HttpProcess::index);
+    route("/test", None(), &HttpProcess::test);
   }
 
-  Future<http::Response> index(const http::Request& request)
-  {
-    return http::OK();
-  }
+  MOCK_METHOD1(test, Future<http::Response>(const http::Request&));
 };
 
 
@@ -295,9 +292,10 @@ TEST_F(FetcherTest, OSNetUriTest)
   spawn(process);
 
   string url = "http://"; + net::getHostname(process.self().address.ip).get() +
-                ":" + stringify(process.self().address.port) + "/help";
+               ":" + stringify(process.self().address.port) +
+               "/" + process.self().id + "/test";
 
-  string localFile = path::join(os::getcwd(), "help");
+  string localFile = path::join(os::getcwd(), "test");
   EXPECT_FALSE(os::exists(localFile));
 
   slave::Flags flags;
@@ -314,8 +312,59 @@ TEST_F(FetcherTest, OSNetUriTest)
   Fetcher fetcher;
   SlaveID slaveId;
 
+  EXPECT_CALL(process, test(_))
+    .WillOnce(Return(http::OK()));
+
   Future<Nothing> fetch = fetcher.fetch(
       containerId, commandInfo, os::getcwd(), None(), slaveId, flags);
+
+  AWAIT_READY(fetch);
+
+  EXPECT_TRUE(os::exists(localFile));
+}
+
+
+// Tests whether fetcher can process URIs that contain leading whitespace
+// characters. This was added as a verification for MESOS-2862.
+//
+// TODO(hartem): This test case should be merged with the previous one.
+TEST_F(FetcherTest, OSNetUriSpaceTest)
+{
+  HttpProcess process;
+
+  spawn(process);
+
+  // A URL with a bunch of leading whitespace characters.
+  string url = " \t \n  http://"; +
+               net::getHostname(process.self().address.ip).get() + ":" +
+               stringify(process.self().address.port) +
+               "/" + process.self().id + "/test";
+
+  string localFile = path::join(os::getcwd(), "test");
+  EXPECT_FALSE(os::exists(localFile));
+
+  slave::Flags flags;
+  flags.launcher_dir = path::join(tests::flags.build_dir, "src");
+  flags.frameworks_home = "/tmp/frameworks";
+
+  ContainerID containerId;
+  containerId.set_value(UUID::random().toString());
+
+  CommandInfo commandInfo;
+  CommandInfo::URI* uri = commandInfo.add_uris();
+
+  uri->set_value(url);
+
+  Fetcher fetcher;
+  SlaveID slaveId;
+
+  // Verify that the intended endpoint is hit.
+  EXPECT_CALL(process, test(_))
+    .WillOnce(Return(http::OK()));
+
+  Future<Nothing> fetch = fetcher.fetch(
+      containerId, commandInfo, os::getcwd(), None(), slaveId, flags);
+
   AWAIT_READY(fetch);
 
   EXPECT_TRUE(os::exists(localFile));

Reply via email to