From 3427b25ea680abd66232326696eeb29d344d0d4f Mon Sep 17 00:00:00 2001 From: Dawid Heyman Date: Mon, 5 Aug 2024 12:57:02 +0200 Subject: [PATCH] SNOW-1569214: Fix regex for account name validation (#879) --- lib/util.js | 2 +- .../unit/connection/connection_config_test.js | 34 ++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/util.js b/lib/util.js index 284eb796b..29befaa9d 100644 --- a/lib/util.js +++ b/lib/util.js @@ -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); }; diff --git a/test/unit/connection/connection_config_test.js b/test/unit/connection/connection_config_test.js index 2973a0bbd..8e75ef23a 100644 --- a/test/unit/connection/connection_config_test.js +++ b/test/unit/connection/connection_config_test.js @@ -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: @@ -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: @@ -1603,4 +1636,3 @@ describe('ConnectionConfig: basic', function () { }); }); }); -