update TODO
[awesomized/libmemcached] / test / tests / memcached / sasl.cpp
1 #include "test/lib/common.hpp"
2 #include "test/lib/Shell.hpp"
3 #include "test/lib/MemcachedCluster.hpp"
4 #include "test/fixtures/callbacks.hpp"
5
6 TEST_CASE("memcached_sasl") {
7 #if !LIBMEMCACHED_WITH_SASL_SUPPORT
8 WARN("ENABLE_SASL=OFF");
9 #else
10 Shell sh;
11 string mc{MEMCACHED_BINARY}, err;
12
13 if (!sh.run(mc + " -S --version", err)) {
14 WARN(mc << ": " << err);
15 } else {
16 auto test = MemcachedCluster::sasl();
17 auto memc = &test.memc;
18
19 REQUIRE_SUCCESS(memcached_set(memc, S(__func__), S(__func__), 0, 0));
20 REQUIRE_SUCCESS(memcached_delete(memc, S(__func__), 0));
21 REQUIRE_SUCCESS(memcached_destroy_sasl_auth_data(memc));
22 REQUIRE_SUCCESS(memcached_destroy_sasl_auth_data(memc));
23 REQUIRE_RC(MEMCACHED_INVALID_ARGUMENTS, memcached_destroy_sasl_auth_data(nullptr));
24
25 memcached_quit(memc);
26
27 REQUIRE_RC(MEMCACHED_AUTH_FAILURE, memcached_set(memc, S(__func__), S(__func__), 0, 0));
28
29 REQUIRE_SUCCESS(memcached_set_sasl_auth_data(memc, "username", "password"));
30 REQUIRE_RC(MEMCACHED_AUTH_FAILURE, memcached_set(memc, S(__func__), S(__func__), 0, 0));
31
32 SECTION("getpid2") {
33 memcached_return_t rc;
34
35 for (auto &server : test.cluster.getServers()) {
36 REQUIRE(server.getPid() == libmemcached_util_getpid2("localhost", get<int>(server.getSocketOrPort()), "memcached", "memcached", &rc));
37 REQUIRE_SUCCESS(rc);
38 }
39
40 REQUIRE(-1 == libmemcached_util_getpid2("localhost", 1, "foo", "bar", &rc));
41 REQUIRE(memcached_fatal(rc));
42 }
43
44 SECTION("ping2") {
45 memcached_server_fn fptr[] = {&ping2_callback};
46
47 REQUIRE_SUCCESS(memcached_server_cursor(memc, fptr, nullptr, 1));
48 }
49 }
50 #endif
51 }