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 2011/06/05 07:36:52 UTC

svn commit: r1131816 - in /incubator/mesos/trunk/src/tests: external_test.cpp test_utils.hpp testing_utils.hpp

Author: benh
Date: Sun Jun  5 05:36:52 2011
New Revision: 1131816

URL: http://svn.apache.org/viewvc?rev=1131816&view=rev
Log:
Added some validation of test case name in runExternalTest and renamed
test_utils.hpp to testing_utils.hpp to make it clear that it's not a
test itself.

Added:
    incubator/mesos/trunk/src/tests/testing_utils.hpp
      - copied, changed from r1131815, incubator/mesos/trunk/src/tests/test_utils.hpp
Removed:
    incubator/mesos/trunk/src/tests/test_utils.hpp
Modified:
    incubator/mesos/trunk/src/tests/external_test.cpp

Modified: incubator/mesos/trunk/src/tests/external_test.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/external_test.cpp?rev=1131816&r1=1131815&r2=1131816&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/external_test.cpp (original)
+++ incubator/mesos/trunk/src/tests/external_test.cpp Sun Jun  5 05:36:52 2011
@@ -1,5 +1,6 @@
 #include <gtest/gtest.h>
 
+#include <ctype.h>
 #include <stdlib.h>
 
 #include <string>
@@ -8,10 +9,26 @@
 
 #include "external_test.hpp"
 #include "fatal.hpp"
-#include "test_utils.hpp"
+#include "testing_utils.hpp"
 
 using std::string;
 
+namespace {
+
+// Check that a test name contains only letters, numbers and underscores, to
+// prevent messing with directories outside test_output in runExternalTest.
+bool isValidTestName(const char* name) {
+  for (const char* p = name; *p != 0; p++) {
+    if (!isalnum(*p) && *p != '_') {
+      return false;
+    }
+  }
+  return true;
+}
+
+}
+
+
 /**
  * Run an external test with the given name. The test is expected to be
  * located in src/tests/external/<testCase>/<testName>.sh.
@@ -21,6 +38,11 @@ using std::string;
  */
 void nexus::test::runExternalTest(const char* testCase, const char* testName)
 {
+  // Check that the test name is valid
+  if (!isValidTestName(testCase) || !isValidTestName(testName)) {
+    FAIL() << "Invalid test name for external test (name should " 
+           << "only contain alphanumeric and underscore characters)";
+  }
   // Figure out the absolute path to the test script
   string script = MESOS_HOME + "/tests/external/" + testCase
                              + "/" + testName + ".sh";
@@ -32,8 +54,9 @@ void nexus::test::runExternalTest(const 
   ASSERT_EQ(0, system(command.c_str())) << "Command failed: " << command;
   // Fork a process to change directory and run the test
   pid_t pid;
-  if ((pid = fork()) == -1)
+  if ((pid = fork()) == -1) {
     FAIL() << "Failed to fork to launch external test";
+  }
   if (pid) {
     // In parent process
     int exitCode;

Copied: incubator/mesos/trunk/src/tests/testing_utils.hpp (from r1131815, incubator/mesos/trunk/src/tests/test_utils.hpp)
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/testing_utils.hpp?p2=incubator/mesos/trunk/src/tests/testing_utils.hpp&p1=incubator/mesos/trunk/src/tests/test_utils.hpp&r1=1131815&r2=1131816&rev=1131816&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/test_utils.hpp (original)
+++ incubator/mesos/trunk/src/tests/testing_utils.hpp Sun Jun  5 05:36:52 2011
@@ -1,5 +1,5 @@
-#ifndef __TEST_UTILS_HPP__
-#define __TEST_UTILS_HPP__
+#ifndef __TESTING_UTILS_HPP__
+#define __TESTING_UTILS_HPP__
 
 #include <string>
 
@@ -8,4 +8,4 @@
 // we clean up our directory structure a little. Initialized in main.cpp.
 extern std::string MESOS_HOME;
 
-#endif /* __TEST_UTILS_HPP__ */
+#endif /* __TESTING_UTILS_HPP__ */