Skip to content

Allow tls=false override with mongodb+srv protocol #1165

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

Merged
merged 1 commit into from
Aug 2, 2023
Merged
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
4 changes: 2 additions & 2 deletions driver-core/src/main/com/mongodb/ConnectionString.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, List<String>> 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"));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to the non-deprecated parameter name

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

}
translateOptions(combinedOptionsMaps);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only one that failed. The others are just to increase test coverage.

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
Expand Down