Skip to content

Commit

Permalink
don't use MsSQLConfigBuilder.withSsl with strings, but instead proper…
Browse files Browse the repository at this point in the history
…ly named and typed methods
  • Loading branch information
stephane-airbyte committed Dec 14, 2023
1 parent e9d0acb commit 3d31fe6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected FeatureFlags featureFlags() {
@Override
protected JsonNode getConfig() {
return testdb.integrationTestConfigBuilder()
.withSsl(Map.of("ssl_method", "encrypted_trust_server_certificate"))
.withEncrytedTrustServerCertificate()
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class SslEnabledMssqlSourceAcceptanceTest extends MssqlSourceAcceptanceTe
@Override
protected JsonNode getConfig() {
return testdb.integrationTestConfigBuilder()
.withSsl(Map.of("ssl_method", "encrypted_trust_server_certificate"))
.withEncrytedTrustServerCertificate()
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,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);
Expand All @@ -77,7 +77,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);
Expand All @@ -94,7 +94,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public class MssqlSslSourceTest {

@BeforeEach
void setup() {
testDb = MsSQLTestDatabase.in(BaseImage.MSSQL_2022, ContainerModifier.WITH_SSL_CERTIFICATES
);
testDb = MsSQLTestDatabase.in(BaseImage.MSSQL_2022, ContainerModifier.WITH_SSL_CERTIFICATES);
}

@AfterEach
Expand All @@ -43,8 +42,7 @@ public void tearDown() {
public void testDiscoverWithCertificateTrustHostname(CertificateKey certificateKey) throws Exception {
String certificate = testDb.getCertificate(certificateKey);
JsonNode config = testDb.testConfigBuilder()
.withSsl(Map.of("ssl_method", "encrypted_verify_certificate",
"certificate", certificate))
.withEncrytedVerifyServerCertificate(certificate, null)
.build();
try {
AirbyteCatalog catalog = new MssqlSource().discover(config);
Expand All @@ -63,8 +61,7 @@ public void testDiscoverWithCertificateNoTrustHostnameWrongHostname(CertificateK
String containerIp = InetAddress.getByName(testDb.getContainer().getHost()).getHostAddress();
String certificate = testDb.getCertificate(certificateKey);
JsonNode config = testDb.configBuilder()
.withSsl(Map.of("ssl_method", "encrypted_verify_certificate",
"certificate", certificate))
.withEncrytedVerifyServerCertificate(certificate, null)
.with(JdbcUtils.HOST_KEY, containerIp)
.with(JdbcUtils.PORT_KEY, testDb.getContainer().getFirstMappedPort())
.withCredentials()
Expand All @@ -89,9 +86,7 @@ public void testDiscoverWithCertificateNoTrustHostnameAlternateHostname(Certific
if (certificateKey.isValid) {
String certificate = testDb.getCertificate(certificateKey);
JsonNode config = testDb.configBuilder()
.withSsl(Map.of("ssl_method", "encrypted_verify_certificate",
"certificate", certificate,
"hostNameInCertificate", testDb.getContainer().getHost()))
.withEncrytedVerifyServerCertificate(certificate, testDb.getContainer().getHost())
.with(JdbcUtils.HOST_KEY, containerIp)
.with(JdbcUtils.PORT_KEY, testDb.getContainer().getFirstMappedPort())
.withCredentials()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ private BaseImage(String reference) {
public static enum ContainerModifier {

NETWORK("withNetwork"),
AGENT("withAgent");
AGENT("withAgent"),
WITH_SSL_CERTIFICATES("withSslCertificates");

private final String methodName;

Expand Down Expand Up @@ -268,9 +269,25 @@ public MsSQLConfigBuilder withoutSsl() {
return withSsl(Map.of("ssl_method", "unencrypted"));
}

@Override
@Deprecated
public MsSQLConfigBuilder withSsl(Map<Object, Object> 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));
}
}
}
}

0 comments on commit 3d31fe6

Please sign in to comment.