Skip to content

Commit

Permalink
chore: Throw IOException on validateUniverseDomain
Browse files Browse the repository at this point in the history
  • Loading branch information
lqiu96 committed Mar 6, 2024
1 parent 7a0b3fa commit 83612b6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,30 +147,24 @@ private String determineEndpoint(Builder builder) {
* from the google-auth-library. If the HttpRequestInitializer is not used, the configured
* Universe Domain is validated against the Google Default Universe (GDU): `googleapis.com`.
*
* @throws IllegalStateException if the configured Universe Domain does not match the Universe
* Domain in the Credentials
* @throws IOException if the configured Universe Domain does not match the Universe Domain in the
* Credentials or there is an error reading the Universe Domain from the credentials
*/
public void validateUniverseDomain() {
public void validateUniverseDomain() throws IOException {
String expectedUniverseDomain;
try {
if (!(httpRequestInitializer instanceof HttpCredentialsAdapter)) {
expectedUniverseDomain = Credentials.GOOGLE_DEFAULT_UNIVERSE;
} else {
Credentials credentials =
((HttpCredentialsAdapter) httpRequestInitializer).getCredentials();
expectedUniverseDomain = credentials.getUniverseDomain();
}
if (!expectedUniverseDomain.equals(getUniverseDomain())) {
throw new IllegalStateException(
String.format(
"The configured universe domain (%s) does not match the universe domain found"
+ " in the credentials (%s). If you haven't configured the universe domain"
+ " explicitly, `googleapis.com` is the default.",
getUniverseDomain(), expectedUniverseDomain));
}
} catch (IOException e) {
throw new IllegalStateException(
"Unable to retrieve the Universe Domain from the Credentials.", e);
if (!(httpRequestInitializer instanceof HttpCredentialsAdapter)) {
expectedUniverseDomain = Credentials.GOOGLE_DEFAULT_UNIVERSE;
} else {
Credentials credentials = ((HttpCredentialsAdapter) httpRequestInitializer).getCredentials();
expectedUniverseDomain = credentials.getUniverseDomain();
}
if (!expectedUniverseDomain.equals(getUniverseDomain())) {
throw new IOException(
String.format(
"The configured universe domain (%s) does not match the universe domain found"
+ " in the credentials (%s). If you haven't configured the universe domain"
+ " explicitly, `googleapis.com` is the default.",
getUniverseDomain(), expectedUniverseDomain));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,17 +351,18 @@ public void validateUniverseDomain_invalidUniverseDomain() throws IOException {
.setApplicationName(applicationName)
.build();
assertThrows(
IllegalStateException.class,
IOException.class,
new ThrowingRunnable() {
@Override
public void run() {
public void run() throws IOException {
client.validateUniverseDomain();
}
});
}

@Test
public void validateUniverseDomain_notUsingHttpCredentialsAdapter_defaultUniverseDomain() {
public void validateUniverseDomain_notUsingHttpCredentialsAdapter_defaultUniverseDomain()
throws IOException {
String rootUrl = "https://test.googleapis.com/";
String applicationName = "Test Application";
String servicePath = "test/";
Expand Down Expand Up @@ -398,10 +399,10 @@ public void validateUniverseDomain_notUsingHttpCredentialsAdapter_customUniverse
.setUniverseDomain(universeDomain)
.build();
assertThrows(
IllegalStateException.class,
IOException.class,
new ThrowingRunnable() {
@Override
public void run() {
public void run() throws IOException {
client.validateUniverseDomain();
}
});
Expand Down

0 comments on commit 83612b6

Please sign in to comment.