Skip to content

Commit 4abb4db

Browse files
committed
Added function for dummy RAB.
1 parent ef6eff6 commit 4abb4db

12 files changed

Lines changed: 172 additions & 441 deletions

google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/RegionalAccessBoundary.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,6 @@ public String toString() {
164164
}
165165
}
166166

167-
/**
168-
* Checks if the regional access boundary feature is enabled.
169-
*
170-
* <p>This method is for internal use only and may be changed or removed in future releases.
171-
*
172-
* @return True if the regional access boundary feature is enabled, false otherwise.
173-
*/
174-
175167
/**
176168
* Refreshes the regional access boundary by making a network call to the lookup endpoint.
177169
*

google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/RegionalAccessBoundaryManager.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
package com.google.auth.oauth2;
3333

34+
import static com.google.auth.oauth2.LoggingUtils.log;
35+
3436
import com.google.api.client.util.Clock;
3537
import com.google.api.core.InternalApi;
3638
import com.google.auth.http.HttpTransportFactory;
@@ -215,11 +217,13 @@ void triggerAsyncRefresh(
215217
} catch (Exception | Error e) {
216218
// If scheduling fails (e.g., RejectedExecutionException, OutOfMemoryError for threads),
217219
// the task's finally block will never execute. We must release the lock here.
218-
LoggingUtils.log(
220+
log(
219221
LOGGER_PROVIDER,
220-
java.util.logging.Level.WARNING,
222+
Level.FINE,
221223
null,
222-
"Regional Access Boundary background refresh failed to schedule: " + e.getMessage());
224+
"Could not submit background refresh task for Regional Access Boundary. "
225+
+ "This is non-blocking and the library will attempt to refresh on the next access. Error: "
226+
+ e.getMessage());
223227
future.setException(e);
224228
refreshFuture.set(null);
225229
}
@@ -247,13 +251,13 @@ private void handleRefreshFailure(Exception e) {
247251
// concurrent failures from logging redundant messages or incorrectly calculating
248252
// the exponential backoff.
249253
if (cooldownState.compareAndSet(currentCooldownState, next)) {
250-
LoggingUtils.log(
254+
log(
251255
LOGGER_PROVIDER,
252256
Level.FINE,
253257
null,
254-
"Regional Access Boundary lookup failed; entering cooldown for "
258+
"Regional Access Boundary lookup was not successful; will retry after a cooldown of "
255259
+ (next.durationMillis / 60000)
256-
+ "m. Error: "
260+
+ "m. This is handled automatically. Details: "
257261
+ e.getMessage());
258262
}
259263
}

google-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/AwsCredentialsTest.java

Lines changed: 36 additions & 99 deletions
Large diffs are not rendered by default.

google-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/ComputeEngineCredentialsTest.java

Lines changed: 31 additions & 89 deletions
Large diffs are not rendered by default.

google-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/ExternalAccountAuthorizedUserCredentialsTest.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
package com.google.auth.oauth2;
3333

3434
import static com.google.auth.Credentials.GOOGLE_DEFAULT_UNIVERSE;
35+
import static com.google.auth.oauth2.TestUtils.createDummyRab;
3536
import static org.junit.jupiter.api.Assertions.assertEquals;
3637
import static org.junit.jupiter.api.Assertions.assertFalse;
3738
import static org.junit.jupiter.api.Assertions.assertNotEquals;
@@ -706,9 +707,7 @@ void createScopedRequired_false() {
706707
void getRequestMetadata() throws IOException {
707708
GoogleCredentials credentials =
708709
ExternalAccountAuthorizedUserCredentials.fromJson(buildJsonCredentials(), transportFactory);
709-
credentials.regionalAccessBoundaryManager.setCachedRAB(
710-
new RegionalAccessBoundary(
711-
"dummy-locations", Arrays.asList("dummy-loc"), credentials.clock));
710+
credentials.regionalAccessBoundaryManager.setCachedRAB(createDummyRab(credentials.clock));
712711

713712
Map<String, List<String>> metadata = credentials.getRequestMetadata(CALL_URI);
714713

@@ -720,9 +719,7 @@ void getRequestMetadata() throws IOException {
720719
void getRequestMetadata_withQuotaProjectId() throws IOException {
721720
GoogleCredentials credentials =
722721
ExternalAccountAuthorizedUserCredentials.fromJson(buildJsonCredentials(), transportFactory);
723-
credentials.regionalAccessBoundaryManager.setCachedRAB(
724-
new RegionalAccessBoundary(
725-
"dummy-locations", Arrays.asList("dummy-loc"), credentials.clock));
722+
credentials.regionalAccessBoundaryManager.setCachedRAB(createDummyRab(credentials.clock));
726723

727724
Map<String, List<String>> metadata = credentials.getRequestMetadata(CALL_URI);
728725

@@ -741,9 +738,7 @@ void getRequestMetadata_withAccessToken() throws IOException {
741738
.setHttpTransportFactory(transportFactory)
742739
.setAccessToken(new AccessToken(ACCESS_TOKEN, /* expirationTime= */ null))
743740
.build();
744-
credentials.regionalAccessBoundaryManager.setCachedRAB(
745-
new RegionalAccessBoundary(
746-
"dummy-locations", Arrays.asList("dummy-loc"), credentials.clock));
741+
credentials.regionalAccessBoundaryManager.setCachedRAB(createDummyRab(credentials.clock));
747742

