|
| 1 | +package com.devshawn.kafka.gitops.config |
| 2 | + |
| 3 | + |
| 4 | +import org.apache.kafka.common.config.SaslConfigs |
| 5 | +import org.junit.ClassRule |
| 6 | +import org.junit.contrib.java.lang.system.EnvironmentVariables |
| 7 | +import spock.lang.Shared |
| 8 | +import spock.lang.Specification |
| 9 | + |
| 10 | +class KafkaGitopsConfigLoaderSpec extends Specification { |
| 11 | + |
| 12 | + @Shared |
| 13 | + @ClassRule |
| 14 | + EnvironmentVariables environmentVariables |
| 15 | + |
| 16 | + void setupSpec() { |
| 17 | + environmentVariables.set("KAFKA_BOOTSTRAP_SERVERS", "localhost:9092") |
| 18 | + environmentVariables.set("KAFKA_SASL_MECHANISM", "PLAIN") |
| 19 | + environmentVariables.set("KAFKA_SECURITY_PROTOCOL", "SASL_PLAINTEXT") |
| 20 | + } |
| 21 | + |
| 22 | + void 'test username and password shortcut'() { |
| 23 | + setup: |
| 24 | + environmentVariables.set("KAFKA_SASL_JAAS_USERNAME", "test") |
| 25 | + environmentVariables.set("KAFKA_SASL_JAAS_PASSWORD", "test-secret") |
| 26 | + |
| 27 | + when: |
| 28 | + KafkaGitopsConfig config = KafkaGitopsConfigLoader.load() |
| 29 | + |
| 30 | + then: |
| 31 | + config |
| 32 | + config.config.get(SaslConfigs.SASL_JAAS_CONFIG) == "org.apache.kafka.common.security.plain.PlainLoginModule required username=\"test\" password=\"test-secret\";" |
| 33 | + } |
| 34 | + |
| 35 | + void 'test escaping username and password shortcut'() { |
| 36 | + setup: |
| 37 | + environmentVariables.set("KAFKA_SASL_JAAS_USERNAME", "te\"st") |
| 38 | + environmentVariables.set("KAFKA_SASL_JAAS_PASSWORD", "te\"st-secr\"et") |
| 39 | + |
| 40 | + when: |
| 41 | + KafkaGitopsConfig config = KafkaGitopsConfigLoader.load() |
| 42 | + |
| 43 | + then: |
| 44 | + config |
| 45 | + config.config.get(SaslConfigs.SASL_JAAS_CONFIG) == "org.apache.kafka.common.security.plain.PlainLoginModule required username=\"te\\\"st\" password=\"te\\\"st-secr\\\"et\";" |
| 46 | + } |
| 47 | + |
| 48 | + |
| 49 | +} |
0 commit comments