use of com.mongodb.AuthenticationMechanism in project mongo-java-driver by mongodb.
the class ConnectionStringTest method testValidAuth.
private void testValidAuth() {
ConnectionString connectionString = null;
try {
connectionString = new ConnectionString(input);
} catch (Throwable t) {
if (description.contains("without password")) {
// We don't allow null passwords without setting the authentication mechanism.
return;
} else {
assertTrue(String.format("Connection string '%s' should not have throw an exception: %s", input, t.toString()), false);
}
}
assertString("auth.db", getAuthDB(connectionString));
assertString("auth.username", connectionString.getUsername());
// Passwords for certain auth mechanisms are ignored.
String password = null;
if (connectionString.getPassword() != null) {
password = new String(connectionString.getPassword());
}
List<MongoCredential> credentials = connectionString.getCredentialList();
if (credentials.size() > 0) {
AuthenticationMechanism mechanism = credentials.get(0).getAuthenticationMechanism();
if (mechanism == null) {
assertString("auth.password", password);
} else {
switch(mechanism) {
case PLAIN:
case MONGODB_CR:
case SCRAM_SHA_1:
assertString("auth.password", password);
break;
default:
}
}
} else {
assertString("auth.password", password);
}
}
Aggregations