-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Postgres/MySQL Source Strict Encrypt: stop enforce SSL if ssl mode di…
…sabled (#19025) * Postgres/MySQL Source Strict Encrypt: stop enforce SSL if ssl mode disabled * fixed checkstyle * updated changelog * add tests * replaced MySQL test to mysql-strict-encrypt module * fixed Connection Refused for mysql test * replaced Postgres Source strict-encrypt tests into new class * bump version * auto-bump connector version * auto-bump connector version Co-authored-by: Octavia Squidington III <octavia-squidington-iii@users.noreply.github.com>
- Loading branch information
1 parent
f54f4af
commit c72b75e
Showing
12 changed files
with
168 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...rc/test/java/io/airbyte/integrations/source/postgres/PostgresSourceStrictEncryptTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package io.airbyte.integrations.source.postgres; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.google.common.collect.ImmutableMap; | ||
import io.airbyte.db.jdbc.JdbcUtils; | ||
import io.airbyte.integrations.base.ssh.SshBastionContainer; | ||
import io.airbyte.integrations.base.ssh.SshTunnel; | ||
import io.airbyte.protocol.models.AirbyteConnectionStatus; | ||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.containers.Network; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class PostgresSourceStrictEncryptTest { | ||
private static final SshBastionContainer bastion = new SshBastionContainer(); | ||
private static final Network network = Network.newNetwork(); | ||
|
||
@Test | ||
void testCheckWithSSlModeDisable() throws Exception { | ||
|
||
try (PostgreSQLContainer<?> db = new PostgreSQLContainer<>("postgres:13-alpine").withNetwork(network)) { | ||
bastion.initAndStartBastion(network); | ||
db.start(); | ||
|
||
// stop to enforce ssl for ssl_mode disable | ||
final ImmutableMap.Builder<Object, Object> builderWithSSLModeDisable = getDatabaseConfigBuilderWithSSLMode(db, "disable"); | ||
final JsonNode configWithSSLModeDisable = bastion.getTunnelConfig(SshTunnel.TunnelMethod.SSH_PASSWORD_AUTH, builderWithSSLModeDisable); | ||
final AirbyteConnectionStatus connectionStatusForDisabledMode = new PostgresSourceStrictEncrypt().check(configWithSSLModeDisable); | ||
assertEquals(AirbyteConnectionStatus.Status.SUCCEEDED, connectionStatusForDisabledMode.getStatus()); | ||
|
||
} finally { | ||
bastion.stopAndClose(); | ||
} | ||
} | ||
|
||
@Test | ||
void testCheckWithSSlModePrefer() throws Exception { | ||
|
||
try (PostgreSQLContainer<?> db = new PostgreSQLContainer<>("postgres:13-alpine").withNetwork(network)) { | ||
bastion.initAndStartBastion(network); | ||
db.start(); | ||
//continue to enforce ssl because ssl mode is prefer | ||
final ImmutableMap.Builder<Object, Object> builderWithSSLModePrefer = getDatabaseConfigBuilderWithSSLMode(db, "prefer"); | ||
final JsonNode configWithSSLModePrefer = bastion.getTunnelConfig(SshTunnel.TunnelMethod.SSH_PASSWORD_AUTH, builderWithSSLModePrefer); | ||
final AirbyteConnectionStatus connectionStatusForPreferredMode = new PostgresSourceStrictEncrypt().check(configWithSSLModePrefer); | ||
assertEquals(AirbyteConnectionStatus.Status.FAILED, connectionStatusForPreferredMode.getStatus()); | ||
assertEquals("State code: 08004; Message: The server does not support SSL.", connectionStatusForPreferredMode.getMessage()); | ||
|
||
} finally { | ||
bastion.stopAndClose(); | ||
} | ||
} | ||
|
||
private ImmutableMap.Builder<Object, Object> getDatabaseConfigBuilderWithSSLMode(PostgreSQLContainer<?> db, String sslMode) { | ||
return ImmutableMap.builder() | ||
.put(JdbcUtils.HOST_KEY, Objects.requireNonNull(db.getContainerInfo() | ||
.getNetworkSettings() | ||
.getNetworks() | ||
.entrySet().stream() | ||
.findFirst() | ||
.get().getValue().getIpAddress())) | ||
.put(JdbcUtils.PORT_KEY, db.getExposedPorts().get(0)) | ||
.put(JdbcUtils.DATABASE_KEY, db.getDatabaseName()) | ||
.put(JdbcUtils.SCHEMAS_KEY, List.of("public")) | ||
.put(JdbcUtils.USERNAME_KEY, db.getUsername()) | ||
.put(JdbcUtils.PASSWORD_KEY, db.getPassword()) | ||
.put(JdbcUtils.SSL_MODE_KEY, Map.of(JdbcUtils.MODE_KEY, sslMode)); | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters