)
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)
+ set(LIBMEMCACHED_WITH_SASL_PWDB "${CMAKE_CURRENT_BINARY_DIR}/memcached.pwdb" PARENT_SCOPE)
+ set(LIBMEMCACHED_WITH_SASL_CONF "${CMAKE_CURRENT_BINARY_DIR}" PARENT_SCOPE)
cmake_host_system_information(RESULT HOSTNAME QUERY HOSTNAME)
configure_file(memcached.pwdb.in memcached.pwdb @ONLY)
void MemcachedCluster::init() {
REQUIRE(cluster.start());
+ Retry cluster_is_listening([this]() {
+ return cluster.isListening();
+ });
+ REQUIRE(cluster_is_listening());
+
REQUIRE(memcached_create(&memc));
for (const auto &server : cluster.getServers()) {
auto target = server.getSocketOrPort();
}
}
- Retry cluster_is_listening([this]() {
- return cluster.isListening();
- });
- REQUIRE(cluster_is_listening());
}
MemcachedCluster::~MemcachedCluster() {
}}};
}
+#if LIBMEMCACHED_WITH_SASL_SUPPORT
+MemcachedCluster MemcachedCluster::sasl() {
+ auto mc = MemcachedCluster{Cluster{Server{
+ MEMCACHED_BINARY,
+ {
+ Server::arg_pair_t{"-p", random_socket_or_port_string},
+ Server::arg_t{"-S"}
+ }
+ }}};
+ mc.enableBinaryProto();
+ REQUIRE(MEMCACHED_SUCCESS == memcached_set_sasl_auth_data(&mc.memc,
+ "memcached", "memcached"));
+ return mc;
+}
+#endif
+
void MemcachedCluster::enableBinaryProto(bool enable) {
REQUIRE(MEMCACHED_SUCCESS == memcached_behavior_set(&memc,
MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, enable));
static MemcachedCluster network();
static MemcachedCluster socket();
+#if LIBMEMCACHED_WITH_SASL_SUPPORT
+ static MemcachedCluster sasl();
+#endif
+
private:
static const memcached_st empty_memc;
return true;
}
this_thread::sleep_for(dur);
- dur *= 2;
+ dur *= 1.2;
}
return false;
if (arg == "-p" || arg == "--port") {
auto port = next_arg(arg);
pushArg(arr, port);
- pushArg(arr, "-U");
- pushArg(arr, port);
+// pushArg(arr, "-U");
+// pushArg(arr, port);
socket_or_port = stoi(port);
return port;
} else if (arg == "-s" || arg == "--unix-socket") {
pushArg(arr, sock);
socket_or_port = sock;
return sock;
+ } else if (arg == "-S" || arg == "--enable-sasl") {
+ sasl = true;
}
return {};
}
}
}
+ if (sasl) {
+ memcached_behavior_set(*memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
+ memcached_set_sasl_auth_data(*memc, "memcached", "memcached");
+ }
+
Malloced stat(memcached_stat(*memc, nullptr, nullptr));
if (!*stat || !stat->pid || stat->pid != pid) {
return false;
private:
string binary;
argv_t args;
+ bool sasl = false;
pid_t pid = 0;
int pipe = -1;
int status = 0;
#define CATCH_CONFIG_RUNNER
#include "lib/catch.hpp"
+#include "mem_config.h"
#include <cstdlib>
+#if HAVE_SETENV
+# define SET_ENV(n, k, v) setenv(k, v, 0);
+#else // !HAVE_SETENV
+# define SET_ENV(n, k, v) static char n ## _env[] = k "=" v; putenv(n ## _env)
+#endif
+
int main(int argc, char *argv[]) {
+
#if HAVE_ASAN
-# if HAVE_SETENV
- setenv("ASAN_OPTIONS", "halt_on_error=0", 0);
-# else
- char env[] = "ASAN_OPTIONS=halt_on_error=0";
- putenv(env);
-# endif
+ SET_ENV(asan, "ASAN_OPTIONS", "halt_on_error=0")
#endif
+
+#if LIBMEMCACHED_WITH_SASL_SUPPORT
+ SET_ENV(sasl_pwdb, "MEMCACHED_SASL_PWDB", LIBMEMCACHED_WITH_SASL_PWDB);
+ SET_ENV(sasl_conf, "SASL_CONF_PATH", LIBMEMCACHED_WITH_SASL_CONF);
+#endif
+
return Catch::Session().run(argc, argv);
}
str[i] = random_ascii_string(36);
chr[i] = str[i].data();
len[i] = str[i].length();
- cerr << str[i] << endl;
}
REQUIRE_SUCCESS(memcached_mget(memc, chr.data(), len.data(), NUM_KEYS));
--- /dev/null
+#include "testing/lib/common.hpp"
+#include "testing/lib/Shell.hpp"
+#include "testing/lib/MemcachedCluster.hpp"
+
+TEST_CASE("memcached_sasl") {
+#if !LIBMEMCACHED_WITH_SASL_SUPPORT
+ WARN("ENABLE_SASL=OFF");
+#else
+ Shell sh;
+ string mc{MEMCACHED_BINARY}, err;
+
+ if (!sh.run(mc + " -S --version", err)) {
+ WARN(mc << ": " << err);
+ } else {
+ auto test = MemcachedCluster::sasl();
+ auto memc = &test.memc;
+
+ REQUIRE_SUCCESS(memcached_set(memc, S(__func__), S(__func__), 0, 0));
+ REQUIRE_SUCCESS(memcached_delete(memc, S(__func__), 0));
+ REQUIRE_SUCCESS(memcached_destroy_sasl_auth_data(memc));
+ REQUIRE_SUCCESS(memcached_destroy_sasl_auth_data(memc));
+ REQUIRE_RC(MEMCACHED_INVALID_ARGUMENTS, memcached_destroy_sasl_auth_data(nullptr));
+
+ memcached_quit(memc);
+
+ REQUIRE_RC(MEMCACHED_AUTH_FAILURE, memcached_set(memc, S(__func__), S(__func__), 0, 0));
+
+ REQUIRE_SUCCESS(memcached_set_sasl_auth_data(memc, "username", "password"));
+ REQUIRE_RC(MEMCACHED_AUTH_FAILURE, memcached_set(memc, S(__func__), S(__func__), 0, 0));
+ }
+#endif
+}