Skip to content

Commit e94b310

Browse files
committed
test presence of categories in acl cat
1 parent fcc0007 commit e94b310

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

acl_commands.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,20 @@ import "context"
44

55
type ACLCmdable interface {
66
ACLDryRun(ctx context.Context, username string, command ...interface{}) *StringCmd
7+
78
ACLLog(ctx context.Context, count int64) *ACLLogCmd
89
ACLLogReset(ctx context.Context) *StatusCmd
10+
911
ACLSetUser(ctx context.Context, username string, rules ...string) *StatusCmd
1012
ACLDelUser(ctx context.Context, username string) *IntCmd
1113
ACLList(ctx context.Context) *StringSliceCmd
14+
15+
ACLCat(ctx context.Context) *StringSliceCmd
16+
ACLCatArgs(ctx context.Context, options *ACLCatArgs) *StringSliceCmd
17+
}
18+
19+
type ACLCatArgs struct {
20+
Category string
1221
}
1322

1423
func (c cmdable) ACLDryRun(ctx context.Context, username string, command ...interface{}) *StringCmd {
@@ -65,3 +74,21 @@ func (c cmdable) ACLList(ctx context.Context) *StringSliceCmd {
6574
_ = c(ctx, cmd)
6675
return cmd
6776
}
77+
78+
func (c cmdable) ACLCat(ctx context.Context) *StringSliceCmd {
79+
cmd := NewStringSliceCmd(ctx, "acl", "cat")
80+
_ = c(ctx, cmd)
81+
return cmd
82+
}
83+
84+
func (c cmdable) ACLCatArgs(ctx context.Context, options *ACLCatArgs) *StringSliceCmd {
85+
// if there is a category passed, build new cmd, if there isn't - use the ACLCat method
86+
if options != nil && options.Category != "" {
87+
args := []interface{}{"acl", "cat", options.Category}
88+
cmd := NewStringSliceCmd(ctx, args...)
89+
_ = c(ctx, cmd)
90+
return cmd
91+
}
92+
93+
return c.ACLCat(ctx)
94+
}

acl_commands_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,54 @@ var _ = Describe("ACL Commands", func() {
5757
Expect(resAfterDeletion).To(HaveLen(1))
5858
Expect(resAfterDeletion[0]).To(BeEquivalentTo(res[0]))
5959
})
60+
61+
It("lists acl categories and subcategories", func() {
62+
res, err := client.ACLCat(ctx).Result()
63+
Expect(err).NotTo(HaveOccurred())
64+
Expect(len(res)).To(BeNumerically(">", 20))
65+
Expect(res).To(ContainElements(
66+
"read",
67+
"write",
68+
"keyspace",
69+
"dangerous",
70+
"slow",
71+
"set",
72+
"sortedset",
73+
"list",
74+
"hash",
75+
))
76+
77+
res, err = client.ACLCatArgs(ctx, &redis.ACLCatArgs{Category: "read"}).Result()
78+
Expect(err).NotTo(HaveOccurred())
79+
Expect(res).To(ContainElement("get"))
80+
})
81+
82+
It("lists acl categories and subcategories with Modules", func() {
83+
SkipBeforeRedisMajor(8, "modules are included in acl for redis version >= 8")
84+
aclTestCase := map[string]string{
85+
"search": "FT.CREATE",
86+
"bloom": "bf.add",
87+
"json": "json.get",
88+
"cuckoo": "cf.insert",
89+
"cms": "cms.query",
90+
"topk": "topk.list",
91+
"tdigest": "tdigest.rank",
92+
"timeseries": "ts.range",
93+
}
94+
var cats []interface{}
95+
96+
for cat, subitem := range aclTestCase {
97+
cats = append(cats, cat)
98+
99+
res, err := client.ACLCatArgs(ctx, &redis.ACLCatArgs{
100+
Category: cat,
101+
}).Result()
102+
Expect(err).NotTo(HaveOccurred())
103+
Expect(res).To(ContainElement(subitem))
104+
}
105+
106+
res, err := client.ACLCat(ctx).Result()
107+
Expect(err).NotTo(HaveOccurred())
108+
Expect(res).To(ContainElements(cats...))
109+
})
60110
})

0 commit comments

Comments
 (0)