Skip to content

Commit 8cfff61

Browse files
committed
refactor acl tests
1 parent 1bdb7a7 commit 8cfff61

File tree

2 files changed

+67
-58
lines changed

2 files changed

+67
-58
lines changed

acl_commands_test.go

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,74 @@ import (
1010
)
1111

1212
var TestUserName string = "goredis"
13+
var _ = Describe("ACL", func() {
14+
var client *redis.Client
15+
var ctx context.Context
16+
17+
BeforeEach(func() {
18+
ctx = context.Background()
19+
opt := redisOptions()
20+
client = redis.NewClient(opt)
21+
})
22+
23+
It("should ACL LOG", Label("NonRedisEnterprise"), func() {
24+
Expect(client.ACLLogReset(ctx).Err()).NotTo(HaveOccurred())
25+
err := client.Do(ctx, "acl", "setuser", "test", ">test", "on", "allkeys", "+get").Err()
26+
Expect(err).NotTo(HaveOccurred())
27+
28+
clientAcl := redis.NewClient(redisOptions())
29+
clientAcl.Options().Username = "test"
30+
clientAcl.Options().Password = "test"
31+
clientAcl.Options().DB = 0
32+
_ = clientAcl.Set(ctx, "mystring", "foo", 0).Err()
33+
_ = clientAcl.HSet(ctx, "myhash", "foo", "bar").Err()
34+
_ = clientAcl.SAdd(ctx, "myset", "foo", "bar").Err()
35+
36+
logEntries, err := client.ACLLog(ctx, 10).Result()
37+
Expect(err).NotTo(HaveOccurred())
38+
Expect(len(logEntries)).To(Equal(4))
39+
40+
for _, entry := range logEntries {
41+
Expect(entry.Reason).To(Equal("command"))
42+
Expect(entry.Context).To(Equal("toplevel"))
43+
Expect(entry.Object).NotTo(BeEmpty())
44+
Expect(entry.Username).To(Equal("test"))
45+
Expect(entry.AgeSeconds).To(BeNumerically(">=", 0))
46+
Expect(entry.ClientInfo).NotTo(BeNil())
47+
Expect(entry.EntryID).To(BeNumerically(">=", 0))
48+
Expect(entry.TimestampCreated).To(BeNumerically(">=", 0))
49+
Expect(entry.TimestampLastUpdated).To(BeNumerically(">=", 0))
50+
}
51+
52+
limitedLogEntries, err := client.ACLLog(ctx, 2).Result()
53+
Expect(err).NotTo(HaveOccurred())
54+
Expect(len(limitedLogEntries)).To(Equal(2))
55+
56+
// cleanup after creating the user
57+
err = client.Do(ctx, "acl", "deluser", "test").Err()
58+
Expect(err).NotTo(HaveOccurred())
59+
})
60+
61+
It("should ACL LOG RESET", Label("NonRedisEnterprise"), func() {
62+
// Call ACL LOG RESET
63+
resetCmd := client.ACLLogReset(ctx)
64+
Expect(resetCmd.Err()).NotTo(HaveOccurred())
65+
Expect(resetCmd.Val()).To(Equal("OK"))
66+
67+
// Verify that the log is empty after the reset
68+
logEntries, err := client.ACLLog(ctx, 10).Result()
69+
Expect(err).NotTo(HaveOccurred())
70+
Expect(len(logEntries)).To(Equal(0))
71+
})
72+
73+
})
1374
var _ = Describe("ACL user commands", Label("NonRedisEnterprise"), func() {
1475
var client *redis.Client
1576
var ctx context.Context
1677

1778
BeforeEach(func() {
1879
ctx = context.Background()
1980
opt := redisOptions()
20-
opt.UnstableResp3 = true
2181
client = redis.NewClient(opt)
2282
})
2383

@@ -58,6 +118,12 @@ var _ = Describe("ACL user commands", Label("NonRedisEnterprise"), func() {
58118
Expect(resAfterDeletion).To(HaveLen(1))
59119
Expect(resAfterDeletion[0]).To(BeEquivalentTo(res[0]))
60120
})
121+
122+
It("should acl dryrun", func() {
123+
dryRun := client.ACLDryRun(ctx, "default", "get", "randomKey")
124+
Expect(dryRun.Err()).NotTo(HaveOccurred())
125+
Expect(dryRun.Val()).To(Equal("OK"))
126+
})
61127
})
62128

