Commit 87f7edc6 authored by Georgios Bitzes's avatar Georgios Bitzes
Browse files

Activate password authentication in most tests

parent e996694b
Pipeline #410184 passed with stages
in 31 minutes and 57 seconds
......@@ -21,6 +21,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
************************************************************************/
#include "raft/RaftContactDetails.hh"
#include "StateMachine.hh"
#include "../test-utils.hh"
#include "bench-utils.hh"
......@@ -90,7 +91,8 @@ template<typename TestcaseProvider>
class ExecutorHelper : public Executor {
public:
ExecutorHelper(size_t ev, StateMachine *sm) : Executor(ev), stateMachine(sm) {}
ExecutorHelper(size_t ev, const RaftServer &srv) : Executor(ev), server(srv) {}
ExecutorHelper(size_t ev, const RaftServer &srv, const std::string &pw)
: Executor(ev), server(srv), password(pw) {}
void main(int threadId) override {
if(stateMachine) {
......@@ -109,7 +111,12 @@ public:
}
void mainRedis(int threadId) {
qclient::QClient tunnel(server.hostname, server.port, {} );
qclient::Options opts;
if(!password.empty()) {
opts.handshake.reset(new qclient::AuthHandshake(password));
}
qclient::QClient tunnel(server.hostname, server.port, std::move(opts) );
while(true) {
size_t next = nextEvent++;
if(next > events) break;
......@@ -126,6 +133,7 @@ private:
RaftServer server;
StateMachine *stateMachine = nullptr;
std::atomic<size_t> nextEvent {0};
std::string password;
};
class Benchmarker {
......@@ -170,12 +178,12 @@ public:
else if(params.mode == Mode::kRedisStandalone) {
customDispatcher = new RedisDispatcher(*stateMachine());
customPoller = new Poller(34567, customDispatcher);
executor = new ExecutorHelper<TestcaseProvider>(params.events, {"localhost", 34567});
executor = new ExecutorHelper<TestcaseProvider>(params.events, {"localhost", 34567}, "");
}
else if(params.mode == Mode::kConsensus) {
spinup(0); spinup(1); spinup(2);
RETRY_ASSERT_TRUE(checkStateConsensus(0, 1, 2));
executor = new ExecutorHelper<TestcaseProvider>(params.events, myself(getLeaderID()));
executor = new ExecutorHelper<TestcaseProvider>(params.events, myself(getLeaderID()), contactDetails()->getPassword() );
}
}
protected:
......
......@@ -26,6 +26,7 @@
#include "raft/RaftTimeouts.hh"
#include "raft/RaftCommitTracker.hh"
#include "raft/RaftConfig.hh"
#include "raft/RaftContactDetails.hh"
#include "Poller.hh"
#include "Configuration.hh"
#include "QuarkDBNode.hh"
......@@ -794,10 +795,14 @@ TEST_F(Raft_e2e, monitor) {
Link link(initiator.getFd());
BufferedReader reader(&link);
ASSERT_EQ(link.Send(SSTR("*2\r\n$4\r\nAUTH\r\n$" << contactDetails()->getPassword().size() << "\r\n" << contactDetails()->getPassword() << "\r\n")), 56);
std::string response;
RETRY_ASSERT_TRUE(reader.consume(5, response));
ASSERT_EQ(response, "+OK\r\n");
ASSERT_EQ(link.Send("*1\r\n$7\r\nMONITOR\r\n"), 17);
ASSERT_EQ(link.Send("random string"), 13);
std::string response;
RETRY_ASSERT_TRUE(reader.consume(5, response));
ASSERT_EQ(response, "+OK\r\n");
......
......@@ -22,6 +22,7 @@
************************************************************************/
#include "redis/MultiOp.hh"
#include "raft/RaftContactDetails.hh"
#include "test-utils.hh"
#include "test-reply-macros.hh"
#include <gtest/gtest.h>
......
......@@ -39,7 +39,7 @@ TEST_F(tPoller, T1) {
Poller smPoller(myself().port, &dispatcher);
// start first connection
QClient tunnel(myself().hostname, myself().port, makeNoRedirectOptions());
QClient tunnel(myself().hostname, myself().port, {} );
redisReplyPtr reply = tunnel.exec("set", "abc", "1234").get();
ASSERT_REPLY(reply, "OK");
......@@ -48,7 +48,7 @@ TEST_F(tPoller, T1) {
ASSERT_REPLY(reply, "1234");
// start second connection, ensure the poller can handle them concurrently
QClient tunnel2(myself().hostname, myself().port, makeNoRedirectOptions());
QClient tunnel2(myself().hostname, myself().port, {} );
reply = tunnel2.exec("get", "abc").get();
ASSERT_REPLY(reply, "1234");
......@@ -57,7 +57,7 @@ TEST_F(tPoller, T1) {
ASSERT_REPLY(reply, "OK");
// now try a third
QClient tunnel3(myself().hostname, myself().port, makeNoRedirectOptions());
QClient tunnel3(myself().hostname, myself().port, {} );
reply = tunnel3.exec("get", "qwert").get();
ASSERT_REPLY(reply, "asdf");
}
......@@ -65,7 +65,7 @@ TEST_F(tPoller, T1) {
TEST_F(tPoller, test_reconnect) {
RedisDispatcher dispatcher(*stateMachine());
QClient tunnel(myself().hostname, myself().port, makeNoRedirectOptions());
QClient tunnel(myself().hostname, myself().port, {} );
for(size_t reconnects = 0; reconnects < 5; reconnects++) {
Poller rocksdbpoller(myself().port, &dispatcher);
......
......@@ -47,8 +47,11 @@ TEST_F(Background_Flusher, basic_sanity) {
qclient::Notifier dummyNotifier;
ASSERT_EQ(system("rm -rf /tmp/quarkdb-tests-flusher"), 0);
qclient::Options opts;
opts.handshake = makeQClientHandshake();
qclient::BackgroundFlusher flusher(qclient::Members(myself(follower).hostname, myself(follower).port),
qclient::Options(), dummyNotifier, new qclient::RocksDBPersistency("/tmp/quarkdb-tests-flusher")
std::move(opts), dummyNotifier, new qclient::RocksDBPersistency("/tmp/quarkdb-tests-flusher")
);
const int nentries = 10000;
......@@ -87,7 +90,10 @@ TEST_F(Background_Flusher, with_transition) {
qclient::Notifier dummyNotifier;
ASSERT_EQ(system("rm -rf /tmp/quarkdb-tests-flusher"), 0);
qclient::BackgroundFlusher flusher(members, qclient::Options(), dummyNotifier,
qclient::Options opts;
opts.handshake = makeQClientHandshake();
qclient::BackgroundFlusher flusher(members, std::move(opts), dummyNotifier,
new qclient::RocksDBPersistency("/tmp/quarkdb-tests-flusher")
);
......@@ -121,8 +127,10 @@ TEST_F(Background_Flusher, persistency) {
qclient::Notifier dummyNotifier;
ASSERT_EQ(system("rm -rf /tmp/quarkdb-tests-flusher"), 0);
qclient::Options opts;
opts.handshake = makeQClientHandshake();
std::unique_ptr<qclient::BackgroundFlusher> flusher(
new qclient::BackgroundFlusher(qclient::Members(myself(follower).hostname, myself(follower).port), qclient::Options(), dummyNotifier, new qclient::RocksDBPersistency("/tmp/quarkdb-tests-flusher"))
new qclient::BackgroundFlusher(qclient::Members(myself(follower).hostname, myself(follower).port), std::move(opts), dummyNotifier, new qclient::RocksDBPersistency("/tmp/quarkdb-tests-flusher"))
);
// queue entries
......@@ -135,7 +143,9 @@ TEST_F(Background_Flusher, persistency) {
// stop the flusher, recover contents from persistency layer
flusher.reset();
flusher.reset(new qclient::BackgroundFlusher(qclient::Members(myself(follower).hostname, myself(follower).port), qclient::Options(), dummyNotifier, new qclient::RocksDBPersistency("/tmp/quarkdb-tests-flusher")));
opts = {};
opts.handshake = makeQClientHandshake();
flusher.reset(new qclient::BackgroundFlusher(qclient::Members(myself(follower).hostname, myself(follower).port), std::move(opts), dummyNotifier, new qclient::RocksDBPersistency("/tmp/quarkdb-tests-flusher")));
ASSERT_GT(flusher->size(), 0u);
RETRY_ASSERT_TRUE(flusher->size() == 0u);
......
......@@ -48,6 +48,8 @@ TEST_F(QClientTests, hide_transient_failures) {
qclient::Options opts;
opts.transparentRedirects = true;
opts.retryStrategy = qclient::RetryStrategy::WithTimeout(std::chrono::seconds(30));
opts.handshake = makeQClientHandshake();
QClient qcl(members, std::move(opts));
// Issue request _before_ spinning up the cluster! Verify it succeeds.
......@@ -102,6 +104,7 @@ TEST_F(QClientTests, nullptr_only_after_timeout) {
qclient::Options opts;
opts.transparentRedirects = true;
opts.handshake = makeQClientHandshake();
opts.retryStrategy = qclient::RetryStrategy::WithTimeout(std::chrono::seconds(3));
QClient qcl(members, std::move(opts));
......@@ -177,6 +180,7 @@ TEST_F(QClientTests, MultipleWriterThreads) {
// Launch many threads doing pings, using the same QClient object.
qclient::Options opts;
opts.backpressureStrategy = BackpressureStrategy::RateLimitPendingRequests(2048);
opts.handshake = makeQClientHandshake();
QClient qcl(myself(leaderID).hostname, myself(leaderID).port, std::move(opts));
......
......@@ -159,6 +159,10 @@ qclient::QClient* TestCluster::tunnel(int id) {
return node(id)->tunnel();
}
std::unique_ptr<qclient::Handshake> TestCluster::makeQClientHandshake(int id) {
return node(id)->makeQClientHandshake();
}
qclient::Options TestCluster::makeNoRedirectOptions(int id) {
return node(id)->makeNoRedirectOptions();
}
......@@ -251,6 +255,7 @@ TestNode::TestNode(RaftServer me, RaftClusterID clust, const std::vector<RaftSer
"redis.mode raft\n" <<
"redis.database " << shardPath << "\n"
"redis.myself " << myselfSrv.toString() << "\n"
"redis.password 1234567890-qwerty-0987654321-ytrewq\n"
), config);
if(!status) {
......@@ -304,9 +309,19 @@ Poller* TestNode::poller() {
qclient::Options TestNode::makeNoRedirectOptions() {
qclient::Options options;
options.transparentRedirects = false;
options.handshake = makeQClientHandshake();
return options;
}
std::unique_ptr<qclient::Handshake> TestNode::makeQClientHandshake() {
if(group()->contactDetails()->getPassword().empty()) {
return {};
}
return std::unique_ptr<qclient::Handshake>(new qclient::AuthHandshake(group()->contactDetails()->getPassword()));
}
qclient::QClient* TestNode::tunnel() {
if(tunnelptr == nullptr) {
tunnelptr = new qclient::QClient(myself().hostname, myself().port, makeNoRedirectOptions());
......
......@@ -143,6 +143,7 @@ public:
Poller *poller();
qclient::QClient *tunnel();
qclient::Options makeNoRedirectOptions();
std::unique_ptr<qclient::Handshake> makeQClientHandshake();
RaftServer myself();
std::vector<RaftServer> nodes();
......@@ -185,6 +186,8 @@ public:
const RaftContactDetails* contactDetails(int id = 0);
qclient::Options makeNoRedirectOptions(int id = 0);
std::unique_ptr<qclient::Handshake> makeQClientHandshake(int id = 0);
void killTunnel(int id = 0);
// manage node state
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment