|
15 | 15 | */
|
16 | 16 | package com.datastax.oss.common.sink.config;
|
17 | 17 |
|
| 18 | +import static com.datastax.oss.common.sink.config.AuthenticatorConfig.KEYTAB_OPT; |
18 | 19 | import static com.datastax.oss.common.sink.config.CassandraSinkConfig.COMPRESSION_DEFAULT;
|
19 | 20 | import static com.datastax.oss.common.sink.config.CassandraSinkConfig.COMPRESSION_DRIVER_SETTING;
|
20 | 21 | import static com.datastax.oss.common.sink.config.CassandraSinkConfig.COMPRESSION_OPT;
|
|
39 | 40 | import static com.datastax.oss.common.sink.config.CassandraSinkConfig.SECURE_CONNECT_BUNDLE_OPT;
|
40 | 41 | import static com.datastax.oss.common.sink.config.CassandraSinkConfig.SSL_OPT_PREFIX;
|
41 | 42 | import static com.datastax.oss.common.sink.config.CassandraSinkConfig.withDriverPrefix;
|
| 43 | +import static com.datastax.oss.common.sink.config.SslConfig.KEYSTORE_PATH_OPT; |
| 44 | +import static com.datastax.oss.common.sink.config.SslConfig.OPENSSL_KEY_CERT_CHAIN_OPT; |
| 45 | +import static com.datastax.oss.common.sink.config.SslConfig.OPENSSL_PRIVATE_KEY_OPT; |
42 | 46 | import static com.datastax.oss.common.sink.config.SslConfig.PROVIDER_OPT;
|
| 47 | +import static com.datastax.oss.common.sink.config.SslConfig.TRUSTSTORE_PATH_OPT; |
43 | 48 | import static com.datastax.oss.common.sink.config.TableConfig.MAPPING_OPT;
|
44 | 49 | import static com.datastax.oss.common.sink.config.TableConfig.getTableSettingPath;
|
45 | 50 | import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.CONTACT_POINTS;
|
46 | 51 | import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.METRICS_SESSION_CQL_REQUESTS_INTERVAL;
|
47 | 52 | import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.METRICS_SESSION_ENABLED;
|
48 | 53 | import static com.datastax.oss.dsbulk.tests.assertions.TestAssertions.assertThat;
|
| 54 | +import static java.nio.charset.StandardCharsets.UTF_8; |
49 | 55 | import static org.assertj.core.api.Assertions.assertThat;
|
50 | 56 | import static org.assertj.core.api.Assertions.assertThatCode;
|
51 | 57 | import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
59 | 65 | import com.datastax.oss.driver.shaded.guava.common.collect.Maps;
|
60 | 66 | import com.datastax.oss.dsbulk.tests.logging.LogInterceptingExtension;
|
61 | 67 | import com.datastax.oss.dsbulk.tests.logging.LogInterceptor;
|
62 |
| -import java.io.ByteArrayOutputStream; |
63 | 68 | import java.io.File;
|
64 | 69 | import java.nio.file.Files;
|
65 | 70 | import java.nio.file.attribute.PosixFilePermission;
|
|
69 | 74 | import java.util.List;
|
70 | 75 | import java.util.Map;
|
71 | 76 | import java.util.Set;
|
| 77 | +import java.util.function.Function; |
72 | 78 | import java.util.stream.Stream;
|
73 |
| -import java.util.zip.ZipEntry; |
74 |
| -import java.util.zip.ZipOutputStream; |
75 | 79 | import org.junit.jupiter.api.Test;
|
76 | 80 | import org.junit.jupiter.api.extension.ExtendWith;
|
77 | 81 | import org.junit.jupiter.params.ParameterizedTest;
|
@@ -680,33 +684,80 @@ void should_set_default_driver_setting(String driverSettingName, String expected
|
680 | 684 | }
|
681 | 685 |
|
682 | 686 | @Test
|
683 |
| - void should_unpack_base64_zip_file_legacy_name() throws Exception { |
684 |
| - should_unpack_base64_zip_file(SECURE_CONNECT_BUNDLE_OPT); |
| 687 | + void should_unpack_base64_secureBundle_legacy_name() throws Exception { |
| 688 | + should_unpack_base64_file( |
| 689 | + SECURE_CONNECT_BUNDLE_OPT, |
| 690 | + (CassandraSinkConfig config) -> { |
| 691 | + assertThat(config.isCloud()).isEqualTo(true); |
| 692 | + return config.getJavaDriverSettings().get(SECURE_CONNECT_BUNDLE_DRIVER_SETTING); |
| 693 | + }); |
685 | 694 | }
|
686 | 695 |
|
687 | 696 | @Test
|
688 |
| - void should_unpack_base64_zip_file() throws Exception { |
689 |
| - should_unpack_base64_zip_file(SECURE_CONNECT_BUNDLE_DRIVER_SETTING); |
| 697 | + void should_unpack_base64_secureBundle() throws Exception { |
| 698 | + should_unpack_base64_file( |
| 699 | + SECURE_CONNECT_BUNDLE_DRIVER_SETTING, |
| 700 | + (CassandraSinkConfig config) -> { |
| 701 | + assertThat(config.isCloud()).isEqualTo(true); |
| 702 | + return config.getJavaDriverSettings().get(SECURE_CONNECT_BUNDLE_DRIVER_SETTING); |
| 703 | + }); |
690 | 704 | }
|
691 | 705 |
|
692 |
| - void should_unpack_base64_zip_file(String entryName) throws Exception { |
693 |
| - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); |
694 |
| - // it is not necessary that we really have a zip file here |
695 |
| - // but this gives the flavour of the type of content we expect |
696 |
| - // to be encoded in the secureBundleZip |
697 |
| - try (ZipOutputStream zip = new ZipOutputStream(buffer)) { |
698 |
| - zip.putNextEntry(new ZipEntry("file.bin")); |
699 |
| - zip.write(1234); |
700 |
| - zip.closeEntry(); |
701 |
| - } |
702 |
| - byte[] zipFileContents = buffer.toByteArray(); |
| 706 | + @Test |
| 707 | + void should_unpack_base64_ssl_keystore() throws Exception { |
| 708 | + should_unpack_base64_file( |
| 709 | + KEYSTORE_PATH_OPT, |
| 710 | + (CassandraSinkConfig config) -> { |
| 711 | + return config.getSslConfig().getKeystorePath().toString(); |
| 712 | + }); |
| 713 | + } |
| 714 | + |
| 715 | + @Test |
| 716 | + void should_unpack_base64_ssl_trustore() throws Exception { |
| 717 | + should_unpack_base64_file( |
| 718 | + TRUSTSTORE_PATH_OPT, |
| 719 | + (CassandraSinkConfig config) -> { |
| 720 | + return config.getSslConfig().getTruststorePath().toString(); |
| 721 | + }); |
| 722 | + } |
| 723 | + |
| 724 | + @Test |
| 725 | + void should_unpack_base64_ssl_openssl_private_key() throws Exception { |
| 726 | + should_unpack_base64_file( |
| 727 | + OPENSSL_PRIVATE_KEY_OPT, |
| 728 | + (CassandraSinkConfig config) -> { |
| 729 | + return config.getSslConfig().getOpenSslPrivateKey().toString(); |
| 730 | + }); |
| 731 | + } |
| 732 | + |
| 733 | + @Test |
| 734 | + void should_unpack_base64_ssl_openssl_cert_chain() throws Exception { |
| 735 | + should_unpack_base64_file( |
| 736 | + OPENSSL_KEY_CERT_CHAIN_OPT, |
| 737 | + (CassandraSinkConfig config) -> { |
| 738 | + return config.getSslConfig().getOpenSslKeyCertChain().toString(); |
| 739 | + }); |
| 740 | + } |
| 741 | + |
| 742 | + @Test |
| 743 | + void should_unpack_base64_auth_keytab() throws Exception { |
| 744 | + should_unpack_base64_file( |
| 745 | + KEYTAB_OPT, |
| 746 | + (CassandraSinkConfig config) -> { |
| 747 | + return config.getAuthenticatorConfig().getKeyTabPath().toString(); |
| 748 | + }); |
| 749 | + } |
| 750 | + |
| 751 | + void should_unpack_base64_file( |
| 752 | + String entryName, Function<CassandraSinkConfig, String> parameterAccessor) throws Exception { |
| 753 | + |
| 754 | + byte[] zipFileContents = "foo".getBytes(UTF_8); |
703 | 755 | String encoded = "base64:" + Base64.getEncoder().encodeToString(zipFileContents);
|
704 | 756 | Map<String, String> inputSettings = new HashMap<>();
|
705 | 757 | inputSettings.put(entryName, encoded);
|
706 | 758 | CassandraSinkConfig cassandraSinkConfig = new CassandraSinkConfig(inputSettings);
|
707 |
| - assertThat(cassandraSinkConfig.isCloud()).isEqualTo(true); |
708 |
| - Map<String, String> javaDriverSettings = cassandraSinkConfig.getJavaDriverSettings(); |
709 |
| - String path = javaDriverSettings.get(SECURE_CONNECT_BUNDLE_DRIVER_SETTING); |
| 759 | + |
| 760 | + String path = parameterAccessor.apply(cassandraSinkConfig); |
710 | 761 | File file = new File(path);
|
711 | 762 | assertThat(file.isFile()).isEqualTo(true);
|
712 | 763 | Set<PosixFilePermission> posixFilePermissions = Files.getPosixFilePermissions(file.toPath());
|
|
0 commit comments