You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by ja...@apache.org on 2020/07/24 14:32:04 UTC
[incubator-brpc] branch master updated: Modify RedisTest.auth to
adapt redis 6.0
This is an automated email from the ASF dual-hosted git repository.
jamesge pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-brpc.git
The following commit(s) were added to refs/heads/master by this push:
new 983b997 Modify RedisTest.auth to adapt redis 6.0
983b997 is described below
commit 983b997066dee33022bfba27d7e00f207c092b21
Author: jamesge <jg...@gmail.com>
AuthorDate: Fri Jul 24 22:31:38 2020 +0800
Modify RedisTest.auth to adapt redis 6.0
---
test/brpc_redis_unittest.cpp | 51 +++++++++++++++++++++++++++-----------------
1 file changed, 31 insertions(+), 20 deletions(-)
diff --git a/test/brpc_redis_unittest.cpp b/test/brpc_redis_unittest.cpp
index 08576bf..1176676 100644
--- a/test/brpc_redis_unittest.cpp
+++ b/test/brpc_redis_unittest.cpp
@@ -356,18 +356,25 @@ TEST_F(RedisTest, by_components) {
AssertResponseEqual(response2, response, 2);
}
+static std::string GeneratePassword() {
+ std::string result;
+ result.reserve(12);
+ for (size_t i = 0; i < result.capacity(); ++i) {
+ result.push_back(butil::fast_rand_in('a', 'z'));
+ }
+ return result;
+}
+
TEST_F(RedisTest, auth) {
if (g_redis_pid < 0) {
puts("Skipped due to absence of redis-server");
return;
}
// generate a random password
- char PASSWORD[12];
- for (size_t i = 0; i < arraysize(PASSWORD) - 1; ++i) {
- PASSWORD[i] = butil::fast_rand_in('a', 'z');
- }
- PASSWORD[arraysize(PASSWORD)-1] = '\0';
- LOG(INFO) << "Generated password=" << PASSWORD;
+ const std::string passwd1 = GeneratePassword();
+ const std::string passwd2 = GeneratePassword();
+ LOG(INFO) << "Generated passwd1=" << passwd1 << " passwd2=" << passwd2;
+
// config auth
{
brpc::ChannelOptions options;
@@ -378,10 +385,10 @@ TEST_F(RedisTest, auth) {
brpc::RedisResponse response;
brpc::Controller cntl;
- request.AddCommand("set passwd %s", PASSWORD);
- request.AddCommand("config set requirepass %s", PASSWORD);
- request.AddCommand("auth %s", PASSWORD);
- request.AddCommand("get passwd");
+ request.AddCommand("set mykey %s", passwd1.c_str());
+ request.AddCommand("config set requirepass %s", passwd1.c_str());
+ request.AddCommand("auth %s", passwd1.c_str());
+ request.AddCommand("get mykey");
channel.CallMethod(NULL, &cntl, &request, &response, NULL);
ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText();
@@ -393,7 +400,7 @@ TEST_F(RedisTest, auth) {
ASSERT_EQ(brpc::REDIS_REPLY_STATUS, response.reply(2).type());
ASSERT_STREQ("OK", response.reply(2).c_str());
ASSERT_EQ(brpc::REDIS_REPLY_STRING, response.reply(3).type());
- ASSERT_STREQ(PASSWORD, response.reply(3).c_str());
+ ASSERT_STREQ(passwd1.c_str(), response.reply(3).c_str());
}
// Auth failed
@@ -406,54 +413,58 @@ TEST_F(RedisTest, auth) {
brpc::RedisResponse response;
brpc::Controller cntl;
- request.AddCommand("get passwd");
+ request.AddCommand("get mykey");
channel.CallMethod(NULL, &cntl, &request, &response, NULL);
ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText();
ASSERT_EQ(1, response.reply_size());
ASSERT_EQ(brpc::REDIS_REPLY_ERROR, response.reply(0).type());
}
- // Auth with RedisAuthenticator && clear auth
+ // Auth with RedisAuthenticator and change to passwd2 (setting to empty
+ // pass does not work on redis 6.0.6)
{
brpc::ChannelOptions options;
options.protocol = brpc::PROTOCOL_REDIS;
brpc::Channel channel;
brpc::policy::RedisAuthenticator* auth =
- new brpc::policy::RedisAuthenticator(PASSWORD);
+ new brpc::policy::RedisAuthenticator(passwd1.c_str());
options.auth = auth;
ASSERT_EQ(0, channel.Init("0.0.0.0:" REDIS_SERVER_PORT, &options));
brpc::RedisRequest request;
brpc::RedisResponse response;
brpc::Controller cntl;
- request.AddCommand("get passwd");
- request.AddCommand("config set requirepass ''");
+ request.AddCommand("get mykey");
+ request.AddCommand("config set requirepass %s", passwd2.c_str());
channel.CallMethod(NULL, &cntl, &request, &response, NULL);
ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText();
ASSERT_EQ(2, response.reply_size());
ASSERT_EQ(brpc::REDIS_REPLY_STRING, response.reply(0).type());
- ASSERT_STREQ(PASSWORD, response.reply(0).c_str());
+ ASSERT_STREQ(passwd1.c_str(), response.reply(0).c_str());
ASSERT_EQ(brpc::REDIS_REPLY_STATUS, response.reply(1).type());
ASSERT_STREQ("OK", response.reply(1).c_str());
}
- // check noauth.
+ // Auth with passwd2
{
brpc::ChannelOptions options;
options.protocol = brpc::PROTOCOL_REDIS;
+ brpc::policy::RedisAuthenticator* auth =
+ new brpc::policy::RedisAuthenticator(passwd2.c_str());
+ options.auth = auth;
brpc::Channel channel;
ASSERT_EQ(0, channel.Init("0.0.0.0:" REDIS_SERVER_PORT, &options));
brpc::RedisRequest request;
brpc::RedisResponse response;
brpc::Controller cntl;
- request.AddCommand("get passwd");
+ request.AddCommand("get mykey");
channel.CallMethod(NULL, &cntl, &request, &response, NULL);
ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText();
ASSERT_EQ(1, response.reply_size());
ASSERT_EQ(brpc::REDIS_REPLY_STRING, response.reply(0).type()) << response.reply(0);
- ASSERT_STREQ(PASSWORD, response.reply(0).c_str());
+ ASSERT_STREQ(passwd1.c_str(), response.reply(0).c_str());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org