Skip to content

Commit 9b173f5

Browse files
committed
Fix Util.constructHostname bug with us-west-2
1 parent a2d4814 commit 9b173f5

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

lib/util.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,12 @@ exports.userAgent = userAgent;
511511
* @returns {string} host name
512512
*/
513513
exports.constructHostname = function (region, account) {
514+
if (region === "us-west-2") {
515+
region = null;
516+
}
517+
514518
let host;
515-
if (region === 'us-west-2') {
516-
region = '';
517-
} else if (region != null) {
519+
if (region != null) {
518520
if (account.indexOf('.') > 0) {
519521
account = account.substring(0, account.indexOf('.'));
520522
}

test/unit/util_test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,43 @@ describe('Util', function () {
727727
}
728728
});
729729

730+
describe("Util.constructHostname", () => {
731+
it("works with undefined region", () => {
732+
assert.strictEqual(
733+
Util.constructHostname(undefined, "abc123"),
734+
"abc123.snowflakecomputing.com"
735+
);
736+
});
737+
738+
it("adds region to the account", () => {
739+
assert.strictEqual(
740+
Util.constructHostname("us-west-1", "abc123"),
741+
"abc123.us-west-1.snowflakecomputing.com"
742+
);
743+
});
744+
745+
it("Skips region when it is us-west-2", () => {
746+
assert.strictEqual(
747+
Util.constructHostname("us-west-2", "abc123"),
748+
"abc123.snowflakecomputing.com"
749+
);
750+
});
751+
752+
it("Ignores the account region when a different region is specified", () => {
753+
assert.strictEqual(
754+
Util.constructHostname("us-east-2", "abc123.us-east-1"),
755+
"abc123.us-east-2.snowflakecomputing.com"
756+
);
757+
});
758+
759+
it("Uses account region when there is no other region specified", () => {
760+
assert.strictEqual(
761+
Util.constructHostname(undefined, "abc123.us-east-1"),
762+
"abc123.us-east-1.snowflakecomputing.com"
763+
);
764+
});
765+
});
766+
730767
describe('Okta Authentication Retry Condition', () => {
731768
const testCases =
732769
[

0 commit comments

Comments
 (0)