-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update grpc x-goog-user-project handling gracefulness (#1983)
When an instance of credentials that hasRequestMetadata() but can't refresh an IllegalStateException can be thrown. Add new tests to force failure and update handling to be graceful of this.
- Loading branch information
1 parent
86fbc4a
commit f274739
Showing
3 changed files
with
124 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageOptionsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.cloud.storage.it; | ||
|
||
import static org.junit.Assume.assumeTrue; | ||
|
||
import com.google.auth.Credentials; | ||
import com.google.auth.oauth2.GoogleCredentials; | ||
import com.google.auth.oauth2.OAuth2Credentials; | ||
import com.google.cloud.NoCredentials; | ||
import com.google.cloud.storage.Storage; | ||
import com.google.cloud.storage.StorageOptions; | ||
import com.google.cloud.storage.TestUtils; | ||
import com.google.cloud.storage.it.ITStorageOptionsTest.CredentialsParameters; | ||
import com.google.cloud.storage.it.runner.StorageITRunner; | ||
import com.google.cloud.storage.it.runner.annotations.Backend; | ||
import com.google.cloud.storage.it.runner.annotations.Parameterized; | ||
import com.google.cloud.storage.it.runner.annotations.Parameterized.Parameter; | ||
import com.google.cloud.storage.it.runner.annotations.Parameterized.ParametersProvider; | ||
import com.google.cloud.storage.it.runner.annotations.SingleBackend; | ||
import com.google.common.collect.ImmutableList; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(StorageITRunner.class) | ||
@SingleBackend(Backend.PROD) | ||
@Parameterized(CredentialsParameters.class) | ||
public final class ITStorageOptionsTest { | ||
|
||
public static final class CredentialsParameters implements ParametersProvider { | ||
|
||
@Override | ||
public ImmutableList<?> parameters() { | ||
return ImmutableList.of( | ||
NoCredentials.getInstance(), | ||
GoogleCredentials.create(/* accessToken= */ null), | ||
OAuth2Credentials.create(null)); | ||
} | ||
} | ||
|
||
@Parameter public Credentials credentials; | ||
|
||
@Test | ||
public void clientShouldConstructCleanly_http() throws Exception { | ||
StorageOptions options = StorageOptions.http().setCredentials(credentials).build(); | ||
doTest(options); | ||
} | ||
|
||
@Test | ||
public void clientShouldConstructCleanly_grpc() throws Exception { | ||
StorageOptions options = | ||
StorageOptions.grpc().setCredentials(credentials).setAttemptDirectPath(false).build(); | ||
doTest(options); | ||
} | ||
|
||
@Test | ||
@Ignore("waiting on conformation from the backend team if this should even be possible") | ||
public void clientShouldConstructCleanly_directPath() throws Exception { | ||
assumeTrue( | ||
"Unable to determine environment can access directPath", TestUtils.isOnComputeEngine()); | ||
StorageOptions options = | ||
StorageOptions.grpc().setCredentials(credentials).setAttemptDirectPath(true).build(); | ||
doTest(options); | ||
} | ||
|
||
private static void doTest(StorageOptions options) throws Exception { | ||
//noinspection EmptyTryBlock | ||
try (Storage ignore = options.getService()) {} | ||
} | ||
} |