diff --git a/driver-core/src/main/com/mongodb/ConnectionString.java b/driver-core/src/main/com/mongodb/ConnectionString.java index 34378d4069f..c4e50d88020 100644 --- a/driver-core/src/main/com/mongodb/ConnectionString.java +++ b/driver-core/src/main/com/mongodb/ConnectionString.java @@ -38,7 +38,6 @@ import java.net.URLDecoder; import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -240,9 +239,7 @@ * mechanism (the default). * *
A TOKEN_RESOURCE with a comma character must be given as a `MongoClient` configuration and not as + * part of the connection string. The TOKEN_RESOURCE value can contain a colon character. + * * @see MongoCredential#ENVIRONMENT_KEY * @see #createOidcCredential(String) * @since 5.1 diff --git a/driver-core/src/test/resources/auth/legacy/connection-string.json b/driver-core/src/test/resources/auth/legacy/connection-string.json index 072dd176dc8..f8b0f9426c1 100644 --- a/driver-core/src/test/resources/auth/legacy/connection-string.json +++ b/driver-core/src/test/resources/auth/legacy/connection-string.json @@ -565,7 +565,7 @@ }, { "description": "should handle a complicated url-encoded TOKEN_RESOURCE (MONGODB-OIDC)", - "uri": "mongodb://user@localhost/?authMechanism=MONGODB-OIDC&authMechanismProperties=ENVIRONMENT:azure,TOKEN_RESOURCE:abc%2Cd%25ef%3Ag%26hi", + "uri": "mongodb://user@localhost/?authMechanism=MONGODB-OIDC&authMechanismProperties=ENVIRONMENT:azure,TOKEN_RESOURCE:abcd%25ef%3Ag%26hi", "valid": true, "credential": { "username": "user", @@ -574,7 +574,7 @@ "mechanism": "MONGODB-OIDC", "mechanism_properties": { "ENVIRONMENT": "azure", - "TOKEN_RESOURCE": "abc,d%ef:g&hi" + "TOKEN_RESOURCE": "abcd%ef:g&hi" } } }, diff --git a/driver-core/src/test/resources/connection-string/valid-options.json b/driver-core/src/test/resources/connection-string/valid-options.json index 4c2bded9e72..cb2027f86ff 100644 --- a/driver-core/src/test/resources/connection-string/valid-options.json +++ b/driver-core/src/test/resources/connection-string/valid-options.json @@ -20,6 +20,25 @@ "options": { "authmechanism": "MONGODB-CR" } + }, + { + "description": "Colon in a key value pair", + "uri": "mongodb://example.com/?authMechanism=MONGODB-OIDC&authMechanismProperties=TOKEN_RESOURCE:mongodb://test-cluster", + "valid": true, + "warning": false, + "hosts": [ + { + "type": "hostname", + "host": "example.com", + "port": null + } + ], + "auth": null, + "options": { + "authmechanismProperties": { + "TOKEN_RESOURCE": "mongodb://test-cluster" + } + } } ] } diff --git a/driver-core/src/test/unit/com/mongodb/ConnectionStringUnitTest.java b/driver-core/src/test/unit/com/mongodb/ConnectionStringUnitTest.java index 6a8d9ff4fc3..bc905c9c6d8 100644 --- a/driver-core/src/test/unit/com/mongodb/ConnectionStringUnitTest.java +++ b/driver-core/src/test/unit/com/mongodb/ConnectionStringUnitTest.java @@ -39,20 +39,6 @@ void defaults() { assertAll(() -> assertNull(connectionStringDefault.getServerMonitoringMode())); } - @Test - public void mustDecodeOidcIndividually() { - String string = "abc,d!@#$%^&*;ef:ghi"; - // encoded tags will fail parsing with an "invalid read preference tag" - // error if decoding is skipped. - String encodedTags = encode("dc:ny,rack:1"); - ConnectionString cs = new ConnectionString( - "mongodb://localhost/?readPreference=primaryPreferred&readPreferenceTags=" + encodedTags - + "&authMechanism=MONGODB-OIDC&authMechanismProperties=" - + "ENVIRONMENT:azure,TOKEN_RESOURCE:" + encode(string)); - MongoCredential credential = Assertions.assertNotNull(cs.getCredential()); - assertEquals(string, credential.getMechanismProperty("TOKEN_RESOURCE", null)); - } - @Test public void mustDecodeNonOidcAsWhole() { // this string allows us to check if there is no double decoding diff --git a/driver-sync/src/test/functional/com/mongodb/internal/connection/OidcAuthenticationProseTests.java b/driver-sync/src/test/functional/com/mongodb/internal/connection/OidcAuthenticationProseTests.java index 70ab06a08b1..2d82ecf3d92 100644 --- a/driver-sync/src/test/functional/com/mongodb/internal/connection/OidcAuthenticationProseTests.java +++ b/driver-sync/src/test/functional/com/mongodb/internal/connection/OidcAuthenticationProseTests.java @@ -236,7 +236,7 @@ public void test2p4InvalidClientConfigurationWithCallback() { public void test2p5InvalidAllowedHosts() { assumeTestEnvironment(); - String uri = "mongodb://localhost/?authMechanism=MONGODB-OIDC&&authMechanismProperties=ENVIRONMENT:azure,TOKEN_RESOURCE:123"; + String uri = "mongodb://localhost/?authMechanism=MONGODB-OIDC&authMechanismProperties=ENVIRONMENT:azure,TOKEN_RESOURCE:123"; ConnectionString cs = new ConnectionString(uri); MongoCredential credential = assertNotNull(cs.getCredential()) .withMechanismProperty("ALLOWED_HOSTS", Collections.emptyList());