diff --git a/package.json b/package.json index a4f2fe49b..698b8af09 100644 --- a/package.json +++ b/package.json @@ -95,6 +95,7 @@ "@grpc/grpc-js": "^1.0.3", "@grpc/proto-loader": "^0.7.0", "@types/async-retry": "^1.4.3", + "@types/duplexify": "^3.6.4", "@types/mime": "^3.0.0", "@types/mocha": "^9.1.1", "@types/mockery": "^1.4.29", diff --git a/src/storage.ts b/src/storage.ts index a7027bc83..681145d3d 100644 --- a/src/storage.ts +++ b/src/storage.ts @@ -715,7 +715,7 @@ export class Storage extends Service { customEndpoint = true; } - if (options.apiEndpoint) { + if (options.apiEndpoint && options.apiEndpoint !== apiEndpoint) { apiEndpoint = Storage.sanitizeEndpoint(options.apiEndpoint); customEndpoint = true; } diff --git a/test/index.ts b/test/index.ts index 72637a466..34104d743 100644 --- a/test/index.ts +++ b/test/index.ts @@ -174,6 +174,30 @@ describe('Storage', () => { assert.strictEqual(calledWith.apiEndpoint, `${apiEndpoint}`); }); + it('should not set `customEndpoint` if `apiEndpoint` matches default', () => { + const apiEndpoint = 'https://storage.googleapis.com'; + const storage = new Storage({ + apiEndpoint, + }); + + const calledWith = storage.calledWith_[0]; + assert.strictEqual(calledWith.apiEndpoint, apiEndpoint); + assert.strictEqual(calledWith.customEndpoint, false); + }); + + it('should not set `customEndpoint` if `apiEndpoint` matches default (w/ universe domain)', () => { + const universeDomain = 'my.universe'; + const apiEndpoint = `https://storage.${universeDomain}`; + const storage = new Storage({ + apiEndpoint, + universeDomain, + }); + + const calledWith = storage.calledWith_[0]; + assert.strictEqual(calledWith.apiEndpoint, apiEndpoint); + assert.strictEqual(calledWith.customEndpoint, false); + }); + it('should propagate the useAuthWithCustomEndpoint option', () => { const useAuthWithCustomEndpoint = true; const apiEndpoint = 'https://some.fake.endpoint';