Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
983b9970
Commit
983b9970
authored
Jul 24, 2020
by
jamesge
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modify RedisTest.auth to adapt redis 6.0
parent
c347f589
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
20 deletions
+31
-20
brpc_redis_unittest.cpp
test/brpc_redis_unittest.cpp
+31
-20
No files found.
test/brpc_redis_unittest.cpp
View file @
983b9970
...
...
@@ -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
());
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment