-
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.
- Loading branch information
1 parent
26d3746
commit bb32bf5
Showing
6 changed files
with
232 additions
and
18 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
105 changes: 105 additions & 0 deletions
105
...s/source-mssql/src/test/java/io/airbyte/integrations/source/mssql/MssqlSslSourceTest.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,105 @@ | ||
/* | ||
* Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.integrations.source.mssql; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import io.airbyte.cdk.db.jdbc.JdbcUtils; | ||
import io.airbyte.commons.exceptions.ConnectionErrorException; | ||
import io.airbyte.integrations.source.mssql.MsSQLTestDatabase.BaseImage; | ||
import io.airbyte.integrations.source.mssql.MsSQLTestDatabase.CertificateKey; | ||
import io.airbyte.integrations.source.mssql.MsSQLTestDatabase.ContainerModifier; | ||
import io.airbyte.protocol.models.v0.AirbyteCatalog; | ||
import java.net.InetAddress; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.EnumSource; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class MssqlSslSourceTest { | ||
|
||
private MsSQLTestDatabase testDb; | ||
private static final Logger LOGGER = LoggerFactory.getLogger(MssqlSslSourceTest.class); | ||
|
||
@BeforeEach | ||
void setup() { | ||
testDb = MsSQLTestDatabase.in(BaseImage.MSSQL_2022, ContainerModifier.WITH_SSL_CERTIFICATES); | ||
Check failure on line 33 in airbyte-integrations/connectors/source-mssql/src/test/java/io/airbyte/integrations/source/mssql/MssqlSslSourceTest.java GitHub Actions / Gradle Check
|
||
} | ||
|
||
@AfterEach | ||
public void tearDown() { | ||
testDb.close(); | ||
} | ||
|
||
@ParameterizedTest | ||
@EnumSource(CertificateKey.class) | ||
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)) | ||
.build(); | ||
try { | ||
AirbyteCatalog catalog = new MssqlSource().discover(config); | ||
assertTrue(certificateKey.isValid); | ||
} catch (Exception e) { | ||
if (certificateKey.isValid) { | ||
throw e; | ||
} | ||
} | ||
} | ||
|
||
@ParameterizedTest | ||
@EnumSource(CertificateKey.class) | ||
public void testDiscoverWithCertificateNoTrustHostnameWrongHostname(CertificateKey certificateKey) throws Throwable { | ||
if (certificateKey.isValid) { | ||
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)) | ||
.with(JdbcUtils.HOST_KEY, containerIp) | ||
.with(JdbcUtils.PORT_KEY, testDb.getContainer().getFirstMappedPort()) | ||
.withCredentials() | ||
.withDatabase() | ||
.build(); | ||
try { | ||
AirbyteCatalog catalog = new MssqlSource().discover(config); | ||
fail("discover should have failed!"); | ||
} catch (ConnectionErrorException e) { | ||
String expectedMessage = | ||
"Failed to validate the server name \"" + containerIp + "\"in a certificate during Secure Sockets Layer (SSL) initialization."; | ||
if (!e.getExceptionMessage().contains(expectedMessage)) { | ||
fail("exception message was " + e.getExceptionMessage() + "\n expected: " + expectedMessage); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@ParameterizedTest | ||
@EnumSource(CertificateKey.class) | ||
public void testDiscoverWithCertificateNoTrustHostnameAlternateHostname(CertificateKey certificateKey) throws Exception { | ||
final String containerIp = InetAddress.getByName(testDb.getContainer().getHost()).getHostAddress(); | ||
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())) | ||
.with(JdbcUtils.HOST_KEY, containerIp) | ||
.with(JdbcUtils.PORT_KEY, testDb.getContainer().getFirstMappedPort()) | ||
.withCredentials() | ||
.withDatabase() | ||
.build(); | ||
AirbyteCatalog catalog = new MssqlSource().discover(config); | ||
} | ||
} | ||
|
||
} |
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