Skip to content

Commit

Permalink
SNOW-1569214: Fix regex for account name validation (#879)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dheyman authored Aug 5, 2024
1 parent 9a3f930 commit 3427b25
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ exports.getCircularReplacer = function () {
* @returns {boolean}
*/
exports.isCorrectSubdomain = function (value) {
const subdomainRegex = RegExp(/^\w([\w.-]+\w|)$/i);
const subdomainRegex = RegExp(/^\w+([.-]\w+)*$/i);
return subdomainRegex.test(value);
};

Expand Down
34 changes: 33 additions & 1 deletion test/unit/connection/connection_config_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,22 @@ describe('ConnectionConfig: basic', function () {
account: 'a',
}
},
{
name: 'two letter account',
input:
{
username: 'username',
password: 'password',
account: 'pm'
},
options:
{
accessUrl: 'https://pm.snowflakecomputing.com',
username: 'username',
password: 'password',
account: 'pm'
}
},
{
name: 'only one letter account and subdomain',
input:
Expand All @@ -1290,6 +1306,23 @@ describe('ConnectionConfig: basic', function () {
region: 'b'
}
},
{
name: 'two letter account and subdomain',
input:
{
username: 'username',
password: 'password',
account: 'pm.ab'
},
options:
{
accessUrl: 'https://pm.ab.snowflakecomputing.com',
username: 'username',
password: 'password',
account: 'pm',
region: 'ab'
}
},
{
name: 'account with [-] in the middle',
input:
Expand Down Expand Up @@ -1603,4 +1636,3 @@ describe('ConnectionConfig: basic', function () {
});
});
});

0 comments on commit 3427b25

Please sign in to comment.