Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 15 additions & 2 deletions driver-core/src/main/com/mongodb/ConnectionString.java
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ public ConnectionString(final String connectionString, @Nullable final DnsClient
throw new IllegalArgumentException("srvMaxHosts can not be specified with replica set name");
}

validateProxyParameters();
validateProxyParameters(combinedOptionsMaps);

credential = createCredentials(combinedOptionsMaps, userName, password);
warnOnUnsupportedOptions(combinedOptionsMaps);
Expand Down Expand Up @@ -1226,7 +1226,7 @@ private void validatePort(final String port) {
}
}

private void validateProxyParameters() {
private void validateProxyParameters(final Map<String, List<String>> optionsMap) {
if (proxyHost == null) {
if (proxyPort != null) {
throw new IllegalArgumentException("proxyPort can only be specified with proxyHost");
Expand Down Expand Up @@ -1259,6 +1259,19 @@ private void validateProxyParameters() {
throw new IllegalArgumentException(
"Both proxyUsername and proxyPassword must be set together. They cannot be set individually");
}

if (proxyHost != null && optionsMap.get("proxyhost").size() > 1) {
throw new IllegalArgumentException("Duplicated values for proxyHost: " + optionsMap.get("proxyhost"));
}
if (proxyPort != null && optionsMap.get("proxyport").size() > 1) {
throw new IllegalArgumentException("Duplicated values for proxyPort: " + optionsMap.get("proxyport"));
}
if (proxyPassword != null && optionsMap.get("proxypassword").size() > 1) {
throw new IllegalArgumentException("Duplicated values for proxyPassword: " + optionsMap.get("proxypassword"));
}
if (proxyUsername != null && optionsMap.get("proxyusername").size() > 1) {
throw new IllegalArgumentException("Duplicated values for proxyUsername: " + optionsMap.get("proxyusername"));
}
}

private int countOccurrences(final String haystack, final String needle) {
Expand Down
3 changes: 0 additions & 3 deletions driver-core/src/test/unit/com/mongodb/UriOptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ public void shouldPassAllOutcomes() {
// No CANONICALIZE_HOST_NAME support https://jira.mongodb.org/browse/JAVA-4278
assumeFalse(getDescription().equals("Valid auth options are parsed correctly (GSSAPI)"));

// https://jira.mongodb.org/browse/JAVA-5834
assumeFalse(getFilename().equals("proxy-options.json"));

if (getDefinition().getBoolean("valid", BsonBoolean.TRUE).getValue()) {
testValidOptions();
} else {
Expand Down