From 5b67dd5884e0740340a1ad3ea35a31240fe8d21a Mon Sep 17 00:00:00 2001 From: Nidhi Nandwani Date: Wed, 25 Nov 2026 13:45:42 +0000 Subject: [PATCH 1/4] fix(storage): make URL signing universe domain handling consistent with EndpointContext StorageImpl derives default signing hosts from the configured universe domain and checks the signer's universe domain as EndpointContext does. Hostname options and signature formats in the default universe are unchanged. StorageSigningUniverseDomainTest covers signUrl and generateSignedPostPolicyV4. --- java-storage/google-cloud-storage/pom.xml | 4 + .../com/google/cloud/storage/StorageImpl.java | 45 ++++ .../StorageSigningUniverseDomainTest.java | 222 ++++++++++++++++++ 3 files changed, 271 insertions(+) create mode 100644 java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageSigningUniverseDomainTest.java diff --git a/java-storage/google-cloud-storage/pom.xml b/java-storage/google-cloud-storage/pom.xml index 3a3796606da7..009de2bfe9bd 100644 --- a/java-storage/google-cloud-storage/pom.xml +++ b/java-storage/google-cloud-storage/pom.xml @@ -83,6 +83,10 @@ com.google.api gax-grpc + + com.google.api + gax-httpjson + com.google.auth google-auth-library-credentials diff --git a/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java b/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java index 8ee6a141e215..25318fce1048 100644 --- a/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java +++ b/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java @@ -25,13 +25,20 @@ import com.google.api.client.util.Data; import com.google.api.core.ApiFuture; +import com.google.api.gax.httpjson.HttpJsonStatusCode; import com.google.api.gax.paging.Page; import com.google.api.gax.retrying.BasicResultRetryAlgorithm; import com.google.api.gax.retrying.ResultRetryAlgorithm; +import com.google.api.gax.rpc.EndpointContext; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.UnauthenticatedException; import com.google.api.services.storage.model.BucketAccessControl; import com.google.api.services.storage.model.ObjectAccessControl; import com.google.api.services.storage.model.StorageObject; +import com.google.auth.Credentials; import com.google.auth.ServiceAccountSigner; +import com.google.auth.oauth2.ComputeEngineCredentials; +import com.google.auth.oauth2.GdchCredentials; import com.google.cloud.BaseService; import com.google.cloud.BatchResult; import com.google.cloud.PageImpl; @@ -891,6 +898,7 @@ public URL signUrl(BlobInfo blobInfo, long duration, TimeUnit unit, SignUrlOptio "Signing key was not provided and could not be derived"); credentials = (ServiceAccountSigner) this.getOptions().getCredentials(); } + validateSigningCredentialsUniverseDomain(credentials, optionMap); long expiration = isV4 @@ -998,6 +1006,7 @@ public PostPolicyV4 generateSignedPostPolicyV4( "Signing key was not provided and could not be derived"); credentials = (ServiceAccountSigner) this.getOptions().getCredentials(); } + validateSigningCredentialsUniverseDomain(credentials, optionMap); checkArgument( !(optionMap.containsKey(SignUrlOption.Option.VIRTUAL_HOSTED_STYLE) @@ -1107,6 +1116,42 @@ public PostPolicyV4 generateSignedPostPolicyV4( blobInfo, duration, unit, PostFieldsV4.newBuilder().build(), options); } + private void validateSigningCredentialsUniverseDomain( + ServiceAccountSigner signer, Map optionMap) { + if (!Strings.isNullOrEmpty((String) optionMap.get(SignUrlOption.Option.HOST_NAME)) + || optionMap.containsKey(SignUrlOption.Option.BUCKET_BOUND_HOST_NAME) + || !(signer instanceof Credentials) + || signer instanceof GdchCredentials + || signer instanceof ComputeEngineCredentials) { + return; + } + Credentials credentialsToValidate = (Credentials) signer; + String credentialsUniverseDomain; + try { + credentialsUniverseDomain = + firstNonNull( + credentialsToValidate.getUniverseDomain(), Credentials.GOOGLE_DEFAULT_UNIVERSE); + } catch (IOException e) { + throw unauthenticated(EndpointContext.UNABLE_TO_RETRIEVE_CREDENTIALS_ERROR_MESSAGE, e); + } + String configuredUniverseDomain = getOptions().getResolvedUniverseDomain(); + if (!configuredUniverseDomain.equals(credentialsUniverseDomain)) { + String errorMessage = + String.format( + EndpointContext.INVALID_UNIVERSE_DOMAIN_ERROR_TEMPLATE, + configuredUniverseDomain, + credentialsUniverseDomain); + throw unauthenticated(errorMessage, new Throwable(errorMessage)); + } + } + + private static StorageException unauthenticated(String message, Throwable cause) { + UnauthenticatedException unauthenticatedException = + new UnauthenticatedException( + message, cause, HttpJsonStatusCode.of(StatusCode.Code.UNAUTHENTICATED), false); + return new StorageException(401, message, unauthenticatedException); + } + private String constructResourceUriPath( String slashlessBucketName, String escapedBlobName, diff --git a/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageSigningUniverseDomainTest.java b/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageSigningUniverseDomainTest.java new file mode 100644 index 000000000000..ddbfe05af538 --- /dev/null +++ b/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageSigningUniverseDomainTest.java @@ -0,0 +1,222 @@ +/* + * Copyright 2026 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; + +import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertThrows; + +import com.google.api.core.ApiClock; +import com.google.api.gax.rpc.EndpointContext; +import com.google.api.gax.rpc.UnauthenticatedException; +import com.google.auth.Credentials; +import com.google.auth.ServiceAccountSigner; +import com.google.auth.oauth2.ServiceAccountCredentials; +import com.google.cloud.NoCredentials; +import com.google.cloud.storage.PostPolicyV4.PostConditionsV4; +import com.google.cloud.storage.PostPolicyV4.PostFieldsV4; +import com.google.cloud.storage.Storage.PostPolicyV4Option; +import com.google.cloud.storage.Storage.SignUrlOption; +import com.google.cloud.storage.Storage.UriScheme; +import com.google.common.collect.ObjectArrays; +import java.net.URL; +import java.security.KeyPairGenerator; +import java.security.PrivateKey; +import java.util.concurrent.TimeUnit; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.junit.After; +import org.junit.Test; + +public final class StorageSigningUniverseDomainTest { + + private static final String CUSTOM_UNIVERSE = "custom.example.com"; + private static final long FIXED_TIMESTAMP_MILLIS = 1700000000000L; + private static final BlobInfo BLOB_INFO = BlobInfo.newBuilder("my-bucket", "my-obj.txt").build(); + private static final PrivateKey RSA_KEY = generateRsaPrivateKey(); + private static final ApiClock FIXED_CLOCK = + new ApiClock() { + @Override + public long nanoTime() { + return TimeUnit.MILLISECONDS.toNanos(FIXED_TIMESTAMP_MILLIS); + } + + @Override + public long millisTime() { + return FIXED_TIMESTAMP_MILLIS; + } + }; + + @After + public void tearDown() { + StorageOptions.resetEnvResolverForTesting(); + } + + @Test + public void formatsSignedUrlsAndPostPolicyV4ForConfiguredUniverseDomain() { + setEnvUniverse(CUSTOM_UNIVERSE); + ServiceAccountCredentials customSigner = createServiceAccountCredentials(CUSTOM_UNIVERSE); + Storage storage = createStorage(customSigner, null); + + assertThat(storage.signUrl(BLOB_INFO, 15, TimeUnit.MINUTES).getHost()) + .isEqualTo("storage.custom.example.com"); + assertThat( + storage + .signUrl(BLOB_INFO, 15, TimeUnit.MINUTES, SignUrlOption.withVirtualHostedStyle()) + .getHost()) + .isEqualTo("my-bucket.storage.custom.example.com"); + + assertThat(signV4(storage).getHost()).isEqualTo("storage.custom.example.com"); + + assertThat(signV4(storage, SignUrlOption.withVirtualHostedStyle()).getHost()) + .isEqualTo("my-bucket.storage.custom.example.com"); + assertThat( + signV4(storage, SignUrlOption.withHostName("https://override.example.com")).getHost()) + .isEqualTo("override.example.com"); + assertThat( + signV4( + storage, + SignUrlOption.withBucketBoundHostname( + "cdn.custom.example.com", UriScheme.HTTPS)) + .getHost()) + .isEqualTo("cdn.custom.example.com"); + + assertThat(storage.generateSignedPostPolicyV4(BLOB_INFO, 900, TimeUnit.SECONDS).getUrl()) + .isEqualTo("https://storage.custom.example.com/my-bucket/"); + assertThat( + storage + .generateSignedPostPolicyV4( + BLOB_INFO, 900, TimeUnit.SECONDS, PostPolicyV4Option.withVirtualHostedStyle()) + .getUrl()) + .isEqualTo("https://my-bucket.storage.custom.example.com/"); + + Storage unauthStorage = StorageOptions.getUnauthenticatedInstance().getService(); + assertThat(signV4(unauthStorage, SignUrlOption.signWith(customSigner)).getHost()) + .isEqualTo("storage.custom.example.com"); + } + + @Test + public void validatesCredentialsUniverseDomainInSignUrl() { + Storage defaultStorage = createStorage(createServiceAccountCredentials(CUSTOM_UNIVERSE), null); + StorageException thrown = assertUnauthenticated(() -> signV4(defaultStorage)); + assertThat(thrown) + .hasMessageThat() + .contains(expectedMismatch(Credentials.GOOGLE_DEFAULT_UNIVERSE, CUSTOM_UNIVERSE)); + assertThat( + signV4(defaultStorage, SignUrlOption.withHostName("https://override.example.com")) + .getHost()) + .isEqualTo("override.example.com"); + + setEnvUniverse(CUSTOM_UNIVERSE); + Storage configuredStorage = createStorage(NoCredentials.getInstance(), null); + SignUrlOption signWithDefault = + SignUrlOption.signWith( + createServiceAccountCredentials(Credentials.GOOGLE_DEFAULT_UNIVERSE)); + assertUnauthenticated(() -> signV4(configuredStorage, signWithDefault)); + + ServiceAccountCredentials defaultCredentials = + createServiceAccountCredentials(Credentials.GOOGLE_DEFAULT_UNIVERSE); + ServiceAccountSigner signer = + new ServiceAccountSigner() { + @Override + public String getAccount() { + return defaultCredentials.getAccount(); + } + + @Override + public byte[] sign(byte[] toSign) { + return defaultCredentials.sign(toSign); + } + }; + Storage clientCredentialsStorage = createStorage(defaultCredentials, null); + assertThat(signV4(clientCredentialsStorage, SignUrlOption.signWith(signer)).getHost()) + .isEqualTo("storage.custom.example.com"); + } + + @Test + public void validatesCredentialsUniverseDomainInPostPolicyV4() { + Storage customStorage = createStorage(NoCredentials.getInstance(), CUSTOM_UNIVERSE); + PostFieldsV4 fields = PostFieldsV4.newBuilder().build(); + PostConditionsV4 conditions = PostConditionsV4.newBuilder().build(); + PostPolicyV4Option signWithDefault = + PostPolicyV4Option.signWith( + createServiceAccountCredentials(Credentials.GOOGLE_DEFAULT_UNIVERSE)); + + StorageException thrown = + assertUnauthenticated( + () -> + customStorage.generateSignedPostPolicyV4( + BLOB_INFO, 15, TimeUnit.MINUTES, fields, conditions, signWithDefault)); + assertThat(thrown) + .hasMessageThat() + .contains(expectedMismatch(CUSTOM_UNIVERSE, Credentials.GOOGLE_DEFAULT_UNIVERSE)); + } + + private static URL signV4(Storage storage, SignUrlOption... options) { + return storage.signUrl( + BLOB_INFO, + 900, + TimeUnit.SECONDS, + ObjectArrays.concat(SignUrlOption.withV4Signature(), options)); + } + + private static String expectedMismatch(String expectedUniverse, String actualUniverse) { + return String.format( + EndpointContext.INVALID_UNIVERSE_DOMAIN_ERROR_TEMPLATE, expectedUniverse, actualUniverse); + } + + private static void setEnvUniverse(String universe) { + StorageOptions.setEnvResolverForTesting( + k -> EndpointContext.GOOGLE_CLOUD_UNIVERSE_DOMAIN.equals(k) ? universe : null); + } + + private static Storage createStorage(Credentials creds, @Nullable String explicitUniverse) { + HttpStorageOptions.Builder builder = + StorageOptions.http().setProjectId("test-proj").setCredentials(creds).setClock(FIXED_CLOCK); + if (explicitUniverse != null) { + builder.setUniverseDomain(explicitUniverse); + } + return builder.build().getService(); + } + + private static StorageException assertUnauthenticated(Runnable runnable) { + StorageException thrown = assertThrows(StorageException.class, runnable::run); + assertThat(thrown.getCode()).isEqualTo(401); + assertThat(thrown.isRetryable()).isFalse(); + assertThat(thrown).hasCauseThat().isInstanceOf(UnauthenticatedException.class); + return thrown; + } + + private static ServiceAccountCredentials createServiceAccountCredentials(String universeDomain) { + return ServiceAccountCredentials.newBuilder() + .setClientId("test-client-id") + .setClientEmail("signer@test-proj.iam.gserviceaccount.com") + .setPrivateKey(RSA_KEY) + .setPrivateKeyId("test-key-id") + .setProjectId("test-proj") + .setUniverseDomain(universeDomain) + .build(); + } + + private static PrivateKey generateRsaPrivateKey() { + try { + KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA"); + generator.initialize(2048); + return generator.generateKeyPair().getPrivate(); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } +} From 7ef0f1cfa73a9569b12dff2277de11c4c063c970 Mon Sep 17 00:00:00 2001 From: Nidhi Nandwani Date: Wed, 2 Dec 2026 10:32:04 +0000 Subject: [PATCH 2/4] test(storage): initialize clean env resolver in StorageSigningUniverseDomainTest StorageSigningUniverseDomainTest now installs a clean test environment resolver in @Before, before default StorageOptions instances are built. Existing test cases and @After cleanup remain unchanged. [Generated-by: AI] --- .../cloud/storage/StorageSigningUniverseDomainTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageSigningUniverseDomainTest.java b/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageSigningUniverseDomainTest.java index ddbfe05af538..5d600e9f759a 100644 --- a/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageSigningUniverseDomainTest.java +++ b/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageSigningUniverseDomainTest.java @@ -38,6 +38,7 @@ import java.util.concurrent.TimeUnit; import org.checkerframework.checker.nullness.qual.Nullable; import org.junit.After; +import org.junit.Before; import org.junit.Test; public final class StorageSigningUniverseDomainTest { @@ -59,6 +60,11 @@ public long millisTime() { } }; + @Before + public void setUp() { + StorageOptions.setEnvResolverForTesting(k -> null); + } + @After public void tearDown() { StorageOptions.resetEnvResolverForTesting(); From 22dcd3e41a373048f5b43b4bc400ad9ec1d46f19 Mon Sep 17 00:00:00 2001 From: Nidhi Nandwani Date: Wed, 2 Dec 2026 10:51:15 +0000 Subject: [PATCH 3/4] fix(storage): apply signer universe domain check for all signing hosts StorageImpl validates the signer's universe domain for every signed URL and POST policy host, consistent with EndpointContext. Signature formats for credentials in the configured universe domain are unchanged. StorageSigningUniverseDomainTest covers hostname options and universe domain lookup failures. [Generated-by: AI] --- .../com/google/cloud/storage/StorageImpl.java | 11 +-- .../StorageSigningUniverseDomainTest.java | 80 ++++++++++++++++++- 2 files changed, 80 insertions(+), 11 deletions(-) diff --git a/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java b/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java index 25318fce1048..d858e443855c 100644 --- a/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java +++ b/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageImpl.java @@ -898,7 +898,7 @@ public URL signUrl(BlobInfo blobInfo, long duration, TimeUnit unit, SignUrlOptio "Signing key was not provided and could not be derived"); credentials = (ServiceAccountSigner) this.getOptions().getCredentials(); } - validateSigningCredentialsUniverseDomain(credentials, optionMap); + validateSigningCredentialsUniverseDomain(credentials); long expiration = isV4 @@ -1006,7 +1006,7 @@ public PostPolicyV4 generateSignedPostPolicyV4( "Signing key was not provided and could not be derived"); credentials = (ServiceAccountSigner) this.getOptions().getCredentials(); } - validateSigningCredentialsUniverseDomain(credentials, optionMap); + validateSigningCredentialsUniverseDomain(credentials); checkArgument( !(optionMap.containsKey(SignUrlOption.Option.VIRTUAL_HOSTED_STYLE) @@ -1116,11 +1116,8 @@ public PostPolicyV4 generateSignedPostPolicyV4( blobInfo, duration, unit, PostFieldsV4.newBuilder().build(), options); } - private void validateSigningCredentialsUniverseDomain( - ServiceAccountSigner signer, Map optionMap) { - if (!Strings.isNullOrEmpty((String) optionMap.get(SignUrlOption.Option.HOST_NAME)) - || optionMap.containsKey(SignUrlOption.Option.BUCKET_BOUND_HOST_NAME) - || !(signer instanceof Credentials) + private void validateSigningCredentialsUniverseDomain(ServiceAccountSigner signer) { + if (!(signer instanceof Credentials) || signer instanceof GdchCredentials || signer instanceof ComputeEngineCredentials) { return; diff --git a/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageSigningUniverseDomainTest.java b/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageSigningUniverseDomainTest.java index 5d600e9f759a..c4f9c97ecafa 100644 --- a/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageSigningUniverseDomainTest.java +++ b/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageSigningUniverseDomainTest.java @@ -32,9 +32,14 @@ import com.google.cloud.storage.Storage.SignUrlOption; import com.google.cloud.storage.Storage.UriScheme; import com.google.common.collect.ObjectArrays; +import java.io.IOException; +import java.net.URI; import java.net.URL; import java.security.KeyPairGenerator; import java.security.PrivateKey; +import java.util.Collections; +import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; import org.checkerframework.checker.nullness.qual.Nullable; import org.junit.After; @@ -120,10 +125,18 @@ public void validatesCredentialsUniverseDomainInSignUrl() { assertThat(thrown) .hasMessageThat() .contains(expectedMismatch(Credentials.GOOGLE_DEFAULT_UNIVERSE, CUSTOM_UNIVERSE)); - assertThat( - signV4(defaultStorage, SignUrlOption.withHostName("https://override.example.com")) - .getHost()) - .isEqualTo("override.example.com"); + StorageException hostOverrideThrown = + assertUnauthenticated( + () -> + signV4(defaultStorage, SignUrlOption.withHostName("https://override.example.com"))); + assertThat(hostOverrideThrown) + .hasMessageThat() + .contains(expectedMismatch(Credentials.GOOGLE_DEFAULT_UNIVERSE, CUSTOM_UNIVERSE)); + assertUnauthenticated( + () -> + signV4( + defaultStorage, + SignUrlOption.withBucketBoundHostname("cdn.custom.example.com", UriScheme.HTTPS))); setEnvUniverse(CUSTOM_UNIVERSE); Storage configuredStorage = createStorage(NoCredentials.getInstance(), null); @@ -149,6 +162,13 @@ public byte[] sign(byte[] toSign) { Storage clientCredentialsStorage = createStorage(defaultCredentials, null); assertThat(signV4(clientCredentialsStorage, SignUrlOption.signWith(signer)).getHost()) .isEqualTo("storage.custom.example.com"); + + Storage failingCredentialsStorage = createStorage(new FailingUniverseCredentials(), null); + StorageException ioThrown = assertUnauthenticated(() -> signV4(failingCredentialsStorage)); + assertThat(ioThrown) + .hasMessageThat() + .contains(EndpointContext.UNABLE_TO_RETRIEVE_CREDENTIALS_ERROR_MESSAGE); + assertThat(ioThrown.getCause()).hasCauseThat().isInstanceOf(IOException.class); } @Test @@ -168,6 +188,17 @@ public void validatesCredentialsUniverseDomainInPostPolicyV4() { assertThat(thrown) .hasMessageThat() .contains(expectedMismatch(CUSTOM_UNIVERSE, Credentials.GOOGLE_DEFAULT_UNIVERSE)); + assertUnauthenticated( + () -> + customStorage.generateSignedPostPolicyV4( + BLOB_INFO, + 15, + TimeUnit.MINUTES, + fields, + conditions, + signWithDefault, + PostPolicyV4Option.withBucketBoundHostname( + "cdn.custom.example.com", UriScheme.HTTPS))); } private static URL signV4(Storage storage, SignUrlOption... options) { @@ -216,6 +247,47 @@ private static ServiceAccountCredentials createServiceAccountCredentials(String .build(); } + private static final class FailingUniverseCredentials extends Credentials + implements ServiceAccountSigner { + @Override + public String getAuthenticationType() { + return "OAuth2"; + } + + @Override + public String getUniverseDomain() throws IOException { + throw new IOException("failed to retrieve universe domain"); + } + + @Override + public String getAccount() { + return "signer@test-proj.iam.gserviceaccount.com"; + } + + @Override + public byte[] sign(byte[] toSign) { + return new byte[0]; + } + + @Override + public Map> getRequestMetadata(@Nullable URI uri) { + return Collections.emptyMap(); + } + + @Override + public boolean hasRequestMetadata() { + return false; + } + + @Override + public boolean hasRequestMetadataOnly() { + return true; + } + + @Override + public void refresh() {} + } + private static PrivateKey generateRsaPrivateKey() { try { KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA"); From 335c50235be076c55ac9717dbfda1e352dc9c4b8 Mon Sep 17 00:00:00 2001 From: Nidhi Nandwani Date: Thu, 3 Dec 2026 11:00:22 +0000 Subject: [PATCH 4/4] test(storage): cover custom host with default universe domain in signUrl StorageSigningUniverseDomainTest verifies that StorageOptions configured with a custom host and an explicit googleapis.com universe domain produce a V4 signed URL that uses that host in both the URL and the signed payload. Existing test cases remain unchanged. [Generated-by: AI] --- .../StorageSigningUniverseDomainTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageSigningUniverseDomainTest.java b/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageSigningUniverseDomainTest.java index c4f9c97ecafa..485c3f6bbb45 100644 --- a/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageSigningUniverseDomainTest.java +++ b/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageSigningUniverseDomainTest.java @@ -77,6 +77,26 @@ public void tearDown() { @Test public void formatsSignedUrlsAndPostPolicyV4ForConfiguredUniverseDomain() { + ServiceAccountCredentials defaultSigner = + createServiceAccountCredentials(Credentials.GOOGLE_DEFAULT_UNIVERSE); + Storage customHostStorage = + StorageOptions.http() + .setProjectId("test-proj") + .setCredentials(defaultSigner) + .setClock(FIXED_CLOCK) + .setHost("https://custom.example.com") + .setUniverseDomain(Credentials.GOOGLE_DEFAULT_UNIVERSE) + .build() + .getService(); + URL customHostUrl = signV4(customHostStorage); + assertThat(customHostUrl.getHost()).isEqualTo("custom.example.com"); + assertThat(customHostUrl.getQuery()) + .isEqualTo( + signV4( + createStorage(defaultSigner, null), + SignUrlOption.withHostName("https://custom.example.com")) + .getQuery()); + setEnvUniverse(CUSTOM_UNIVERSE); ServiceAccountCredentials customSigner = createServiceAccountCredentials(CUSTOM_UNIVERSE); Storage storage = createStorage(customSigner, null);