|
46 | 46 | import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.METRICS_SESSION_CQL_REQUESTS_INTERVAL;
|
47 | 47 | import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.METRICS_SESSION_ENABLED;
|
48 | 48 | import static com.datastax.oss.dsbulk.tests.assertions.TestAssertions.assertThat;
|
| 49 | +import static org.assertj.core.api.Assertions.assertThat; |
49 | 50 | import static org.assertj.core.api.Assertions.assertThatCode;
|
50 | 51 | import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
51 | 52 |
|
|
58 | 59 | import com.datastax.oss.driver.shaded.guava.common.collect.Maps;
|
59 | 60 | import com.datastax.oss.dsbulk.tests.logging.LogInterceptingExtension;
|
60 | 61 | import com.datastax.oss.dsbulk.tests.logging.LogInterceptor;
|
| 62 | +import java.io.ByteArrayOutputStream; |
| 63 | +import java.io.File; |
| 64 | +import java.nio.file.Files; |
| 65 | +import java.nio.file.attribute.PosixFilePermission; |
| 66 | +import java.util.Base64; |
61 | 67 | import java.util.Collections;
|
62 | 68 | import java.util.HashMap;
|
63 | 69 | import java.util.List;
|
64 | 70 | import java.util.Map;
|
| 71 | +import java.util.Set; |
65 | 72 | import java.util.stream.Stream;
|
| 73 | +import java.util.zip.ZipEntry; |
| 74 | +import java.util.zip.ZipOutputStream; |
66 | 75 | import org.junit.jupiter.api.Test;
|
67 | 76 | import org.junit.jupiter.api.extension.ExtendWith;
|
68 | 77 | import org.junit.jupiter.params.ParameterizedTest;
|
@@ -670,6 +679,46 @@ void should_set_default_driver_setting(String driverSettingName, String expected
|
670 | 679 | .isEqualTo(expectedDefault);
|
671 | 680 | }
|
672 | 681 |
|
| 682 | + @Test |
| 683 | + void should_unpack_base64_zip_file_legacy_name() throws Exception { |
| 684 | + should_unpack_base64_zip_file(SECURE_CONNECT_BUNDLE_OPT); |
| 685 | + } |
| 686 | + |
| 687 | + @Test |
| 688 | + void should_unpack_base64_zip_file() throws Exception { |
| 689 | + should_unpack_base64_zip_file(SECURE_CONNECT_BUNDLE_DRIVER_SETTING); |
| 690 | + } |
| 691 | + |
| 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(); |
| 703 | + String encoded = "base64:" + Base64.getEncoder().encodeToString(zipFileContents); |
| 704 | + Map<String, String> inputSettings = new HashMap<>(); |
| 705 | + inputSettings.put(entryName, encoded); |
| 706 | + 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); |
| 710 | + File file = new File(path); |
| 711 | + assertThat(file.isFile()).isEqualTo(true); |
| 712 | + Set<PosixFilePermission> posixFilePermissions = Files.getPosixFilePermissions(file.toPath()); |
| 713 | + assertThat(posixFilePermissions) |
| 714 | + .contains(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE); |
| 715 | + assertThat(posixFilePermissions.size()) |
| 716 | + .as("bad permissions " + posixFilePermissions) |
| 717 | + .isEqualTo(2); |
| 718 | + byte[] content = Files.readAllBytes(file.toPath()); |
| 719 | + assertThat(content).isEqualTo(zipFileContents); |
| 720 | + } |
| 721 | + |
673 | 722 | @Test
|
674 | 723 | void should_transform_list_setting_to_indexed_typesafe_setting() {
|
675 | 724 | // given
|
|
0 commit comments