Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(destination-mssql-v2): add datasource url tests #50426

Open
wants to merge 3 commits into
base: move/destination-mssql-v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import java.util.UUID
import javax.sql.DataSource

@Singleton
class MSSQLChecker(private val dataSourceFactory: MSSQLDataSourceFactory) : DestinationChecker<MSSQLConfiguration> {
class MSSQLChecker(private val dataSourceFactory: MSSQLDataSourceFactory) :
DestinationChecker<MSSQLConfiguration> {
override fun check(config: MSSQLConfiguration) {
val dataSource: DataSource = dataSourceFactory.getDataSource(config)
val testTableName = "check_test_${UUID.randomUUID()}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,31 @@ class DataSourceFactory {
}

fun MSSQLConfiguration.toSQLServerDataSource(): SQLServerDataSource {
val connectionString = StringBuilder().apply {
append("jdbc:sqlserver://${host}:${port};databaseName=${database}")
val connectionString =
StringBuilder()
.apply {
append("jdbc:sqlserver://${host}:${port};databaseName=${database}")

when (sslMethod) {
is EncryptedVerify -> {
append(";encrypt=true")
sslMethod.trustStoreName?.let { append(";trustStoreName=$it") }
sslMethod.trustStorePassword?.let { append(";trustStorePassword=$it") }
sslMethod.hostNameInCertificate?.let { append(";hostNameInCertificate=$it") }
}
is EncryptedTrust -> {
append(";encrypt=true;trustServerCertificate=true")
}
is Unencrypted -> {
append(";encrypt=false")
}
}
when (sslMethod) {
is EncryptedVerify -> {
append(";encrypt=true")
sslMethod.trustStoreName?.let { append(";trustStoreName=$it") }
sslMethod.trustStorePassword?.let { append(";trustStorePassword=$it") }
sslMethod.hostNameInCertificate?.let {
append(";hostNameInCertificate=$it")
}
}
is EncryptedTrust -> {
append(";encrypt=true;trustServerCertificate=true")
}
is Unencrypted -> {
append(";encrypt=false")
}
}

jdbcUrlParams?.let { append(";$it") }
}.toString()
jdbcUrlParams?.let { append(";$it") }
}
.toString()

return SQLServerDataSource().also {
it.url = connectionString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,31 +112,29 @@ class EncryptedTrust : EncryptionMethod {

@JsonSchemaTitle("Encrypted (verify certificate)")
@JsonSchemaDescription("Verify and use the certificate provided by the server.")
class EncryptedVerify : EncryptionMethod {
companion object {
const val NAME = "encrypted_verify_certificate"
}
override val name: String = NAME

class EncryptedVerify(
@get:JsonSchemaTitle("Trust Store Name")
@get:JsonPropertyDescription("Specifies the name of the trust store.")
@get:JsonProperty("trustStoreName")
@get:JsonSchemaInject(json = """{"order":1}""")
val trustStoreName: String? = null

val trustStoreName: String? = null,
@get:JsonSchemaTitle("Trust Store Password")
@get:JsonPropertyDescription("Specifies the password of the trust store.")
@get:JsonProperty("trustStorePassword")
@get:JsonSchemaInject(json = """{"airbyte_secret":true,"order":2}""")
val trustStorePassword: String? = null

val trustStorePassword: String? = null,
@get:JsonSchemaTitle("Host Name In Certificate")
@get:JsonPropertyDescription(
"Specifies the host name of the server. The value of this property must match the subject property of the certificate."
)
@get:JsonProperty("hostNameInCertificate")
@get:JsonSchemaInject(json = """{"order":3}""")
val hostNameInCertificate: String? = null
val hostNameInCertificate: String? = null,
) : EncryptionMethod {
companion object {
const val NAME = "encrypted_verify_certificate"
}
override val name: String = NAME
}

@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@ package io.airbyte.integrations.destination.mssql.v2
import io.airbyte.cdk.load.check.CheckIntegrationTest
import io.airbyte.cdk.load.check.CheckTestConfig
import io.airbyte.integrations.destination.mssql.v2.config.MSSQLSpecification
import java.util.regex.Pattern

class MSSQLCheckTest : CheckIntegrationTest<MSSQLSpecification>(
successConfigFilenames = listOf(
CheckTestConfig(MSSQLTestConfigUtil.getConfigPath("check/valid.json")),
),
failConfigFilenamesAndFailureReasons = emptyMap()
) {
}
class MSSQLCheckTest :
CheckIntegrationTest<MSSQLSpecification>(
successConfigFilenames =
listOf(
CheckTestConfig(MSSQLTestConfigUtil.getConfigPath("check/valid.json")),
CheckTestConfig(MSSQLTestConfigUtil.getConfigPath("check/valid-ssl-trust.json")),
),
failConfigFilenamesAndFailureReasons =
mapOf(
CheckTestConfig(
MSSQLTestConfigUtil.getConfigPath("check/fail-internal-schema-invalid.json")
) to Pattern.compile("\"iamnotthere\" either does not exist"),
)
) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.airbyte.integrations.destination.mssql.v2

import io.airbyte.cdk.load.spec.SpecTest

class MSSQLSpecTest : SpecTest() {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ import java.nio.file.Path

object MSSQLTestConfigUtil {
fun getConfigPath(relativePath: String): Path =
Path.of(this::class.java.classLoader.getResource(relativePath)?.toURI() ?: throw IllegalArgumentException("Resource $relativePath could not be found"))
Path.of(
this::class.java.classLoader.getResource(relativePath)?.toURI()
?: throw IllegalArgumentException("Resource $relativePath could not be found")
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"host": "localhost",
"port": 1433,
"database": "master",
"schema": "dbo",
"raw_data_schema": "iamnotthere",
"ssl_method": {"name": "unencrypted"},
"user": "sa",
"password": "Averycomplicatedpassword1!"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"host": "localhost",
"port": 1433,
"database": "master",
"schema": "dbo",
"raw_data_schema": "guest",
"ssl_method": {"name": "encrypted_trust_server_certificate"},
"user": "sa",
"password": "Averycomplicatedpassword1!"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
{
"documentationUrl" : "https://docs.airbyte.com/integrations/destinations/mssql-v2",
"connectionSpecification" : {
"$schema" : "http://json-schema.org/draft-07/schema#",
"title" : "MSSQL V2 Destination Specification",
"type" : "object",
"additionalProperties" : true,
"properties" : {
"host" : {
"type" : "string",
"description" : "The host name of the MSSQL database.",
"title" : "Host",
"order" : 0
},
"port" : {
"type" : "integer",
"description" : "The port of the MSSQL database.",
"title" : "Port",
"minimum" : 0,
"maximum" : 65536,
"examples" : [ "1433" ],
"order" : 1
},
"database" : {
"type" : "string",
"description" : "The name of the MSSQL database.",
"title" : "DB Name",
"order" : 2
},
"schema" : {
"type" : "string",
"description" : "The default schema tables are written to if the source does not specify a namespace. The usual value for this field is \"public\".",
"title" : "Default Schema",
"examples" : [ "public" ],
"default" : "public",
"order" : 3
},
"user" : {
"type" : "string",
"description" : "The username which is used to access the database.",
"title" : "User",
"order" : 4
},
"password" : {
"type" : "string",
"description" : "The password associated with this username.",
"title" : "Password",
"airbyte_secret" : true,
"order" : 5
},
"jdbc_url_params" : {
"type" : "string",
"description" : "Additional properties to pass to the JDBC URL string when connecting to the database formatted as 'key=value' pairs separated by the symbol '&'. (example: key1=value1&key2=value2&key3=value3).",
"title" : "JDBC URL Params",
"order" : 6
},
"raw_data_schema" : {
"type" : "string",
"description" : "The schema to write raw tables into (default: airbyte_internal)",
"title" : "Raw Table Schema Name",
"default" : "airbyte_internal",
"order" : 5
},
"ssl_method" : {
"oneOf" : [ {
"title" : "Unencrypted",
"type" : "object",
"additionalProperties" : true,
"description" : "The data transfer will not be encrypted.",
"properties" : {
"name" : {
"type" : "string",
"enum" : [ "unencrypted" ],
"default" : "unencrypted"
}
},
"required" : [ "name" ]
}, {
"title" : "Encrypted (trust server certificate)",
"type" : "object",
"additionalProperties" : true,
"description" : "Use the certificate provided by the server without verification. (For testing purposes only!)",
"properties" : {
"name" : {
"type" : "string",
"enum" : [ "encrypted_trust_server_certificate" ],
"default" : "encrypted_trust_server_certificate"
}
},
"required" : [ "name" ]
}, {
"title" : "Encrypted (verify certificate)",
"type" : "object",
"additionalProperties" : true,
"description" : "Verify and use the certificate provided by the server.",
"properties" : {
"name" : {
"type" : "string",
"enum" : [ "encrypted_verify_certificate" ],
"default" : "encrypted_verify_certificate"
},
"trustStoreName" : {
"type" : "string",
"description" : "Specifies the name of the trust store.",
"title" : "Trust Store Name",
"order" : 1
},
"trustStorePassword" : {
"type" : "string",
"description" : "Specifies the password of the trust store.",
"title" : "Trust Store Password",
"airbyte_secret" : true,
"order" : 2
},
"hostNameInCertificate" : {
"type" : "string",
"description" : "Specifies the host name of the server. The value of this property must match the subject property of the certificate.",
"title" : "Host Name In Certificate",
"order" : 3
}
},
"required" : [ "name" ]
} ],
"description" : "The encryption method which is used to communicate with the database.",
"title" : "SSL Method",
"order" : 8,
"type" : "object"
}
},
"required" : [ "host", "port", "database", "schema", "raw_data_schema", "ssl_method" ]
},
"supportsIncremental" : true,
"supportsNormalization" : false,
"supportsDBT" : false,
"supported_destination_sync_modes" : [ "overwrite", "append", "append_dedup" ]
}
Loading
Loading