tests: enable sasl
authorMichael Wallner <mike@php.net>
Thu, 6 Feb 2020 13:22:34 +0000 (14:22 +0100)
committerMichael Wallner <mike@php.net>
Thu, 6 Feb 2020 13:22:34 +0000 (14:22 +0100)
13 files changed:
CMakeConfig.txt
libmemcached/sasl.cc
libtest/CMakeLists.txt
libtest/cmdline.cc
libtest/has.cc
libtest/memcached.cc
libtest/memcached.h
libtest/server_container.cc
support/CMakeLists.txt
support/memcached.conf.in [new file with mode: 0644]
support/memcached.pwdb.in [new file with mode: 0644]
tests/libmemcached-1.0/sasl.cc
tests/libmemcached_world.h

index 1ea464f0f0f7b5ba69228be6a1429105c4d59735..5f1b47abd37942e20b09465e51af7ee001b791b7 100644 (file)
@@ -11,6 +11,9 @@ set(BUILD_TESTING ON
 set(ENABLE_SANITIZERS ""
     CACHE STRING "sanitizers to enable (e.g. address undefined ...)")
 
+set(MEMCACHED_BINARY "/usr/bin/memcached"
+    CACHE FILEPATH "memcached binary")
+
 # sasl
 
 set(ENABLE_SASL OFF
index 5ec8bee2fd454cd09184c2aabcba920a5c6bf94c..89462e50d7edfa204cbd8c1a0d7565ed45914e07 100644 (file)
@@ -37,6 +37,7 @@
 
 #include "libmemcached/common.h"
 #include <cassert>
+#include <atomic>
 
 #if defined(LIBMEMCACHED_WITH_SASL_SUPPORT) && LIBMEMCACHED_WITH_SASL_SUPPORT
 
@@ -120,7 +121,7 @@ static void sasl_shutdown_function()
   sasl_done();
 }
 
-static volatile int sasl_startup_state= SASL_OK;
+static std::atomic<int> sasl_startup_state(SASL_OK);
 pthread_mutex_t sasl_startup_state_LOCK= PTHREAD_MUTEX_INITIALIZER;
 static pthread_once_t sasl_startup_once= PTHREAD_ONCE_INIT;
 static void sasl_startup_function(void)
index 675d40c2ca6fd432c0eb9d4e1abac806a013f797..492465fd0790b92731914bab40b84208e48ffcab 100644 (file)
@@ -1,12 +1,12 @@
 
 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/tmp_chroot)
-file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/libtool CONTENT
+file(WRITE ${CMAKE_BINARY_DIR}/libtool
 "#!/bin/bash
 shift
 exec $@
 ")
 if(UNIX)
-    if (EXISTS ${CMAKE_BINARY_DIR}/libtool)
+    if(EXISTS ${CMAKE_BINARY_DIR}/libtool)
         execute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/libtool)
     endif()
 endif()
@@ -54,7 +54,7 @@ target_compile_definitions(libtest PRIVATE
 
         DRIZZLED_BINARY=\"drizzled\"
         GEARMAND_BINARY=\"gearmand\"
-        MEMCACHED_BINARY=\"/usr/bin/memcached\"
+        MEMCACHED_BINARY=\"${MEMCACHED_BINARY}\"
         HAVE_MEMCACHED_BINARY=1
         )
 target_link_libraries(libtest PRIVATE Threads::Threads ${CMAKE_DL_LIBS})
index 55e6b5b66ba0a31a3e6c7bf00ab3a68c73946c3c..375b00a156a837cf3ae95cff393dcfa024b0613e 100644 (file)
@@ -266,7 +266,7 @@ Application::error_t Application::run(const char *args[])
   }
   else
   {
-    spawn_ret= posix_spawn(&_pid, built_argv[0], &file_actions, &spawnattr, &built_argv[0], NULL);
+    spawn_ret= posix_spawn(&_pid, built_argv[0], &file_actions, &spawnattr, &built_argv[0], environ);
   }
 
   posix_spawn_file_actions_destroy(&file_actions);
index 6048bacf24cd806e955779459b5b347da06924d1..74b4aa26112b58e7a282b807f2c471944473124f 100644 (file)
@@ -45,7 +45,11 @@ namespace libtest {
 
 bool has_libmemcached_sasl(void)
 {
+#ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
+  return LIBMEMCACHED_WITH_SASL_SUPPORT;
+#else
   return false;
+#endif
 }
 
 bool has_libmemcached(void)
index 7d43ec0ef04e7894b851a1590b0a8952e80c7b1e..caeb11c363e90312f661bf46949207b268351a7b 100644 (file)
@@ -86,7 +86,12 @@ public:
 
   virtual const char *sasl() const
   {
-    return NULL;
+    return "-S";
+  }
+
+  bool is_sasl() const
+  {
+    return _username.size() && _password.size();
   }
 
   const std::string& password() const
@@ -113,7 +118,7 @@ public:
       return false;
     }
 
-    if (is_socket())
+    if (is_socket() or is_sasl())
     {
       return _app.check();
     }
