diff --git a/driver-core/src/main/com/mongodb/ConnectionString.java b/driver-core/src/main/com/mongodb/ConnectionString.java index cd8f359f35c..0199534b43d 100644 --- a/driver-core/src/main/com/mongodb/ConnectionString.java +++ b/driver-core/src/main/com/mongodb/ConnectionString.java @@ -420,8 +420,8 @@ public ConnectionString(final String connectionString, @Nullable final DnsClient + "'%s' contains the keys %s", ALLOWED_OPTIONS_IN_TXT_RECORD, unresolvedHosts.get(0), txtRecordsOptionsMap.keySet())); } Map> combinedOptionsMaps = combineOptionsMaps(txtRecordsOptionsMap, connectionStringOptionsMap); - if (isSrvProtocol && !combinedOptionsMaps.containsKey("ssl")) { - combinedOptionsMaps.put("ssl", singletonList("true")); + if (isSrvProtocol && !(combinedOptionsMaps.containsKey("tls") || combinedOptionsMaps.containsKey("ssl"))) { + combinedOptionsMaps.put("tls", singletonList("true")); } translateOptions(combinedOptionsMaps); diff --git a/driver-core/src/test/unit/com/mongodb/ConnectionStringSpecification.groovy b/driver-core/src/test/unit/com/mongodb/ConnectionStringSpecification.groovy index c4057576995..63cd8aeb27a 100644 --- a/driver-core/src/test/unit/com/mongodb/ConnectionStringSpecification.groovy +++ b/driver-core/src/test/unit/com/mongodb/ConnectionStringSpecification.groovy @@ -683,6 +683,20 @@ class ConnectionStringSpecification extends Specification { connectionString.hosts == ['test5.test.build.10gen.cc'] } + // sslEnabled defaults to true with mongodb+srv but can be overridden via query parameter + def 'should set sslEnabled property with SRV protocol'() { + expect: + connectionString.getSslEnabled() == sslEnabled + + where: + connectionString | sslEnabled + new ConnectionString('mongodb+srv://test5.test.build.10gen.cc') | true + new ConnectionString('mongodb+srv://test5.test.build.10gen.cc/?tls=true') | true + new ConnectionString('mongodb+srv://test5.test.build.10gen.cc/?ssl=true') | true + new ConnectionString('mongodb+srv://test5.test.build.10gen.cc/?tls=false') | false + new ConnectionString('mongodb+srv://test5.test.build.10gen.cc/?ssl=false') | false + } + // these next two tests are functionally part of the initial-dns-seedlist-discovery specification tests, but since those // tests require that the driver connects to an actual replica set, it isn't possible to create specification tests