Skip to content

Commit 4296b5b

Browse files
Additional listeners should inherit the configured authentication method (#7594)
Co-authored-by: Eddú Meléndez Gonzales <[email protected]>
1 parent 202680e commit 4296b5b

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

modules/redpanda/src/main/java/org/testcontainers/redpanda/RedpandaContainer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ private Transferable getRedpandaFile(Configuration cfg) {
232232
Map<String, Object> listenerMap = new HashMap<>();
233233
listenerMap.put("address", listener.getAddress());
234234
listenerMap.put("port", listener.getPort());
235+
listenerMap.put("authentication_method", this.authenticationMethod);
235236
return listenerMap;
236237
})
237238
.collect(Collectors.toList());

modules/redpanda/src/main/resources/testcontainers/redpanda.yaml.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ redpanda:
2525
- address: 0.0.0.0
2626
name: ${listener.address}
2727
port: ${listener.port}
28+
authentication_method: ${listener.authentication_method}
2829
</#list>
2930

3031
advertised_kafka_api:

modules/redpanda/src/test/java/org/testcontainers/redpanda/RedpandaContainerTest.java

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.time.Duration;
3232
import java.util.Collection;
3333
import java.util.Collections;
34+
import java.util.HashMap;
3435
import java.util.List;
3536
import java.util.Map;
3637
import java.util.UUID;
@@ -138,6 +139,84 @@ public void testUsageWithListener() throws Exception {
138139
}
139140
}
140141

142+
@Test
143+
public void testUsageWithListenerAndSasl() throws Exception {
144+
final String username = "panda";
145+
final String password = "pandapass";
146+
final String algorithm = "SCRAM-SHA-256";
147+
148+
try (
149+
Network network = Network.newNetwork();
150+
RedpandaContainer redpanda = new RedpandaContainer("docker.redpanda.com/redpandadata/redpanda:v23.1.7")
151+
.enableAuthorization()
152+
.enableSasl()
153+
.withSuperuser("panda")
154+
.withListener(() -> "my-panda:29092")
155+
.withNetwork(network);
156+
GenericContainer<?> kcat = new GenericContainer<>("confluentinc/cp-kcat:7.4.1")
157+
.withCreateContainerCmdModifier(cmd -> {
158+
cmd.withEntrypoint("sh");
159+
})
160+
.withCopyToContainer(Transferable.of("Message produced by kcat"), "/data/msgs.txt")
161+
.withNetwork(network)
162+
.withCommand("-c", "tail -f /dev/null")
163+
) {
164+
redpanda.start();
165+
166+
String adminUrl = String.format("%s/v1/security/users", redpanda.getAdminAddress());
167+
Map<String, String> params = new HashMap<>();
168+
params.put("username", username);
169+
params.put("password", password);
170+
params.put("algorithm", algorithm);
171+
172+
RestAssured.given().contentType("application/json").body(params).post(adminUrl).then().statusCode(200);
173+
174+
kcat.start();
175+
176+
kcat.execInContainer(
177+
"kcat",
178+
"-b",
179+
"my-panda:29092",
180+
"-X",
181+
"security.protocol=SASL_PLAINTEXT",
182+
"-X",
183+
"sasl.mechanisms=" + algorithm,
184+
"-X",
185+
"sasl.username=" + username,
186+
"-X",
187+
"sasl.password=" + password,
188+
"-t",
189+
"msgs",
190+
"-P",
191+
"-l",
192+
"/data/msgs.txt"
193+
);
194+
195+
String stdout = kcat
196+
.execInContainer(
197+
"kcat",
198+
"-b",
199+
"my-panda:29092",
200+
"-X",
201+
"security.protocol=SASL_PLAINTEXT",
202+
"-X",
203+
"sasl.mechanisms=" + algorithm,
204+
"-X",
205+
"sasl.username=" + username,
206+
"-X",
207+
"sasl.password=" + password,
208+
"-C",
209+
"-t",
210+
"msgs",
211+
"-c",
212+
"1"
213+
)
214+
.getStdout();
215+
216+
assertThat(stdout).contains("Message produced by kcat");
217+
}
218+
}
219+
141220
@SneakyThrows
142221
@Test
143222
public void enableSaslWithSuccessfulTopicCreation() {

0 commit comments

Comments
 (0)