diff --git a/lib/util.js b/lib/util.js index e8bc492ea..851871755 100644 --- a/lib/util.js +++ b/lib/util.js @@ -510,10 +510,12 @@ exports.userAgent = userAgent; * @returns {string} host name */ exports.constructHostname = function (region, account) { - let host; if (region === 'us-west-2') { - region = ''; - } else if (region != null) { + region = null; + } + + let host; + 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 4f0cf2b45..619874f63 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 = [