Skip to content

Commit b212fb8

Browse files
authored
Allow tls=false override with mongodb+srv protocol (#1165)
JAVA-4915
1 parent 46903fb commit b212fb8

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

driver-core/src/main/com/mongodb/ConnectionString.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,8 @@ public ConnectionString(final String connectionString, @Nullable final DnsClient
421421
+ "'%s' contains the keys %s", ALLOWED_OPTIONS_IN_TXT_RECORD, unresolvedHosts.get(0), txtRecordsOptionsMap.keySet()));
422422
}
423423
Map<String, List<String>> combinedOptionsMaps = combineOptionsMaps(txtRecordsOptionsMap, connectionStringOptionsMap);
424-
if (isSrvProtocol && !combinedOptionsMaps.containsKey("ssl")) {
425-
combinedOptionsMaps.put("ssl", singletonList("true"));
424+
if (isSrvProtocol && !(combinedOptionsMaps.containsKey("tls") || combinedOptionsMaps.containsKey("ssl"))) {
425+
combinedOptionsMaps.put("tls", singletonList("true"));
426426
}
427427
translateOptions(combinedOptionsMaps);
428428

driver-core/src/test/unit/com/mongodb/ConnectionStringSpecification.groovy

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,20 @@ class ConnectionStringSpecification extends Specification {
683683
connectionString.hosts == ['test5.test.build.10gen.cc']
684684
}
685685

686+
// sslEnabled defaults to true with mongodb+srv but can be overridden via query parameter
687+
def 'should set sslEnabled property with SRV protocol'() {
688+
expect:
689+
connectionString.getSslEnabled() == sslEnabled
690+
691+
where:
692+
connectionString | sslEnabled
693+
new ConnectionString('mongodb+srv://test5.test.build.10gen.cc') | true
694+
new ConnectionString('mongodb+srv://test5.test.build.10gen.cc/?tls=true') | true
695+
new ConnectionString('mongodb+srv://test5.test.build.10gen.cc/?ssl=true') | true
696+
new ConnectionString('mongodb+srv://test5.test.build.10gen.cc/?tls=false') | false
697+
new ConnectionString('mongodb+srv://test5.test.build.10gen.cc/?ssl=false') | false
698+
}
699+
686700

687701
// these next two tests are functionally part of the initial-dns-seedlist-discovery specification tests, but since those
688702
// tests require that the driver connects to an actual replica set, it isn't possible to create specification tests

0 commit comments

Comments
 (0)