63129
var _ = Describe("ACL permissions", Label("NonRedisEnterprise"), func() {
@@ -324,7 +390,6 @@ var _ = Describe("ACL Categories", func() {
324390
BeforeEach(func() {
325391
ctx = context.Background()
326392
opt := redisOptions()
327-
opt.UnstableResp3 = true
328393
client = redis.NewClient(opt)
329394
})
330395

commands_test.go

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,12 +2228,6 @@ var _ = Describe("Commands", func() {
22282228
Expect(replace.Val()).To(Equal(int64(1)))
22292229
})
22302230

2231-
It("should acl dryrun", func() {
2232-
dryRun := client.ACLDryRun(ctx, "default", "get", "randomKey")
2233-
Expect(dryRun.Err()).NotTo(HaveOccurred())
2234-
Expect(dryRun.Val()).To(Equal("OK"))
2235-
})
2236-
22372231
It("should fail module loadex", Label("NonRedisEnterprise"), func() {
22382232
dryRun := client.ModuleLoadex(ctx, &redis.ModuleLoadexConfig{
22392233
Path: "/path/to/non-existent-library.so",
@@ -2281,56 +2275,6 @@ var _ = Describe("Commands", func() {
22812275

22822276
Expect(args).To(Equal(expectedArgs))
22832277
})
2284-
2285-
It("should ACL LOG", Label("NonRedisEnterprise"), func() {
2286-
Expect(client.ACLLogReset(ctx).Err()).NotTo(HaveOccurred())
2287-
err := client.Do(ctx, "acl", "setuser", "test", ">test", "on", "allkeys", "+get").Err()
2288-
Expect(err).NotTo(HaveOccurred())
2289-
2290-
clientAcl := redis.NewClient(redisOptions())
2291-
clientAcl.Options().Username = "test"
2292-
clientAcl.Options().Password = "test"
2293-
clientAcl.Options().DB = 0
2294-
_ = clientAcl.Set(ctx, "mystring", "foo", 0).Err()
2295-
_ = clientAcl.HSet(ctx, "myhash", "foo", "bar").Err()
2296-
_ = clientAcl.SAdd(ctx, "myset", "foo", "bar").Err()
2297-
2298-
logEntries, err := client.ACLLog(ctx, 10).Result()
2299-
Expect(err).NotTo(HaveOccurred())
2300-
Expect(len(logEntries)).To(Equal(4))
2301-
2302-
for _, entry := range logEntries {
2303-
Expect(entry.Reason).To(Equal("command"))
2304-
Expect(entry.Context).To(Equal("toplevel"))
2305-
Expect(entry.Object).NotTo(BeEmpty())
2306-
Expect(entry.Username).To(Equal("test"))
2307-
Expect(entry.AgeSeconds).To(BeNumerically(">=", 0))
2308-
Expect(entry.ClientInfo).NotTo(BeNil())
2309-
Expect(entry.EntryID).To(BeNumerically(">=", 0))
2310-
Expect(entry.TimestampCreated).To(BeNumerically(">=", 0))
2311-
Expect(entry.TimestampLastUpdated).To(BeNumerically(">=", 0))
2312-
}
2313-
2314-
limitedLogEntries, err := client.ACLLog(ctx, 2).Result()
2315-
Expect(err).NotTo(HaveOccurred())
2316-
Expect(len(limitedLogEntries)).To(Equal(2))
2317-
2318-
// cleanup after creating the user
2319-
err = client.Do(ctx, "acl", "deluser", "test").Err()
2320-
Expect(err).NotTo(HaveOccurred())
2321-
})
2322-
2323-
It("should ACL LOG RESET", Label("NonRedisEnterprise"), func() {
2324-
// Call ACL LOG RESET
2325-
resetCmd := client.ACLLogReset(ctx)
2326-
Expect(resetCmd.Err()).NotTo(HaveOccurred())
2327-
Expect(resetCmd.Val()).To(Equal("OK"))
2328-
2329-
// Verify that the log is empty after the reset
2330-
logEntries, err := client.ACLLog(ctx, 10).Result()
2331-
Expect(err).NotTo(HaveOccurred())
2332-
Expect(len(logEntries)).To(Equal(0))
2333-
})
23342278
})
23352279

23362280
Describe("hashes", func() {

0 commit comments

Comments
 (0)