From 8565b88804d06e5a4f6f1b169cbe54fa7e4ab598 Mon Sep 17 00:00:00 2001 From: Stephane Geneix <147216312+stephane-airbyte@users.noreply.github.com> Date: Thu, 4 Jan 2024 09:52:16 -0800 Subject: [PATCH] don't use MsSQLConfigBuilder.withSsl with strings, but instead properly named and typed methods (#33261) --- ...mentSslEnabledMssqlSourceAcceptanceTest.java | 3 +-- .../SslEnabledMssqlSourceAcceptanceTest.java | 3 +-- .../source/mssql/CloudDeploymentMssqlTest.java | 7 +++---- .../source/mssql/MsSQLTestDatabase.java | 17 ++++++++++++++++- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/airbyte-integrations/connectors/source-mssql/src/test-integration/java/io/airbyte/integrations/source/mssql/CloudDeploymentSslEnabledMssqlSourceAcceptanceTest.java b/airbyte-integrations/connectors/source-mssql/src/test-integration/java/io/airbyte/integrations/source/mssql/CloudDeploymentSslEnabledMssqlSourceAcceptanceTest.java index 37767d5f99b2..f2a311d6b455 100644 --- a/airbyte-integrations/connectors/source-mssql/src/test-integration/java/io/airbyte/integrations/source/mssql/CloudDeploymentSslEnabledMssqlSourceAcceptanceTest.java +++ b/airbyte-integrations/connectors/source-mssql/src/test-integration/java/io/airbyte/integrations/source/mssql/CloudDeploymentSslEnabledMssqlSourceAcceptanceTest.java @@ -8,7 +8,6 @@ import io.airbyte.cdk.integrations.standardtest.source.TestDestinationEnv; import io.airbyte.commons.features.FeatureFlags; import io.airbyte.commons.features.FeatureFlagsWrapper; -import java.util.Map; public class CloudDeploymentSslEnabledMssqlSourceAcceptanceTest extends MssqlSourceAcceptanceTest { @@ -38,7 +37,7 @@ protected FeatureFlags featureFlags() { @Override protected JsonNode getConfig() { return testdb.integrationTestConfigBuilder() - .withSsl(Map.of("ssl_method", "encrypted_trust_server_certificate")) + .withEncrytedTrustServerCertificate() .build(); } diff --git a/airbyte-integrations/connectors/source-mssql/src/test-integration/java/io/airbyte/integrations/source/mssql/SslEnabledMssqlSourceAcceptanceTest.java b/airbyte-integrations/connectors/source-mssql/src/test-integration/java/io/airbyte/integrations/source/mssql/SslEnabledMssqlSourceAcceptanceTest.java index cd6a6e209146..ccd887c9a4b9 100644 --- a/airbyte-integrations/connectors/source-mssql/src/test-integration/java/io/airbyte/integrations/source/mssql/SslEnabledMssqlSourceAcceptanceTest.java +++ b/airbyte-integrations/connectors/source-mssql/src/test-integration/java/io/airbyte/integrations/source/mssql/SslEnabledMssqlSourceAcceptanceTest.java @@ -6,14 +6,13 @@ import com.fasterxml.jackson.databind.JsonNode; import io.airbyte.cdk.integrations.standardtest.source.TestDestinationEnv; -import java.util.Map; public class SslEnabledMssqlSourceAcceptanceTest extends MssqlSourceAcceptanceTest { @Override protected JsonNode getConfig() { return testdb.integrationTestConfigBuilder() - .withSsl(Map.of("ssl_method", "encrypted_trust_server_certificate")) + .withEncrytedTrustServerCertificate() .build(); } diff --git a/airbyte-integrations/connectors/source-mssql/src/test/java/io/airbyte/integrations/source/mssql/CloudDeploymentMssqlTest.java b/airbyte-integrations/connectors/source-mssql/src/test/java/io/airbyte/integrations/source/mssql/CloudDeploymentMssqlTest.java index 97508ceae381..1889315bea6f 100644 --- a/airbyte-integrations/connectors/source-mssql/src/test/java/io/airbyte/integrations/source/mssql/CloudDeploymentMssqlTest.java +++ b/airbyte-integrations/connectors/source-mssql/src/test/java/io/airbyte/integrations/source/mssql/CloudDeploymentMssqlTest.java @@ -15,7 +15,6 @@ import io.airbyte.commons.features.EnvVariableFeatureFlags; import io.airbyte.commons.features.FeatureFlagsWrapper; import io.airbyte.protocol.models.v0.AirbyteConnectionStatus; -import java.util.Map; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.parallel.Execution; import org.junit.jupiter.api.parallel.ExecutionMode; @@ -61,7 +60,7 @@ void testStrictSSLUnsecuredNoTunnel() throws Exception { void testStrictSSLSecuredNoTunnel() throws Exception { try (final var testdb = createTestDatabase()) { final var config = testdb.testConfigBuilder() - .withSsl(Map.of("ssl_method", "encrypted_trust_server_certificate")) + .withEncrytedTrustServerCertificate() .with("tunnel_method", ImmutableMap.builder().put("tunnel_method", "NO_TUNNEL").build()) .build(); final AirbyteConnectionStatus actual = source().check(config); @@ -77,7 +76,7 @@ void testStrictSSLSecuredWithTunnel() throws Exception { .withDatabase() .with(JdbcUtils.USERNAME_KEY, testdb.getUserName()) .with(JdbcUtils.PASSWORD_KEY, "fake") - .withSsl(Map.of("ssl_method", "encrypted_trust_server_certificate")) + .withEncrytedTrustServerCertificate() .with("tunnel_method", ImmutableMap.builder().put("tunnel_method", "SSH_KEY_AUTH").build()) .build(); final AirbyteConnectionStatus actual = source().check(config); @@ -94,7 +93,7 @@ void testStrictSSLUnsecuredWithTunnel() throws Exception { .withDatabase() .with(JdbcUtils.USERNAME_KEY, testdb.getUserName()) .with(JdbcUtils.PASSWORD_KEY, "fake") - .withSsl(Map.of("ssl_method", "encrypted_trust_server_certificate")) + .withEncrytedTrustServerCertificate() .with("tunnel_method", ImmutableMap.builder().put("tunnel_method", "SSH_KEY_AUTH").build()) .build(); final AirbyteConnectionStatus actual = source().check(config); diff --git a/airbyte-integrations/connectors/source-mssql/src/testFixtures/java/io/airbyte/integrations/source/mssql/MsSQLTestDatabase.java b/airbyte-integrations/connectors/source-mssql/src/testFixtures/java/io/airbyte/integrations/source/mssql/MsSQLTestDatabase.java index 873f42cd40a8..4ef21f4684f4 100644 --- a/airbyte-integrations/connectors/source-mssql/src/testFixtures/java/io/airbyte/integrations/source/mssql/MsSQLTestDatabase.java +++ b/airbyte-integrations/connectors/source-mssql/src/testFixtures/java/io/airbyte/integrations/source/mssql/MsSQLTestDatabase.java @@ -229,11 +229,26 @@ public MsSQLConfigBuilder withoutSsl() { return withSsl(Map.of("ssl_method", "unencrypted")); } - @Override + @Deprecated public MsSQLConfigBuilder withSsl(Map sslMode) { return with("ssl_method", sslMode); } + public MsSQLConfigBuilder withEncrytedTrustServerCertificate() { + return withSsl(Map.of("ssl_method", "encrypted_trust_server_certificate")); + } + + public MsSQLConfigBuilder withEncrytedVerifyServerCertificate(String certificate, String hostnameInCertificate) { + if (hostnameInCertificate != null) { + return withSsl(Map.of("ssl_method", "encrypted_verify_certificate", + "certificate", certificate, + "hostNameInCertificate", hostnameInCertificate)); + } else { + return withSsl(Map.of("ssl_method", "encrypted_verify_certificate", + "certificate", certificate)); + } + } + } }