Repository navigation
fix(storage): resolve universe domain from options and env - #10001
kalragauri merged 12 commits into
Conversation
| clientOptions, | ||
| }; | ||
| if (normalizedConfigured) { | ||
| authOptions.universeDomain = normalizedConfigured; |
There was a problem hiding this comment.
Setting authOptions.universeDomain here makes GoogleAuth copy the configured universe into this.clientOptions.universeDomain, which then overwrites client.universeDomain in fromJSON, fromStreamAsync, and fromAPIKey. For non-JSON clients (apiKey, .pem/.p12) where jsonContent is null, assertUniverseDomain ends up comparing the configured universe against itself.
There was a problem hiding this comment.
Fixed. buildGoogleAuthOptions() now strips authOptions.universeDomain, with tests added for apiKey and .pem mismatches.
| this.customEndpoint = true; | ||
| if (options.apiEndpoint) { | ||
| apiEndpoint = sanitizeEndpoint(options.apiEndpoint); | ||
| if (isCustomEndpoint(apiEndpoint, universe)) { |
There was a problem hiding this comment.
isCustomEndpoint() treats apiEndpoint: 'storage.googleapis.com' and 'https://storage.googleapis.com/' as non-custom, flipping storage.customEndpoint to false and changing the url returned by generateSignedPostPolicyV4(). That behavior change is unrelated to universe domain resolution. Consider using isCustomEndpoint() only for hasCustomApiEndpoint here, or moving the customEndpoint change to a separate PR.
There was a problem hiding this comment.
Fixed. restored this.customEndpoint behavior, scoped isCustomEndpoint() to hasCustomApiEndpoint, and reverted the test/file.ts changes.
| ); | ||
| }); | ||
|
|
||
| it('should compare custom endpoints after sanitizing', () => { |
There was a problem hiding this comment.
This test does not cover the protocol, pathname, search, and hash conditions or the catch branch of isCustomEndpoint(), so each could be removed without a failure.
There was a problem hiding this comment.
Added coverage for protocol, username, password, pathname, search, hash and the catch branch.
| ); | ||
| }); | ||
|
|
||
| it('should allow explicit DEFAULT_UNIVERSE via universeDomain to override GOOGLE_CLOUD_UNIVERSE_DOMAIN', async () => { |
There was a problem hiding this comment.
No test combines a non-default GOOGLE_CLOUD_UNIVERSE_DOMAIN with an explicit apiEndpoint: 'https://storage.googleapis.com'. Consider adding a test verifying that default-universe credentials are rejected unless universeDomain: 'googleapis.com' is also passed.
There was a problem hiding this comment.
Added tests verifying default-universe credentials are rejected unless universeDomain: 'googleapis.com' is explicitly passed.
|
|
Updated. Restored pre-PR |
Summary
@google-cloud/storageresolves the client universe domain fromoptions.universeDomain, thenGOOGLE_CLOUD_UNIVERSE_DOMAIN, and defaults to'googleapis.com', keepingapiEndpointindependent of the universe domain, omitting top-leveluniverseDomainfromGoogleAuthso credential-derivedclient.universeDomainvalues are preserved (includingapiKeyand.pem/.p12clients), and validating conflictingclientOptionsuniverse settings during construction when noauthClientis provided.Unchanged Behavior
Default
'googleapis.com'configuration withoutGOOGLE_CLOUD_UNIVERSE_DOMAIN, pre-PRstorage.customEndpointandgenerateSignedPostPolicyV4()behavior, emulator (STORAGE_EMULATOR_HOST) and GCE Compute flows without conflictingclientOptionsuniverse keys, and unauthenticated custom-endpoint upload paths remain unchanged. Passing conflictingclientOptions.universeDomainorclientOptions.universe_domainwithout an explicitauthClientnow throws atnew Storage()construction time (including on Compute).Tests Updated
Updated unit tests in
test/index.ts,test/storage-transport.ts,test/resumable-upload.ts,test/file.ts, andtest/util.ts.