@@ -157,7 +162,11 @@ public:
     char buffer[30];
     snprintf(buffer, sizeof(buffer), "%d", int(arg));
     app.add_option("-p", buffer);
-    app.add_option("-U", buffer);
+
+    if(!is_sasl())
+    {
+      app.add_option("-U", buffer);
+    }
   }
 
   bool has_port_option() const
@@ -209,12 +218,12 @@ bool Memcached::build()
   add_option("-M");
 #endif
 
-  if (sasl())
+  if (is_sasl())
   {
     add_option(sasl());
   }
 
-  //add_option("-vv");
+  //add_option("-vvv");
 
   return true;
 }
@@ -239,4 +248,14 @@ libtest::Server *build_memcached_socket(const std::string& socket_file, const in
   return NULL;
 }
 
+libtest::Server *build_memcached_sasl(const std::string &hostname, const in_port_t try_port, const std::string &username, const std::string &password)
+{
+  if (has_memcached())
+  {
+    return new Memcached(hostname, try_port, false, username, password);
+  }
+
+  return NULL;
+}
+
 } // namespace libtest
index 195ce7ab4fd509b246e295ad0e6ef320b17f8d78..7dc9c4d153b6e9160d2285d0648563d25613f75c 100644 (file)
@@ -42,5 +42,7 @@ libtest::Server *build_memcached(const std::string& hostname, const in_port_t tr
 
 libtest::Server *build_memcached_socket(const std::string& socket_file, const in_port_t try_port);
 
+libtest::Server *build_memcached_sasl(const std::string &hostname, const in_port_t try_port, const std::string &username, const std::string &password);
+
 }
 
index 25da72c6ff2e410f420a119959f6c26c60e6f18c..e6d2f1dfa5aca9ebf35a19f41124d2dae168922f 100644 (file)
@@ -250,6 +250,10 @@ libtest::Server* server_startup_st::create(const std::string& server_type, in_po
       server= build_memcached("localhost", try_port);
     }
   }
+  else if (server_type == "memcached-sasl")
+  {
+    server = build_memcached_sasl("localhost", try_port, _username, _password);
+  }
 
   return server;
 }
index a49ff67c2964a6c5059d135ea922ef12ab422d22..08203f9c5edcbb37fff47b356b158566c26211dc 100644 (file)
@@ -12,3 +12,12 @@ configure_file(libmemcached.pc.in libmemcached.pc @ONLY)
 install(FILES libmemcached.pc
         DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
         )
+
+if(BUILD_TESTING)
+    set(LIBMEMCACHED_WITH_SASL_PWDB "MEMCACHED_SASL_PWDB=${CMAKE_CURRENT_BINARY_DIR}/memcached.pwdb" PARENT_SCOPE)
+    set(LIBMEMCACHED_WITH_SASL_CONF "SASL_CONF_PATH=${CMAKE_CURRENT_BINARY_DIR}" PARENT_SCOPE)
+
+    cmake_host_system_information(RESULT HOSTNAME QUERY HOSTNAME)
+    configure_file(memcached.pwdb.in memcached.pwdb @ONLY)
+    configure_file(memcached.conf.in memcached.conf @ONLY)
+endif()
diff --git a/support/memcached.conf.in b/support/memcached.conf.in
new file mode 100644 (file)
index 0000000..62b6861
--- /dev/null
@@ -0,0 +1,2 @@
+mech_list: plain
+log_level: 7
diff --git a/support/memcached.pwdb.in b/support/memcached.pwdb.in
new file mode 100644 (file)
index 0000000..ade3171
--- /dev/null
@@ -0,0 +1 @@
+memcached@@HOSTNAME@:memcached
index d5249b2fd3fd095194e1bc18de3339b208ac7c07..44d0f31fbad57d383266ffa6ea3d7cd66d90a397 100644 (file)
@@ -47,10 +47,6 @@ using namespace libtest;
 
 static test_return_t pre_sasl(memcached_st *)
 {
-  SKIP_IF(true);
-#if 0
-  SKIP_IF_(true, "currently we are not testing sasl support");
-#endif
   SKIP_IF(LIBMEMCACHED_WITH_SASL_SUPPORT == 0);
 
   return TEST_SUCCESS;
index 2608778c9b13c497bccbc517833665c12ec0d842..a536093e7df7900408a0c06fae1e580454a7b39b 100644 (file)
@@ -41,6 +41,9 @@
 
 #include "tests/libmemcached_test_container.h"
 
+static char *sasl_pwdb = const_cast<char *>(LIBMEMCACHED_WITH_SASL_PWDB);
+static char *sasl_conf = const_cast<char *>(LIBMEMCACHED_WITH_SASL_CONF);
+
 static void *world_create(libtest::server_startup_st& servers, test_return_t& error)
 {
   SKIP_UNLESS(libtest::has_libmemcached());
@@ -55,6 +58,10 @@ static void *world_create(libtest::server_startup_st& servers, test_return_t& er
       error= TEST_SKIPPED;
       return NULL;
     }
+
+    // provide conf and pwdb to memcached binary
+    putenv(sasl_pwdb);
+    putenv(sasl_conf);
   }
 
   for (uint32_t x= 0; x < servers.servers_to_run(); x++)