Skip to content

Commit d76e39e

Browse files
authored
Add modules ACL support (#3102)
* Test HASH module ACL support * Support consolidated CONFIG according to design doc with Redis 8.0-M03 * format imports * Based on RedisContainerIntegrationTests * Use 8.0-M04-pre image * add version condition
1 parent 042f6a9 commit d76e39e

File tree

4 files changed

+174
-2
lines changed

4 files changed

+174
-2
lines changed

src/main/java/io/lettuce/core/AclCategory.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,45 @@ public enum AclCategory {
111111
/**
112112
* scripting command
113113
*/
114-
SCRIPTING
114+
SCRIPTING,
115+
116+
/**
117+
* bloom command
118+
*/
119+
BLOOM,
120+
121+
/**
122+
* cuckoo command
123+
*/
124+
CUCKOO,
125+
126+
/**
127+
* count-min-sketch command
128+
*/
129+
CMS,
130+
131+
/**
132+
* top-k command
133+
*/
134+
TOPK,
135+
136+
/**
137+
* t-digest command
138+
*/
139+
TDIGEST,
140+
141+
/**
142+
* search command
143+
*/
144+
SEARCH,
145+
146+
/**
147+
* timeseries command
148+
*/
149+
TIMESERIES,
150+
151+
/**
152+
* json command
153+
*/
154+
JSON
115155
}

src/main/java/io/lettuce/core/models/command/CommandDetailParser.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ public class CommandDetailParser {
9595
aclCategoriesMap.put("@connection", AclCategory.CONNECTION);
9696
aclCategoriesMap.put("@transaction", AclCategory.TRANSACTION);
9797
aclCategoriesMap.put("@scripting", AclCategory.SCRIPTING);
98+
aclCategoriesMap.put("@bloom", AclCategory.BLOOM);
99+
aclCategoriesMap.put("@cuckoo", AclCategory.CUCKOO);
100+
aclCategoriesMap.put("@cms", AclCategory.CMS);
101+
aclCategoriesMap.put("@topk", AclCategory.TOPK);
102+
aclCategoriesMap.put("@tdigest", AclCategory.TDIGEST);
103+
aclCategoriesMap.put("@search", AclCategory.SEARCH);
104+
aclCategoriesMap.put("@timeseries", AclCategory.TIMESERIES);
105+
aclCategoriesMap.put("@json", AclCategory.JSON);
106+
98107
ACL_CATEGORY_MAPPING = Collections.unmodifiableMap(aclCategoriesMap);
99108
}
100109

src/test/java/io/lettuce/core/RedisContainerIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class RedisContainerIntegrationTests {
2626

2727
private static final String REDIS_STACK_CLUSTER = "clustered-stack";
2828

29-
private static final String REDIS_STACK_VERSION = System.getProperty("REDIS_STACK_VERSION", "8.0-M02");;
29+
private static final String REDIS_STACK_VERSION = System.getProperty("REDIS_STACK_VERSION", "8.0-M04-pre");;
3030

3131
private static Exception initializationException;
3232

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
* Copyright 2011-Present, Redis Ltd. and Contributors
3+
* All rights reserved.
4+
*
5+
* Licensed under the MIT License.
6+
*
7+
* This file contains contributions from third-party contributors
8+
* licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* https://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
package io.lettuce.core.commands;
21+
22+
import io.lettuce.core.*;
23+
import io.lettuce.core.api.sync.RedisCommands;
24+
25+
import io.lettuce.test.condition.RedisConditions;
26+
import org.junit.jupiter.api.*;
27+
28+
import java.util.Arrays;
29+
30+
import static io.lettuce.TestTags.INTEGRATION_TEST;
31+
import static org.assertj.core.api.Assertions.assertThat;
32+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
33+
34+
/**
35+
* Integration tests for ACL commands with Redis modules since Redis 8.0.
36+
*
37+
* @author M Sazzadul Hoque
38+
*/
39+
@Tag(INTEGRATION_TEST)
40+
public class ConsolidatedAclCommandIntegrationTests extends RedisContainerIntegrationTests {
41+
42+
private static RedisClient client;
43+
44+
private static RedisCommands<String, String> redis;
45+
46+
@BeforeAll
47+
public static void setup() {
48+
RedisURI redisURI = RedisURI.Builder.redis("127.0.0.1").withPort(16379).build();
49+
50+
client = RedisClient.create(redisURI);
51+
redis = client.connect().sync();
52+
assumeTrue(RedisConditions.of(redis).hasVersionGreaterOrEqualsTo("7.9"));
53+
}
54+
55+
@AfterAll
56+
static void teardown() {
57+
if (client != null) {
58+
client.shutdown();
59+
}
60+
}
61+
62+
@BeforeEach
63+
void setUp() {
64+
redis.flushall();
65+
redis.aclUsers().stream().filter(o -> !"default".equals(o)).forEach(redis::aclDeluser);
66+
redis.aclLogReset();
67+
}
68+
69+
@Test
70+
public void listACLCategoriesTest() {
71+
assertThat(redis.aclCat()).containsAll(Arrays.asList(AclCategory.BLOOM, AclCategory.CUCKOO, AclCategory.CMS,
72+
AclCategory.TOPK, AclCategory.TDIGEST, AclCategory.SEARCH, AclCategory.TIMESERIES, AclCategory.JSON));
73+
}
74+
75+
@Test
76+
void grantBloomCommandCatTest() {
77+
grantModuleCommandCatTest(AclCategory.BLOOM, "bloom");
78+
}
79+
80+
@Test
81+
void grantCuckooCommandCatTest() {
82+
grantModuleCommandCatTest(AclCategory.CUCKOO, "cuckoo");
83+
}
84+
85+
@Test
86+
void grantCmsCommandCatTest() {
87+
grantModuleCommandCatTest(AclCategory.CMS, "cms");
88+
}
89+
90+
@Test
91+
void grantTopkCommandCatTest() {
92+
grantModuleCommandCatTest(AclCategory.TOPK, "topk");
93+
}
94+
95+
@Test
96+
void grantTdigestCommandCatTest() {
97+
grantModuleCommandCatTest(AclCategory.TDIGEST, "tdigest");
98+
}
99+
100+
@Test
101+
void grantSearchCommandCatTest() {
102+
grantModuleCommandCatTest(AclCategory.SEARCH, "search");
103+
}
104+
105+
@Test
106+
void grantTimeseriesCommandCatTest() {
107+
grantModuleCommandCatTest(AclCategory.TIMESERIES, "timeseries");
108+
}
109+
110+
@Test
111+
void grantJsonCommandCatTest() {
112+
grantModuleCommandCatTest(AclCategory.JSON, "json");
113+
}
114+
115+
private void grantModuleCommandCatTest(AclCategory category, String categoryStr) {
116+
assertThat(redis.aclDeluser("foo")).isNotNull();
117+
AclSetuserArgs args = AclSetuserArgs.Builder.on().addCategory(category);
118+
assertThat(redis.aclSetuser("foo", args)).isEqualTo("OK");
119+
assertThat(redis.aclGetuser("foo")).contains("-@all +@" + categoryStr);
120+
assertThat(redis.aclDeluser("foo")).isNotNull();
121+
}
122+
123+
}

0 commit comments

Comments
 (0)