mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 10:25:47 +02:00
chore(acl_family): add allcomands and nocommands (#3783)
* add allcommands alias for acl * add nocommands alias for acl * add test
This commit is contained in:
parent
105c2bd761
commit
fb2ee90b2d
2 changed files with 27 additions and 1 deletions
|
@ -651,7 +651,7 @@ constexpr uint32_t kGenPass = acl::SLOW;
|
|||
|
||||
// We can't implement the ACL commands and its respective subcommands LIST, CAT, etc
|
||||
// the usual way, (that is, one command called ACL which then dispatches to the subcommand
|
||||
// based on the secocond argument) because each of the subcommands has different ACL
|
||||
// based on the second argument) because each of the subcommands has different ACL
|
||||
// categories. Therefore, to keep it compatible with the CommandId, I need to treat them
|
||||
// as separate commands in the registry. This is the least intrusive change because it's very
|
||||
// easy to handle that case explicitly in `DispatchCommand`.
|
||||
|
@ -990,6 +990,14 @@ using OptCat = std::optional<uint32_t>;
|
|||
// bool == true if +
|
||||
// bool == false if -
|
||||
std::pair<OptCat, bool> AclFamily::MaybeParseAclCategory(std::string_view command) const {
|
||||
if (absl::EqualsIgnoreCase(command, "ALLCOMMANDS")) {
|
||||
return {cat_table_.at("ALL"), true};
|
||||
}
|
||||
|
||||
if (absl::EqualsIgnoreCase(command, "NOCOMMANDS")) {
|
||||
return {cat_table_.at("ALL"), false};
|
||||
}
|
||||
|
||||
if (absl::StartsWith(command, "+@")) {
|
||||
auto res = cat_table_.find(command.substr(2));
|
||||
if (res == cat_table_.end()) {
|
||||
|
|
|
@ -116,6 +116,24 @@ TEST_F(AclFamilyTest, AclSetUser) {
|
|||
// +@NONE should not exist anymore. It's not in the spec.
|
||||
resp = Run({"ACL", "SETUSER", "rand", "+@NONE"});
|
||||
EXPECT_THAT(resp, ErrArg("ERR Unrecognized parameter +@NONE"));
|
||||
|
||||
resp = Run({"ACL", "SETUSER", "rand", "ALLCOMMANDS"});
|
||||
EXPECT_THAT(resp, "OK");
|
||||
|
||||
resp = Run({"ACL", "LIST"});
|
||||
vec = resp.GetVec();
|
||||
EXPECT_THAT(vec, UnorderedElementsAre("user default on nopass ~* &* +@all",
|
||||
"user vlad on resetchannels -@all +acl",
|
||||
"user rand off resetchannels +@all"));
|
||||
|
||||
resp = Run({"ACL", "SETUSER", "rand", "NOCOMMANDS"});
|
||||
EXPECT_THAT(resp, "OK");
|
||||
|
||||
resp = Run({"ACL", "LIST"});
|
||||
vec = resp.GetVec();
|
||||
EXPECT_THAT(vec, UnorderedElementsAre("user default on nopass ~* &* +@all",
|
||||
"user vlad on resetchannels -@all +acl",
|
||||
"user rand off resetchannels -@all"));
|
||||
}
|
||||
|
||||
TEST_F(AclFamilyTest, AclDelUser) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue