Skip to content

Commit 49f1f13

Browse files
committed
Ensure socks5 proxy option parsing is to specification
Duplicates are not permitted, where as elsewhere in the connection string they are. JAVA-5834
1 parent c5290ca commit 49f1f13

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ public ConnectionString(final String connectionString, @Nullable final DnsClient
505505
throw new IllegalArgumentException("srvMaxHosts can not be specified with replica set name");
506506
}
507507

508-
validateProxyParameters();
508+
validateProxyParameters(combinedOptionsMaps);
509509

510510
credential = createCredentials(combinedOptionsMaps, userName, password);
511511
warnOnUnsupportedOptions(combinedOptionsMaps);
@@ -1226,7 +1226,7 @@ private void validatePort(final String port) {
12261226
}
12271227
}
12281228

1229-
private void validateProxyParameters() {
1229+
private void validateProxyParameters(final Map<String, List<String>> optionsMap) {
12301230
if (proxyHost == null) {
12311231
if (proxyPort != null) {
12321232
throw new IllegalArgumentException("proxyPort can only be specified with proxyHost");
@@ -1259,6 +1259,19 @@ private void validateProxyParameters() {
12591259
throw new IllegalArgumentException(
12601260
"Both proxyUsername and proxyPassword must be set together. They cannot be set individually");
12611261
}
1262+
1263+
if (proxyHost != null && optionsMap.get("proxyhost").size() > 1) {
1264+
throw new IllegalArgumentException("Duplicated values for proxyHost: " + optionsMap.get("proxyhost"));
1265+
}
1266+
if (proxyPort != null && optionsMap.get("proxyport").size() > 1) {
1267+
throw new IllegalArgumentException("Duplicated values for proxyPort: " + optionsMap.get("proxyport"));
1268+
}
1269+
if (proxyPassword != null && optionsMap.get("proxypassword").size() > 1) {
1270+
throw new IllegalArgumentException("Duplicated values for proxyPassword: " + optionsMap.get("proxypassword"));
1271+
}
1272+
if (proxyUsername != null && optionsMap.get("proxyusername").size() > 1) {
1273+
throw new IllegalArgumentException("Duplicated values for proxyUsername: " + optionsMap.get("proxyusername"));
1274+
}
12621275
}
12631276

12641277
private int countOccurrences(final String haystack, final String needle) {

driver-core/src/test/unit/com/mongodb/UriOptionsTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ public void shouldPassAllOutcomes() {
4747
// No CANONICALIZE_HOST_NAME support https://jira.mongodb.org/browse/JAVA-4278
4848
assumeFalse(getDescription().equals("Valid auth options are parsed correctly (GSSAPI)"));
4949

50-
// https://jira.mongodb.org/browse/JAVA-5834
51-
assumeFalse(getFilename().equals("proxy-options.json"));
52-
5350
if (getDefinition().getBoolean("valid", BsonBoolean.TRUE).getValue()) {
5451
testValidOptions();
5552
} else {

0 commit comments

Comments
 (0)