Skip to content

Commit 00e4c15

Browse files
committed
PR fixes
1 parent 581ae2e commit 00e4c15

File tree

5 files changed

+39
-46
lines changed

5 files changed

+39
-46
lines changed

.evergreen/.evg.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ stepback: true
1313
command_type: system
1414

1515
# Protect ourselves against rogue test case, or curl gone wild, that runs forever
16-
exec_timeout_secs: 7200
16+
exec_timeout_secs: 3600
1717

1818
# What to do when evergreen hits the timeout (`post:` tasks are run automatically)
1919
timeout:

driver-core/src/main/com/mongodb/MongoCredential.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public final class MongoCredential {
202202
* This callback is invoked when the OIDC-based authenticator requests
203203
* a token. The type of the value must be {@link OidcCallback}.
204204
* {@link IdpInfo} will not be supplied to the callback,
205-
* and a {@linkplain com.mongodb.MongoCredential.OidcTokens#getRefreshToken() refresh token}
205+
* and a {@linkplain com.mongodb.MongoCredential.OidcCallbackResult#getRefreshToken() refresh token}
206206
* must not be returned by the callback.
207207
* <p>
208208
* If this is provided, {@link MongoCredential#ENVIRONMENT_KEY}
@@ -698,7 +698,7 @@ public interface OidcCallback {
698698
* @param context The context.
699699
* @return The response produced by an OIDC Identity Provider
700700
*/
701-
OidcTokens onRequest(OidcCallbackContext context);
701+
OidcCallbackResult onRequest(OidcCallbackContext context);
702702
}
703703

704704
/**
@@ -732,7 +732,7 @@ public interface IdpInfo {
732732
*
733733
* @since 5.1
734734
*/
735-
public static final class OidcTokens {
735+
public static final class OidcCallbackResult {
736736

737737
private final String accessToken;
738738

@@ -746,7 +746,7 @@ public static final class OidcTokens {
746746
* An access token that does not expire.
747747
* @param accessToken The OIDC access token.
748748
*/
749-
public OidcTokens(final String accessToken) {
749+
public OidcCallbackResult(final String accessToken) {
750750
this(accessToken, Duration.ZERO, null);
751751
}
752752

@@ -756,7 +756,7 @@ public OidcTokens(final String accessToken) {
756756
* A {@linkplain Duration#isZero() zero-length} duration
757757
* means that the access token does not expire.
758758
*/
759-
public OidcTokens(final String accessToken, final Duration expiresIn) {
759+
public OidcCallbackResult(final String accessToken, final Duration expiresIn) {
760760
this(accessToken, expiresIn, null);
761761
}
762762

@@ -767,7 +767,7 @@ public OidcTokens(final String accessToken, final Duration expiresIn) {
767767
* means that the access token does not expire.
768768
* @param refreshToken The refresh token. If null, refresh will not be attempted.
769769
*/
770-
public OidcTokens(final String accessToken, final Duration expiresIn,
770+
public OidcCallbackResult(final String accessToken, final Duration expiresIn,
771771
@Nullable final String refreshToken) {
772772
notNull("accessToken", accessToken);
773773
notNull("expiresIn", expiresIn);

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
* <p>This class is not part of the public API and may be removed or changed at any time</p>
3333
*/
3434
public final class GcpCredentialHelper {
35-
3635
public static BsonDocument obtainFromEnvironment() {
3736
String endpoint = "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token";
3837

@@ -43,8 +42,7 @@ public static BsonDocument obtainFromEnvironment() {
4342
if (responseDocument.containsKey("access_token")) {
4443
return new BsonDocument("accessToken", responseDocument.get("access_token"));
4544
} else {
46-
throw new MongoClientException("access_token is missing from GCE metadata response. Full response is ''"
47-
+ response);
45+
throw new MongoClientException("access_token is missing from GCE metadata response. Full response is ''" + response);
4846
}
4947
}
5048

driver-core/src/main/com/mongodb/internal/connection/OidcAuthenticator.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import com.mongodb.MongoCommandException;
2222
import com.mongodb.MongoConfigurationException;
2323
import com.mongodb.MongoCredential;
24-
import com.mongodb.MongoCredential.OidcTokens;
24+
import com.mongodb.MongoCredential.OidcCallbackResult;
2525
import com.mongodb.MongoException;
2626
import com.mongodb.MongoSecurityException;
2727
import com.mongodb.ServerAddress;
@@ -193,8 +193,8 @@ private OidcCallback getRequestCallback() {
193193
@VisibleForTesting(otherwise = VisibleForTesting.AccessModifier.PRIVATE)
194194
public static OidcCallback getTestCallback() {
195195
return (context) -> {
196-
String accessToken = readTestTokenFromFile();
197-
return new OidcTokens(accessToken);
196+
String accessToken = readTokenFromFile();
197+
return new OidcCallbackResult(accessToken);
198198
};
199199
}
200200

@@ -204,7 +204,7 @@ public static OidcCallback getAzureCallback(final MongoCredential credential) {
204204
String resource = assertNotNull(credential.getMechanismProperty(TOKEN_RESOURCE_KEY, null));
205205
String objectId = credential.getUserName();
206206
CredentialInfo response = AzureCredentialHelper.fetchAzureCredentialInfo(resource, objectId);
207-
return new OidcTokens(response.getAccessToken(), response.getExpiresIn());
207+
return new OidcCallbackResult(response.getAccessToken(), response.getExpiresIn());
208208
};
209209
}
210210

@@ -213,7 +213,7 @@ public static OidcCallback getGcpCallback(final MongoCredential credential) {
213213
return (context) -> {
214214
String resource = assertNotNull(credential.getMechanismProperty(TOKEN_RESOURCE_KEY, null));
215215
CredentialInfo response = GcpCredentialHelper.fetchGcpCredentialInfo(resource);
216-
return new OidcTokens(response.getAccessToken(), response.getExpiresIn());
216+
return new OidcCallbackResult(response.getAccessToken(), response.getExpiresIn());
217217
};
218218
}
219219

@@ -302,7 +302,7 @@ private byte[] evaluate(final byte[] challenge) {
302302
assertNotNull(cachedIdpInfo);
303303
// Invoke Callback using cached Refresh Token
304304
fallbackState = FallbackState.PHASE_2_REFRESH_CALLBACK_TOKEN;
305-
OidcTokens result = requestCallback.onRequest(new OidcCallbackContextImpl(
305+
OidcCallbackResult result = requestCallback.onRequest(new OidcCallbackContextImpl(
306306
CALLBACK_TIMEOUT, cachedIdpInfo, cachedRefreshToken, userName));
307307
jwt[0] = populateCacheWithCallbackResultAndPrepareJwt(cachedIdpInfo, result);
308308
} else {
@@ -311,7 +311,7 @@ private byte[] evaluate(final byte[] challenge) {
311311
if (!isHuman) {
312312
// no principal request
313313
fallbackState = FallbackState.PHASE_3B_CALLBACK_TOKEN;
314-
OidcTokens result = requestCallback.onRequest(new OidcCallbackContextImpl(
314+
OidcCallbackResult result = requestCallback.onRequest(new OidcCallbackContextImpl(
315315
CALLBACK_TIMEOUT, userName));
316316
jwt[0] = populateCacheWithCallbackResultAndPrepareJwt(null, result);
317317
if (result.getRefreshToken() != null) {
@@ -341,7 +341,7 @@ private byte[] evaluate(final byte[] challenge) {
341341
IdpInfo idpInfo = toIdpInfo(challenge);
342342
// there is no cached refresh token
343343
fallbackState = FallbackState.PHASE_3B_CALLBACK_TOKEN;
344-
OidcTokens result = requestCallback.onRequest(new OidcCallbackContextImpl(
344+
OidcCallbackResult result = requestCallback.onRequest(new OidcCallbackContextImpl(
345345
CALLBACK_TIMEOUT, idpInfo, null, userName));
346346
jwt[0] = populateCacheWithCallbackResultAndPrepareJwt(idpInfo, result);
347347
}
@@ -485,7 +485,7 @@ public boolean isComplete() {
485485

486486
}
487487

488-
private static String readTestTokenFromFile() {
488+
private static String readTokenFromFile() {
489489
String path = System.getenv(OIDC_TOKEN_FILE);
490490
if (path == null) {
491491
throw new MongoClientException(
@@ -502,14 +502,14 @@ private static String readTestTokenFromFile() {
502502

503503
private byte[] populateCacheWithCallbackResultAndPrepareJwt(
504504
@Nullable final IdpInfo serverInfo,
505-
@Nullable final OidcTokens oidcTokens) {
506-
if (oidcTokens == null) {
505+
@Nullable final OidcCallbackResult oidcCallbackResult) {
506+
if (oidcCallbackResult == null) {
507507
throw new MongoConfigurationException("Result of callback must not be null");
508508
}
509-
OidcCacheEntry newEntry = new OidcCacheEntry(oidcTokens.getAccessToken(),
510-
oidcTokens.getRefreshToken(), serverInfo);
509+
OidcCacheEntry newEntry = new OidcCacheEntry(oidcCallbackResult.getAccessToken(),
510+
oidcCallbackResult.getRefreshToken(), serverInfo);
511511
getMongoCredentialWithCache().setOidcCacheEntry(newEntry);
512-
return prepareTokenAsJwt(oidcTokens.getAccessToken());
512+
return prepareTokenAsJwt(oidcCallbackResult.getAccessToken());
513513
}
514514

515515
private static byte[] prepareUsername(@Nullable final String username) {

driver-sync/src/test/functional/com/mongodb/internal/connection/OidcAuthenticationProseTests.java

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
import static com.mongodb.MongoCredential.OIDC_HUMAN_CALLBACK_KEY;
6565
import static com.mongodb.MongoCredential.OidcCallback;
6666
import static com.mongodb.MongoCredential.OidcCallbackContext;
67-
import static com.mongodb.MongoCredential.OidcTokens;
67+
import static com.mongodb.MongoCredential.OidcCallbackResult;
6868
import static com.mongodb.assertions.Assertions.assertNotNull;
6969
import static java.lang.System.getenv;
7070
import static java.util.Arrays.asList;
@@ -211,7 +211,7 @@ public void test2p3CallbackReturnsMissingData() {
211211
// conforming to the OIDCRequestTokenResult with missing field(s).
212212
OidcCallback callback = (context) -> {
213213
//noinspection ConstantConditions
214-
return new OidcTokens(null);
214+
return new OidcCallbackResult(null);
215215
};
216216
// we ensure that the error is propagated
217217
MongoClientSettings clientSettings = createSettings(callback);
@@ -238,7 +238,7 @@ public void test3p1AuthFailsWithCachedToken() throws ExecutionException, Interru
238238
// reference to the token to poison
239239
CompletableFuture<String> poisonToken = new CompletableFuture<>();
240240
OidcCallback callback = (context) -> {
241-
OidcTokens result = callbackWrapped.onRequest(context);
241+
OidcCallbackResult result = callbackWrapped.onRequest(context);
242242
String accessToken = result.getAccessToken();
243243
if (!poisonToken.isDone()) {
244244
poisonToken.complete(accessToken);
@@ -272,7 +272,7 @@ public void test3p1AuthFailsWithCachedToken() throws ExecutionException, Interru
272272
@Test
273273
public void test3p2AuthFailsWithoutCachedToken() {
274274
OidcCallback callback =
275-
(x) -> new OidcTokens("invalid_token");
275+
(x) -> new OidcCallbackResult("invalid_token");
276276
MongoClientSettings clientSettings = createSettings(callback);
277277
try (MongoClient mongoClient = createMongoClient(clientSettings)) {
278278
assertCause(MongoCommandException.class,
@@ -328,8 +328,8 @@ public void test4p2ReadCommandsFailIfReauthenticationFails() {
328328
// and then bad tokens after the first call.
329329
TestCallback wrappedCallback = createCallback();
330330
OidcCallback callback = (context) -> {
331-
OidcTokens result1 = wrappedCallback.callback(context);
332-
return new OidcTokens(wrappedCallback.getInvocations() > 1 ? "bad" : result1.getAccessToken());
331+
OidcCallbackResult result1 = wrappedCallback.callback(context);
332+
return new OidcCallbackResult(wrappedCallback.getInvocations() > 1 ? "bad" : result1.getAccessToken());
333333
};
334334
MongoClientSettings clientSettings = createSettings(callback);
335335
try (MongoClient mongoClient = createMongoClient(clientSettings)) {
@@ -348,8 +348,8 @@ public void test4p3WriteCommandsFailIfReauthenticationFails() {
348348
// and then bad tokens after the first call.
349349
TestCallback wrappedCallback = createCallback();
350350
OidcCallback callback = (context) -> {
351-
OidcTokens result1 = wrappedCallback.callback(context);
352-
return new OidcTokens(
351+
OidcCallbackResult result1 = wrappedCallback.callback(context);
352+
return new OidcCallbackResult(
353353
wrappedCallback.getInvocations() > 1 ? "bad" : result1.getAccessToken());
354354
};
355355
MongoClientSettings clientSettings = createSettings(callback);
@@ -526,7 +526,7 @@ public void testh2p2HumanCallbackReturnsMissingData() {
526526

527527
//noinspection ConstantConditions
528528
OidcCallback callback =
529-
(context) -> new OidcTokens(null);
529+
(context) -> new OidcCallbackResult(null);
530530
assertFindFails(createHumanSettings(callback, null),
531531
IllegalArgumentException.class,
532532
"accessToken can not be null");
@@ -537,7 +537,7 @@ public void testh2p2HumanCallbackReturnsMissingData() {
537537
public void testRefreshTokenAbsent() {
538538
// additionally, check validation for refresh in machine workflow:
539539
OidcCallback callbackMachineRefresh =
540-
(context) -> new OidcTokens("access", Duration.ZERO, "exists");
540+
(context) -> new OidcCallbackResult("access", Duration.ZERO, "exists");
541541
assertFindFails(createSettings(callbackMachineRefresh),
542542
MongoConfigurationException.class,
543543
"Refresh token must only be provided in human workflow");
@@ -648,8 +648,8 @@ public void testh4p3SucceedsAfterRefreshFails() {
648648
assumeTestEnvironment();
649649
TestCallback callback1 = createHumanCallback();
650650
OidcCallback callback2 = (context) -> {
651-
OidcTokens oidcTokens = callback1.onRequest(context);
652-
return new OidcTokens(oidcTokens.getAccessToken(), Duration.ofMinutes(5), "BAD_REFRESH");
651+
OidcCallbackResult oidcCallbackResult = callback1.onRequest(context);
652+
return new OidcCallbackResult(oidcCallbackResult.getAccessToken(), Duration.ofMinutes(5), "BAD_REFRESH");
653653
};
654654
MongoClientSettings clientSettings = createHumanSettings(callback2, null);
655655
try (MongoClient mongoClient = createMongoClient(clientSettings)) {
@@ -670,8 +670,8 @@ public void testh4p4Fails() {
670670
TestCallback callback1 = createHumanCallback()
671671
.setPathSupplier(() -> tokens.remove());
672672
OidcCallback callback2 = (context) -> {
673-
OidcTokens oidcTokens = callback1.onRequest(context);
674-
return new OidcTokens(oidcTokens.getAccessToken(), Duration.ofMinutes(5), "BAD_REFRESH");
673+
OidcCallbackResult oidcCallbackResult = callback1.onRequest(context);
674+
return new OidcCallbackResult(oidcCallbackResult.getAccessToken(), Duration.ofMinutes(5), "BAD_REFRESH");
675675
};
676676
MongoClientSettings clientSettings = createHumanSettings(callback2, null);
677677
try (MongoClient mongoClient = createMongoClient(clientSettings)) {
@@ -976,7 +976,7 @@ public int getInvocations() {
976976
}
977977

978978
@Override
979-
public OidcTokens onRequest(final OidcCallbackContext context) {
979+
public OidcCallbackResult onRequest(final OidcCallbackContext context) {
980980
if (testListener != null) {
981981
testListener.add("onRequest invoked ("
982982
+ "Refresh Token: " + (context.getRefreshToken() == null ? "none" : "present")
@@ -986,7 +986,7 @@ public OidcTokens onRequest(final OidcCallbackContext context) {
986986
return callback(context);
987987
}
988988

989-
private OidcTokens callback(final OidcCallbackContext context) {
989+
private OidcCallbackResult callback(final OidcCallbackContext context) {
990990
if (concurrentTracker != null) {
991991
if (concurrentTracker.get() > 0) {
992992
throw new RuntimeException("Callbacks should not be invoked by multiple threads.");
@@ -1007,12 +1007,7 @@ private OidcTokens callback(final OidcCallbackContext context) {
10071007
c = OidcAuthenticator.getAzureCallback(credential);
10081008
} else if (oidcEnv.contains("gcp")) {
10091009
c = OidcAuthenticator.getGcpCallback(credential);
1010-
} else if (oidcEnv.contains("test")) {
1011-
c = null;
10121010
} else {
1013-
c = null;
1014-
}
1015-
if (c == null) {
10161011
c = getProseTestCallback();
10171012
}
10181013
return c.onRequest(context);
@@ -1034,7 +1029,7 @@ private OidcCallback getProseTestCallback() {
10341029
if (testListener != null) {
10351030
testListener.add("read access token: " + path.getFileName());
10361031
}
1037-
return new OidcTokens(accessToken, Duration.ZERO, refreshToken);
1032+
return new OidcCallbackResult(accessToken, Duration.ZERO, refreshToken);
10381033
} catch (IOException e) {
10391034
throw new RuntimeException(e);
10401035
}

0 commit comments

Comments
 (0)