Skip to content

Commit 595b11f

Browse files
committed
JAVA-2090: Support non-ASCII passwords
1 parent 5f0e3ad commit 595b11f

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

driver-core/src/main/com/mongodb/internal/authentication/NativeAuthenticationHelper.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,7 @@ public static String createAuthenticationHash(final String userName, final char[
5050
try {
5151
bout.write(userName.getBytes(UTF_8_CHARSET));
5252
bout.write(":mongo:".getBytes(UTF_8_CHARSET));
53-
for (final char ch : password) {
54-
if (ch >= 128) {
55-
throw new IllegalArgumentException("can't handle non-ascii passwords yet");
56-
}
57-
bout.write((byte) ch);
58-
}
53+
bout.write(new String(password).getBytes(UTF_8_CHARSET));
5954
} catch (IOException ioe) {
6055
throw new RuntimeException("impossible", ioe);
6156
}

driver-core/src/test/functional/com/mongodb/operation/UserOperationsSpecification.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ import static com.mongodb.WriteConcern.ACKNOWLEDGED
6565
import static java.util.Arrays.asList
6666

6767
class UserOperationsSpecification extends OperationFunctionalSpecification {
68-
def credential = createCredential('newUser', databaseName, '123'.toCharArray())
68+
def credential = createCredential('\u53f0\u5317', databaseName, 'Ta\u0301ibe\u030Ci'.toCharArray())
6969

7070
def 'an added user should be found'() {
7171
given:

driver-core/src/test/unit/com/mongodb/connection/NativeAuthenticatorUnitTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class NativeAuthenticatorUnitTest {
4141
public void before() {
4242
connection = new TestInternalConnection(new ServerId(new ClusterId(), new ServerAddress("localhost", 27017)));
4343
connectionDescription = new ConnectionDescription(new ServerId(new ClusterId(), new ServerAddress()));
44-
credential = MongoCredential.createMongoCRCredential("user", "database", "pencil".toCharArray());
44+
credential = MongoCredential.createMongoCRCredential("\u53f0\u5317", "database", "Ta\u0301ibe\u030Ci".toCharArray());
4545
subject = new NativeAuthenticator(this.credential);
4646
}
4747

@@ -114,8 +114,8 @@ private void validateMessages() {
114114
String secondCommand = MessageHelper.decodeCommandAsJson(sent.get(1));
115115

116116
assertEquals("{ \"getnonce\" : 1 }", firstCommand);
117-
assertEquals("{ \"authenticate\" : 1, \"user\" : \"user\", "
117+
assertEquals("{ \"authenticate\" : 1, \"user\" : \"\u53f0\u5317\", "
118118
+ "\"nonce\" : \"2375531c32080ae8\", "
119-
+ "\"key\" : \"21742f26431831d5cfca035a08c5bdf6\" }", secondCommand);
119+
+ "\"key\" : \"4fb55df196e38eea50d2b8b200acfa8b\" }", secondCommand);
120120
}
121121
}

0 commit comments

Comments
 (0)