12
12
import org .junit .Rule ;
13
13
import org .junit .Test ;
14
14
import org .junit .rules .ExpectedException ;
15
+ import org .junit .rules .TemporaryFolder ;
15
16
import org .mockito .Mock ;
16
17
18
+ import java .io .File ;
19
+ import java .io .FileWriter ;
20
+ import java .io .IOException ;
17
21
import java .util .HashMap ;
18
22
import java .util .List ;
19
23
import java .util .Properties ;
@@ -31,6 +35,9 @@ public class StreamConfigTest {
31
35
@ Rule
32
36
public ExpectedException thrown = ExpectedException .none ();
33
37
38
+ @ Rule
39
+ public TemporaryFolder temporaryFolder = new TemporaryFolder ();
40
+
34
41
@ Mock
35
42
private Configuration configuration ;
36
43
@@ -121,18 +128,17 @@ public void shouldParseKafkaPropertiesWithSSLConfigurations() {
121
128
kafkaPropMap .put ("bootstrap.servers" , "localhost:9092" );
122
129
kafkaPropMap .put ("auto.offset.reset" , "latest" );
123
130
kafkaPropMap .put ("auto.commit.enable" , "" );
124
- kafkaPropMap .put ("ssl.keystore.password" , "test-keystore-pass" );
131
+ kafkaPropMap .put (Constants . KAFKA_PROPS_SSL_KEYSTORE_PASSWORD_KEY , "test-keystore-pass" );
125
132
kafkaPropMap .put ("ssl.keystore.type" , "JKS" );
126
133
kafkaPropMap .put ("ssl.keystore.location" , "test-keystore-location" );
127
134
kafkaPropMap .put ("ssl.protocol" , "SSL" );
128
135
kafkaPropMap .put ("ssl.key.password" , "test-key-pass" );
129
136
kafkaPropMap .put ("ssl.truststore.type" , "JKS" );
130
137
kafkaPropMap .put ("ssl.truststore.location" , "test-truststore-location" );
131
- kafkaPropMap .put ("ssl.truststore.password" , "test-truststore-pass" );
138
+ kafkaPropMap .put (Constants . KAFKA_PROPS_SSL_TRUSTSTORE_PASSWORD_KEY , "test-truststore-pass" );
132
139
kafkaPropMap .put ("security.protocol" , "SSL" );
133
140
134
141
135
-
136
142
Properties properties = new Properties ();
137
143
properties .putAll (kafkaPropMap );
138
144
@@ -247,6 +253,20 @@ public void shouldParseMultipleAdditionalConsumerConfigs() {
247
253
assertEquals ("1000" , secondStreamProperties .getProperty ("offset.flush.interval.ms" ));
248
254
}
249
255
256
+ @ Test
257
+ public void shouldParseSslPasswordsConfig () throws IOException {
258
+ File keystorePassword = writeDummyPasswordFile ("ssl-keystore-password.txt" , "keystore-password" );
259
+ File truststorePassword = writeDummyPasswordFile ("ssl-truststore-password.txt" , "truststore-password" );
260
+ when (configuration .getString (INPUT_STREAMS , "" ))
261
+ .thenReturn (String .format ("[{\" SOURCE_KAFKA_CONSUMER_CONFIG_SSL_KEYSTORE_PASSWORD_FILE_LOCATION\" : \" %s\" , \" SOURCE_KAFKA_CONSUMER_CONFIG_SSL_TRUSTSTORE_PASSWORD_FILE_LOCATION\" : \" %s\" }]" , keystorePassword .getAbsolutePath (), truststorePassword .getAbsolutePath ()));
262
+ StreamConfig [] streamConfigs = StreamConfig .parse (configuration );
263
+
264
+ Properties streamProperties = streamConfigs [0 ].getKafkaProps (configuration );
265
+
266
+ assertEquals ("keystore-password" , streamProperties .getProperty ("ssl.keystore.password" ));
267
+ assertEquals ("truststore-password" , streamProperties .getProperty ("ssl.truststore.password" ));
268
+ }
269
+
250
270
@ Test (expected = IllegalArgumentException .class )
251
271
public void shouldThrowIllegalArgumentExceptionIfAdditionalKafkaPropsNotMatchingPrefix () {
252
272
String streamConfig = "[ { \" SOURCE_KAFKA_TOPIC_NAMES\" : \" test-topic\" , \" INPUT_SCHEMA_TABLE\" : \" data_stream\" , \" INPUT_SCHEMA_PROTO_CLASS\" : \" com.tests.TestMessage\" , \" INPUT_SCHEMA_EVENT_TIMESTAMP_FIELD_INDEX\" : \" 41\" , \" SOURCE_KAFKA_CONSUMER_CONFIG_BOOTSTRAP_SERVERS\" : \" localhost:9092\" ,\" SOURCE_KAFKA_CONSUMER_CONFIG_SECURITY_PROTOCOL\" : \" SASL_PLAINTEXT\" ,\" SOURCE_KAFKA_CONSUMER_CONFIG_SASL_MECHANISM\" :\" SCRAM-SHA-512\" ,\" SOURCE_KAFKA_CONSUMER_CONFIG_SASL_JAAS_CONFIG\" :\" org.apache.kafka.common.security.scram.ScramLoginModule required username=\\ \" username\\ \" password=\\ \" password\\ \" ;\" , \" SOURCE_KAFKA_CONSUMER_CONFIG_AUTO_COMMIT_ENABLE\" : \" false\" , \" SOURCE_KAFKA_CONSUMER_CONFIG_AUTO_OFFSET_RESET\" : \" latest\" , \" SOURCE_KAFKA_CONSUMER_CONFIG_GROUP_ID\" : \" dummy-consumer-group\" , \" SOURCE_KAFKA_NAME\" : \" local-kafka-stream\" , \" SOURCE_KAFKA_CONSUMER_ADDITIONAL_CONFIGURATIONS\" : {\" SOURCE_KAFKA_CONSUMER_CONFIG_SSL_KEYSTORE_KEY\" : \" ssl_keystore_key\" , \" SOURCE_KAFKA_CONSUMER_CONFIG_SSL_KEYSTORE_LOCATION\" : \" ssl_keystore_location\" } }, {\" INPUT_SCHEMA_TABLE\" : \" data_stream_1\" , \" SOURCE_KAFKA_TOPIC_NAMES\" : \" test-topic\" , \" INPUT_DATATYPE\" : \" JSON\" , \" INPUT_SCHEMA_JSON_SCHEMA\" : \" { \\ \" $schema\\ \" : \\ \" https://json-schema.org/draft/2020-12/schema\\ \" , \\ \" $id\\ \" : \\ \" https://example.com/product.schema.json\\ \" , \\ \" title\\ \" : \\ \" Product\\ \" , \\ \" description\\ \" : \\ \" A product from Acme's catalog\\ \" , \\ \" type\\ \" : \\ \" object\\ \" , \\ \" properties\\ \" : { \\ \" id\\ \" : { \\ \" description\\ \" : \\ \" The unique identifier for a product\\ \" , \\ \" type\\ \" : \\ \" string\\ \" }, \\ \" time\\ \" : { \\ \" description\\ \" : \\ \" event timestamp of the event\\ \" , \\ \" type\\ \" : \\ \" string\\ \" , \\ \" format\\ \" : \\ \" date-time\\ \" } }, \\ \" required\\ \" : [ \\ \" id\\ \" , \\ \" time\\ \" ] }\" , \" INPUT_SCHEMA_EVENT_TIMESTAMP_FIELD_INDEX\" : \" 41\" , \" SOURCE_KAFKA_CONSUMER_CONFIG_BOOTSTRAP_SERVERS\" : \" localhost:9092\" , \" SOURCE_KAFKA_CONSUMER_CONFIG_AUTO_COMMIT_ENABLE\" : \" true\" , \" SOURCE_KAFKA_CONSUMER_CONFIG_AUTO_OFFSET_RESET\" : \" latest\" , \" SOURCE_KAFKA_CONSUMER_CONFIG_GROUP_ID\" : \" dummy-consumer-group\" , \" SOURCE_KAFKA_NAME\" : \" local-kafka-stream\" , \" SOURCE_KAFKA_CONSUMER_ADDITIONAL_CONFIGURATIONS\" : {\" SOURCE_KAFKA_CONSUMER_CONFIG_SSL_KEYSTORE_KEY\" : \" ssl_keystore_key_2\" , \" CONSUMER_CONFIG_SSL_KEYSTORE_LOCATION\" : \" ssl_keystore_location_2\" , \" SOURCE_KAFKA_CONSUMER_CONFIG_OFFSET_FLUSH_INTERVAL_MS\" :\" 1000\" } } ]" ;
@@ -546,4 +566,13 @@ public void shouldTrimLeadingAndTrailingWhitespacesFromParquetFilePathsWhenParqu
546
566
547
567
Assert .assertArrayEquals (new String []{"gs://some-parquet-path" , "gs://another-parquet-path" }, streamConfigs [0 ].getParquetFilePaths ());
548
568
}
569
+
570
+ private File writeDummyPasswordFile (String fileName , String password ) throws IOException {
571
+ File passwordFile = temporaryFolder .newFile (fileName );
572
+ FileWriter writer = new FileWriter (passwordFile );
573
+ writer .write (password );
574
+ writer .close ();
575
+ return passwordFile ;
576
+ }
577
+
549
578
}
0 commit comments