Skip to content

Commit

Permalink
test presence of categories in acl cat
Browse files Browse the repository at this point in the history
  • Loading branch information
ndyakov committed Feb 4, 2025
1 parent fcc0007 commit e94b310
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
27 changes: 27 additions & 0 deletions acl_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@ import "context"

type ACLCmdable interface {
ACLDryRun(ctx context.Context, username string, command ...interface{}) *StringCmd

ACLLog(ctx context.Context, count int64) *ACLLogCmd
ACLLogReset(ctx context.Context) *StatusCmd

ACLSetUser(ctx context.Context, username string, rules ...string) *StatusCmd
ACLDelUser(ctx context.Context, username string) *IntCmd
ACLList(ctx context.Context) *StringSliceCmd

ACLCat(ctx context.Context) *StringSliceCmd
ACLCatArgs(ctx context.Context, options *ACLCatArgs) *StringSliceCmd
}

type ACLCatArgs struct {
Category string
}

func (c cmdable) ACLDryRun(ctx context.Context, username string, command ...interface{}) *StringCmd {
Expand Down Expand Up @@ -65,3 +74,21 @@ func (c cmdable) ACLList(ctx context.Context) *StringSliceCmd {
_ = c(ctx, cmd)
return cmd
}

func (c cmdable) ACLCat(ctx context.Context) *StringSliceCmd {
cmd := NewStringSliceCmd(ctx, "acl", "cat")
_ = c(ctx, cmd)
return cmd
}

func (c cmdable) ACLCatArgs(ctx context.Context, options *ACLCatArgs) *StringSliceCmd {
// if there is a category passed, build new cmd, if there isn't - use the ACLCat method
if options != nil && options.Category != "" {
args := []interface{}{"acl", "cat", options.Category}
cmd := NewStringSliceCmd(ctx, args...)
_ = c(ctx, cmd)
return cmd
}

return c.ACLCat(ctx)
}
50 changes: 50 additions & 0 deletions acl_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,54 @@ var _ = Describe("ACL Commands", func() {
Expect(resAfterDeletion).To(HaveLen(1))
Expect(resAfterDeletion[0]).To(BeEquivalentTo(res[0]))
})

It("lists acl categories and subcategories", func() {
res, err := client.ACLCat(ctx).Result()
Expect(err).NotTo(HaveOccurred())
Expect(len(res)).To(BeNumerically(">", 20))
Expect(res).To(ContainElements(
"read",
"write",
"keyspace",
"dangerous",
"slow",
"set",
"sortedset",
"list",
"hash",
))

res, err = client.ACLCatArgs(ctx, &redis.ACLCatArgs{Category: "read"}).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(ContainElement("get"))
})

It("lists acl categories and subcategories with Modules", func() {
SkipBeforeRedisMajor(8, "modules are included in acl for redis version >= 8")
aclTestCase := map[string]string{
"search": "FT.CREATE",
"bloom": "bf.add",
"json": "json.get",
"cuckoo": "cf.insert",
"cms": "cms.query",
"topk": "topk.list",
"tdigest": "tdigest.rank",
"timeseries": "ts.range",
}
var cats []interface{}

for cat, subitem := range aclTestCase {
cats = append(cats, cat)

res, err := client.ACLCatArgs(ctx, &redis.ACLCatArgs{
Category: cat,
}).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(ContainElement(subitem))
}

res, err := client.ACLCat(ctx).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(ContainElements(cats...))
})
})

0 comments on commit e94b310

Please sign in to comment.