diff --git a/lib/util.js b/lib/util.js index 1c7865629..fe193f446 100644 --- a/lib/util.js +++ b/lib/util.js @@ -511,10 +511,12 @@ exports.userAgent = userAgent; * @returns {string} host name */ exports.constructHostname = function (region, account) { + if (region === "us-west-2") { + region = null; + } + let host; - if (region === 'us-west-2') { - region = ''; - } else if (region != null) { + if (region != null) { if (account.indexOf('.') > 0) { account = account.substring(0, account.indexOf('.')); } diff --git a/test/unit/util_test.js b/test/unit/util_test.js index a3a5e7953..fb110d3ac 100644 --- a/test/unit/util_test.js +++ b/test/unit/util_test.js @@ -727,6 +727,43 @@ describe('Util', function () { } }); + describe("Util.constructHostname", () => { + it("works with undefined region", () => { + assert.strictEqual( + Util.constructHostname(undefined, "abc123"), + "abc123.snowflakecomputing.com" + ); + }); + + it("adds region to the account", () => { + assert.strictEqual( + Util.constructHostname("us-west-1", "abc123"), + "abc123.us-west-1.snowflakecomputing.com" + ); + }); + + it("Skips region when it is us-west-2", () => { + assert.strictEqual( + Util.constructHostname("us-west-2", "abc123"), + "abc123.snowflakecomputing.com" + ); + }); + + it("Ignores the account region when a different region is specified", () => { + assert.strictEqual( + Util.constructHostname("us-east-2", "abc123.us-east-1"), + "abc123.us-east-2.snowflakecomputing.com" + ); + }); + + it("Uses account region when there is no other region specified", () => { + assert.strictEqual( + Util.constructHostname(undefined, "abc123.us-east-1"), + "abc123.us-east-1.snowflakecomputing.com" + ); + }); + }); + describe('Okta Authentication Retry Condition', () => { const testCases = [