From: Michael Wallner Date: Thu, 6 Feb 2020 13:22:34 +0000 (+0100) Subject: tests: enable sasl X-Git-Tag: post_cmake~20 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=f4fcfcef18090e6d636aabfcd48adadcfb2db554;p=awesomized%2Flibmemcached tests: enable sasl --- diff --git a/CMakeConfig.txt b/CMakeConfig.txt index 1ea464f0..5f1b47ab 100644 --- a/CMakeConfig.txt +++ b/CMakeConfig.txt @@ -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 diff --git a/libmemcached/sasl.cc b/libmemcached/sasl.cc index 5ec8bee2..89462e50 100644 --- a/libmemcached/sasl.cc +++ b/libmemcached/sasl.cc @@ -37,6 +37,7 @@ #include "libmemcached/common.h" #include +#include #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 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) diff --git a/libtest/CMakeLists.txt b/libtest/CMakeLists.txt index 675d40c2..492465fd 100644 --- a/libtest/CMakeLists.txt +++ b/libtest/CMakeLists.txt @@ -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}) diff --git a/libtest/cmdline.cc b/libtest/cmdline.cc index 55e6b5b6..375b00a1 100644 --- a/libtest/cmdline.cc +++ b/libtest/cmdline.cc @@ -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); diff --git a/libtest/has.cc b/libtest/has.cc index 6048bacf..74b4aa26 100644 --- a/libtest/has.cc +++ b/libtest/has.cc @@ -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) diff --git a/libtest/memcached.cc b/libtest/memcached.cc index 7d43ec0e..caeb11c3 100644 --- a/libtest/memcached.cc +++ b/libtest/memcached.cc @@ -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 diff --git a/libtest/memcached.h b/libtest/memcached.h index 195ce7ab..7dc9c4d1 100644 --- a/libtest/memcached.h +++ b/libtest/memcached.h @@ -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); + } diff --git a/libtest/server_container.cc b/libtest/server_container.cc index 25da72c6..e6d2f1df 100644 --- a/libtest/server_container.cc +++ b/libtest/server_container.cc @@ -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; } diff --git a/support/CMakeLists.txt b/support/CMakeLists.txt index a49ff67c..08203f9c 100644 --- a/support/CMakeLists.txt +++ b/support/CMakeLists.txt @@ -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 index 00000000..62b68619 --- /dev/null +++ b/support/memcached.conf.in @@ -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 index 00000000..ade3171d --- /dev/null +++ b/support/memcached.pwdb.in @@ -0,0 +1 @@ +memcached@@HOSTNAME@:memcached diff --git a/tests/libmemcached-1.0/sasl.cc b/tests/libmemcached-1.0/sasl.cc index d5249b2f..44d0f31f 100644 --- a/tests/libmemcached-1.0/sasl.cc +++ b/tests/libmemcached-1.0/sasl.cc @@ -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; diff --git a/tests/libmemcached_world.h b/tests/libmemcached_world.h index 2608778c..a536093e 100644 --- a/tests/libmemcached_world.h +++ b/tests/libmemcached_world.h @@ -41,6 +41,9 @@ #include "tests/libmemcached_test_container.h" +static char *sasl_pwdb = const_cast(LIBMEMCACHED_WITH_SASL_PWDB); +static char *sasl_conf = const_cast(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++)