Skip to content

Commit

Permalink
Merge branch 'main' into core-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
NegatioN authored Sep 25, 2024
2 parents e11c3b7 + fb2ee90 commit 5391b26
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/server/acl/acl_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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()) {
Expand Down
18 changes: 18 additions & 0 deletions src/server/acl/acl_family_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 5391b26

Please sign in to comment.