Skip to content

Commit 7bea464

Browse files
authored
test: fix tests and use constants (#11)
1 parent a9bd5c4 commit 7bea464

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

src/main/java/com/devshawn/kafka/gitops/config/KafkaGitopsConfigLoader.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.devshawn.kafka.gitops.exception.MissingConfigurationException;
44
import org.apache.kafka.clients.CommonClientConfigs;
5+
import org.apache.kafka.common.config.SaslConfigs;
56
import org.slf4j.LoggerFactory;
67

78
import java.util.HashMap;
@@ -56,22 +57,19 @@ private static void handleDefaultConfig(Map<String, Object> config) {
5657

5758
private static void handleAuthentication(AtomicReference<String> username, AtomicReference<String> password, Map<String, Object> config) {
5859
if (username.get() != null && password.get() != null) {
59-
6060
// Do we need the Plain or SCRAM module?
6161
String loginModule = null;
62-
if (config.get("sasl.mechanism").equals("PLAIN")) {
62+
if (config.get(SaslConfigs.SASL_MECHANISM).equals("PLAIN")) {
6363
loginModule = "org.apache.kafka.common.security.plain.PlainLoginModule";
64-
}
65-
else if (config.get("sasl.mechanism").equals("SCRAM-SHA-256")) {
64+
} else if (config.get(SaslConfigs.SASL_MECHANISM).equals("SCRAM-SHA-256")) {
6665
loginModule = "org.apache.kafka.common.security.scram.ScramLoginModule";
67-
}
68-
else {
69-
throw new MissingConfigurationException("KAFKA_SASL_MECHANISM");
66+
} else {
67+
throw new MissingConfigurationException("KAFKA_SASL_MECHANISM");
7068
}
7169

7270
String value = String.format("%s required username=\"%s\" password=\"%s\";",
7371
loginModule, username.get(), password.get());
74-
config.put("sasl.jaas.config", value);
72+
config.put(SaslConfigs.SASL_JAAS_CONFIG, value);
7573
} else if (username.get() != null) {
7674
throw new MissingConfigurationException("KAFKA_SASL_JAAS_PASSWORD");
7775
} else if (password.get() != null) {

src/test/resources/plans/seed-topic-modification-3-apply-output.txt

+8-8
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ Successfully applied.
4141

4242
Applying: [DELETE]
4343

44-
+ [ACL] Unnamed ACL
45-
+ resource_name: test-topic
46-
+ resource_type: TOPIC
47-
+ resource_pattern: LITERAL
48-
+ resource_principal: User:test
49-
+ host: *
50-
+ operation: READ
51-
+ permission: ALLOW
44+
- [ACL] Unnamed ACL
45+
- resource_name: test-topic
46+
- resource_type: TOPIC
47+
- resource_pattern: LITERAL
48+
- resource_principal: User:test
49+
- host: *
50+
- operation: READ
51+
- permission: ALLOW
5252

5353

5454
Successfully applied.

src/test/resources/plans/seed-topic-modification-apply-output.txt

+8-8
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ Successfully applied.
3838

3939
Applying: [DELETE]
4040

41-
+ [ACL] Unnamed ACL
42-
+ resource_name: test-topic
43-
+ resource_type: TOPIC
44-
+ resource_pattern: LITERAL
45-
+ resource_principal: User:test
46-
+ host: *
47-
+ operation: READ
48-
+ permission: ALLOW
41+
- [ACL] Unnamed ACL
42+
- resource_name: test-topic
43+
- resource_type: TOPIC
44+
- resource_pattern: LITERAL
45+
- resource_principal: User:test
46+
- host: *
47+
- operation: READ
48+
- permission: ALLOW
4949

5050

5151
Successfully applied.

0 commit comments

Comments
 (0)