748743
Map<String, List<String>> metadata = credentials.getRequestMetadata(CALL_URI);
749744

google-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/ExternalAccountCredentialsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import static com.google.auth.oauth2.OAuth2Utils.IAM_CREDENTIALS_ALLOWED_LOCATIONS_URL_FORMAT_SERVICE_ACCOUNT;
3636
import static com.google.auth.oauth2.OAuth2Utils.IAM_CREDENTIALS_ALLOWED_LOCATIONS_URL_FORMAT_WORKFORCE_POOL;
3737
import static com.google.auth.oauth2.OAuth2Utils.IAM_CREDENTIALS_ALLOWED_LOCATIONS_URL_FORMAT_WORKLOAD_POOL;
38+
import static com.google.auth.oauth2.TestUtils.createDummyRab;
3839
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
3940
import static org.junit.jupiter.api.Assertions.assertEquals;
4041
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
@@ -1109,8 +1110,7 @@ void getRequestMetadata_withQuotaProjectId() throws IOException {
11091110
.setQuotaProjectId("quotaProjectId")
11101111
.build();
11111112
testCredentials.regionalAccessBoundaryManager.setCachedRAB(
1112-
new RegionalAccessBoundary(
1113-
"dummy-locations", Arrays.asList("dummy-loc"), testCredentials.clock));
1113+
createDummyRab(testCredentials.clock));
11141114

11151115
Map<String, List<String>> requestMetadata =
11161116
testCredentials.getRequestMetadata(URI.create("http://googleapis.com/foo/bar"));

google-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/IdTokenCredentialsTest.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131

3232
package com.google.auth.oauth2;
3333

34+
import static com.google.auth.oauth2.TestUtils.createDummyRab;
3435
import static org.junit.jupiter.api.Assertions.assertEquals;
3536

3637
import java.io.IOException;
37-
import java.util.Arrays;
3838
import org.junit.jupiter.api.Test;
3939

4040
/** Test case for {@link IdTokenCredentials}. */
@@ -47,9 +47,7 @@ void hashCode_equals() throws IOException {
4747
transportFactory.transport.setIdToken(ComputeEngineCredentialsTest.STANDARD_ID_TOKEN);
4848
ComputeEngineCredentials credentials =
4949
ComputeEngineCredentials.newBuilder().setHttpTransportFactory(transportFactory).build();
50-
credentials.regionalAccessBoundaryManager.setCachedRAB(
51-
new RegionalAccessBoundary(
52-
"dummy-locations", Arrays.asList("dummy-loc"), credentials.clock));
50+
credentials.regionalAccessBoundaryManager.setCachedRAB(createDummyRab(credentials.clock));
5351

5452
String targetAudience = "https://foo.bar";
5553
IdTokenCredentials tokenCredential =
@@ -76,9 +74,7 @@ void toString_equals() throws IOException {
7674
transportFactory.transport.setIdToken(ComputeEngineCredentialsTest.STANDARD_ID_TOKEN);
7775
ComputeEngineCredentials credentials =
7876
ComputeEngineCredentials.newBuilder().setHttpTransportFactory(transportFactory).build();
79-
credentials.regionalAccessBoundaryManager.setCachedRAB(
80-
new RegionalAccessBoundary(
81-
"dummy-locations", Arrays.asList("dummy-loc"), credentials.clock));
77+
credentials.regionalAccessBoundaryManager.setCachedRAB(createDummyRab(credentials.clock));
8278

8379
String targetAudience = "https://foo.bar";
8480
IdTokenCredentials tokenCredential =
@@ -106,9 +102,7 @@ void serialize() throws IOException, ClassNotFoundException {
106102
transportFactory.transport.setIdToken(ComputeEngineCredentialsTest.STANDARD_ID_TOKEN);
107103
ComputeEngineCredentials credentials =
108104
ComputeEngineCredentials.newBuilder().setHttpTransportFactory(transportFactory).build();
109-
credentials.regionalAccessBoundaryManager.setCachedRAB(
110-
new RegionalAccessBoundary(
111-
"dummy-locations", Arrays.asList("dummy-loc"), credentials.clock));
105+
credentials.regionalAccessBoundaryManager.setCachedRAB(createDummyRab(credentials.clock));
112106

113107
String targetAudience = "https://foo.bar";
114108
IdTokenCredentials tokenCredential =

0 commit comments

Comments
 (0)