Skip to content

OIDC admin credentials #1389

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 3 commits into from
May 29, 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 @@ -234,6 +234,8 @@ public void test2p4InvalidClientConfigurationWithCallback() {

@Test
public void test2p5InvalidAllowedHosts() {
assumeTestEnvironment();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no requirement to run this test in a non-"test" environment; disabled to prevent running on GCP. Tests passing here.


String uri = "mongodb://localhost/?authMechanism=MONGODB-OIDC&&authMechanismProperties=ENVIRONMENT:azure,TOKEN_RESOURCE:123";
ConnectionString cs = new ConnectionString(uri);
MongoCredential credential = assertNotNull(cs.getCredential())
Expand All @@ -245,7 +247,7 @@ public void test2p5InvalidAllowedHosts() {
.credential(credential)
.build();
assertCause(IllegalArgumentException.class,
"ALLOWED_HOSTS must not be specified only when OIDC_HUMAN_CALLBACK is specified",
"ALLOWED_HOSTS must be specified only when OIDC_HUMAN_CALLBACK is specified",
() -> {
try (MongoClient mongoClient = createMongoClient(settings)) {
performFind(mongoClient);
Expand Down