Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-944710: Add account validation #692

Merged
merged 8 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/connection/connection_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function consolidateHostAndAccount(options)
if (Util.exists(options.account))
{
Errors.checkArgumentValid(Util.isString(options.account), ErrorCodes.ERR_CONN_CREATE_INVALID_ACCOUNT);
Errors.checkArgumentValid(Util.isCorrectAccount(options.account), ErrorCodes.ERR_CONN_CREATE_INVALID_ACCOUNT_REGEX);
options.host = Util.construct_hostname(options.region, options.account);
dotPos = options.account.indexOf('.');
realAccount = options.account;
Expand Down
3 changes: 2 additions & 1 deletion lib/constants/error_messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ exports[404038] = 'Invalid gcsUseDownscopedCredential. The specified value must
exports[404039] = 'Invalid forceStageBindError. The specified value must be a number.';
exports[404040] = 'Invalid browser timeout value. The specified value must be a positive number.';
exports[404041] = 'Invalid disablQueryContextCache. The specified value must be a boolean.';
exports[404042] = 'Invalid includeRetryReason. The specified value must be a boolean.'
exports[404042] = 'Invalid includeRetryReason. The specified value must be a boolean.';
exports[404043] = 'Invalid clientConfigFile value. The specified value must be a string.';
exports[404044] = 'Invalid retryTimeout value. The specified value must be a number.';
exports[404045] = 'Invalid account. The specified value must be a valid subdomain string.';

// 405001
exports[405001] = 'Invalid callback. The specified value must be a function.';
Expand Down
1 change: 1 addition & 0 deletions lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ codes.ERR_CONN_CREATE_INVALID_DISABLED_QUERY_CONTEXT_CACHE = 404041
codes.ERR_CONN_CREATE_INVALID_INCLUDE_RETRY_REASON =404042
codes.ERR_CONN_CREATE_INVALID_CLIENT_CONFIG_FILE = 404043;
codes.ERR_CONN_CREATE_INVALID_RETRY_TIMEOUT = 404044;
codes.ERR_CONN_CREATE_INVALID_ACCOUNT_REGEX = 404045;

// 405001
codes.ERR_CONN_CONNECT_INVALID_CALLBACK = 405001;
Expand Down
11 changes: 11 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,4 +627,15 @@ exports.getCircularReplacer = function() {
ancestors.push(value);
return value;
};
};

/**
* Returns if the provided string is a valid account name.
* @param account
* @returns {boolean}
*/
exports.isCorrectAccount = function (account) {
const accountRegex = RegExp(/^\w[\w.-]+\w$/i);

return accountRegex.test(account);
};
50 changes: 50 additions & 0 deletions test/unit/connection/connection_config_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,56 @@ describe('ConnectionConfig: basic', function ()
},
errorCode: ErrorCodes.ERR_CONN_CREATE_INVALID_ACCOUNT
},
{
name: 'account with invalid character',
sfc-gh-dprzybysz marked this conversation as resolved.
Show resolved Hide resolved
options:
{
username: 'username',
password: 'password',
account: 'account?'
},
errorCode: ErrorCodes.ERR_CONN_CREATE_INVALID_ACCOUNT_REGEX
},
{
name: 'account starting with -',
options:
{
username: 'username',
password: 'password',
account: '-account'
},
errorCode: ErrorCodes.ERR_CONN_CREATE_INVALID_ACCOUNT_REGEX
},
{
name: 'account ending with -',
options:
{
username: 'username',
password: 'password',
account: 'account-'
},
errorCode: ErrorCodes.ERR_CONN_CREATE_INVALID_ACCOUNT_REGEX
},
{
name: 'account starting and ending with -',
options:
{
username: 'username',
password: 'password',
account: '-account-'
},
errorCode: ErrorCodes.ERR_CONN_CREATE_INVALID_ACCOUNT_REGEX
},
{
name: 'account with invalid character in the middle',
options:
{
username: 'username',
password: 'password',
account: 'acco?unt'
},
errorCode: ErrorCodes.ERR_CONN_CREATE_INVALID_ACCOUNT_REGEX
},
{
name: 'invalid warehouse',
options:
Expand Down
Loading