Skip to content

OIDC admin credentials #1413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 6 additions & 1 deletion .evergreen/run-mongodb-oidc-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ fi
which java
export OIDC_TESTS_ENABLED=true

./gradlew -Dorg.mongodb.test.uri="$MONGODB_URI" \
# use admin credentials for tests
TO_REPLACE="mongodb://"
REPLACEMENT="mongodb://$OIDC_ADMIN_USER:$OIDC_ADMIN_PWD@"
ADMIN_URI=${MONGODB_URI/$TO_REPLACE/$REPLACEMENT}

./gradlew -Dorg.mongodb.test.uri="$ADMIN_URI" \
--stacktrace --debug --info --no-build-cache driver-core:cleanTest \
driver-sync:test --tests OidcAuthenticationProseTests --tests UnifiedAuthTest \
driver-reactive-streams:test --tests OidcAuthenticationAsyncProseTests \
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.mongodb.ClientEncryptionSettings;
import com.mongodb.ClientSessionOptions;
import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.MongoCredential;
import com.mongodb.ReadConcern;
Expand Down Expand Up @@ -535,6 +536,11 @@ private void initClient(final BsonDocument entity, final String id,
"Unsupported authMechanismProperties for authMechanism: " + value);
}

// override the org.mongodb.test.uri connection string
String uri = getenv("MONGODB_URI");
ConnectionString cs = new ConnectionString(uri);
clientSettingsBuilder.applyConnectionString(cs);

String env = assertNotNull(getenv("OIDC_ENV"));
MongoCredential oidcCredential = MongoCredential
.createOidcCredential(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,29 @@ public void test2p4InvalidClientConfigurationWithCallback() {
() -> performFind(settings));
}

@Test
public void test2p5InvalidAllowedHosts() {
assumeTestEnvironment();

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());
MongoClientSettings settings = MongoClientSettings.builder()
.applicationName(appName)
.applyConnectionString(cs)
.retryReads(false)
.credential(credential)
.build();
assertCause(IllegalArgumentException.class,
"ALLOWED_HOSTS must be specified only when OIDC_HUMAN_CALLBACK is specified",
() -> {
try (MongoClient mongoClient = createMongoClient(settings)) {
performFind(mongoClient);
}
});
}

@Test
public void test3p1AuthFailsWithCachedToken() throws ExecutionException, InterruptedException, NoSuchFieldException, IllegalAccessException {
TestCallback callbackWrapped = createCallback();
Expand Down