Skip to content

Commit

Permalink
Fix Util.constructHostname bug with us-west-2
Browse files Browse the repository at this point in the history
  • Loading branch information
jdorn authored and sfc-gh-pmotacki committed Apr 30, 2024
1 parent 773bd89 commit 7e6baa7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('.'));
}
Expand Down
37 changes: 37 additions & 0 deletions test/unit/util_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
[
Expand Down

0 comments on commit 7e6baa7

Please sign in to comment.