Skip to content

Commit 7465abd

Browse files
Make testDownloadPublicBlobWithoutAuthentication skippable with an environment variable (#3828)
* Add assumptions to storage integration tests * Make testDownloadPublicBlobWithoutAuthentication skippable with an environment variable * Make testDownloadPublicBlobWithoutAuthentication skippable with an environment variable
1 parent a45fe30 commit 7465abd

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

  • google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/it

google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import static org.junit.Assume.assumeFalse;
2929
import static org.junit.Assume.assumeTrue;
3030

31-
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
3231
import com.google.api.gax.paging.Page;
3332
import com.google.auth.ServiceAccountSigner;
3433
import com.google.auth.oauth2.GoogleCredentials;
@@ -143,6 +142,8 @@ public class ITStorageTest {
143142
private static final String KMS_KEY_RING_LOCATION = "us";
144143
private static final String KMS_KEY_ONE_NAME = "gcs_kms_key_one";
145144
private static final String KMS_KEY_TWO_NAME = "gcs_kms_key_two";
145+
private static final boolean IS_VPC_TEST = System.getenv("GOOGLE_CLOUD_TESTS_IN_VPCSC") != null
146+
&& System.getenv("GOOGLE_CLOUD_TESTS_IN_VPCSC").equalsIgnoreCase("true");
146147

147148
@BeforeClass
148149
public static void beforeClass() throws IOException {
@@ -1661,20 +1662,16 @@ public void testGetBlobs() {
16611662

16621663
@Test
16631664
public void testDownloadPublicBlobWithoutAuthentication() {
1665+
assumeFalse(IS_VPC_TEST);
16641666
// create an unauthorized user
16651667
Storage unauthorizedStorage = StorageOptions.getUnauthenticatedInstance().getService();
16661668

16671669
// try to download blobs from a public bucket
16681670
String landsatBucket = "gcp-public-data-landsat";
16691671
String landsatPrefix = "LC08/PRE/044/034/LC80440342016259LGN00/";
16701672
String landsatBlob = landsatPrefix + "LC80440342016259LGN00_MTL.txt";
1671-
byte[] bytes;
1672-
try {
1673-
bytes = unauthorizedStorage.readAllBytes(landsatBucket, landsatBlob);
1674-
} catch (StorageException ex) {
1675-
assumeFalse(403 == ex.getCode());
1676-
return;
1677-
}
1673+
byte[] bytes = unauthorizedStorage.readAllBytes(landsatBucket, landsatBlob);
1674+
16781675
assertThat(bytes.length).isEqualTo(7903);
16791676
int numBlobs = 0;
16801677
Iterator<Blob> blobIterator = unauthorizedStorage

0 commit comments

Comments
 (0)