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-728173: Remove new line for verifier the private key end #566

Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 6 additions & 4 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,13 @@ exports.isNumber = function (value)
*
* @returns {Boolean}
*/
exports.isPrivateKey = function (value)
{
exports.isPrivateKey = function (value) {
const trimmedValue = value.trim();
// The private key is expected to be decrypted when set in the connection string
return (value.startsWith("-----BEGIN PRIVATE KEY-----") &&
value.endsWith("\n-----END PRIVATE KEY-----\n"));
// secret scanner complains about first check since it looks like private key, but it's only check
// pragma: allowlist nextline secret
return (trimmedValue.startsWith('-----BEGIN PRIVATE KEY-----') &&
trimmedValue.endsWith('\n-----END PRIVATE KEY-----'));
};

/**
Expand Down
44 changes: 44 additions & 0 deletions test/unit/util_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,4 +589,48 @@ describe('Util', function ()
err.response, testCase.retry403), testCase.isRetryable)
}
});

describe('isPrivateKey', () => {
[
// pragma: allowlist nextline secret
{ name: 'trimmed already key', key: '-----BEGIN PRIVATE KEY-----\ntest\n-----END PRIVATE KEY-----' },
{
name: 'key with whitespaces at the beginning',
// pragma: allowlist nextline secret
key: ' -----BEGIN PRIVATE KEY-----\ntest\n-----END PRIVATE KEY-----'
},
{
name: 'key with whitespaces at the end',
// pragma: allowlist nextline secret
key: '-----BEGIN PRIVATE KEY-----\ntest\n-----END PRIVATE KEY-----\n\n\n'
},
].forEach(({ name, key }) => {
it(`${name} is valid`, () => {
assert.ok(Util.isPrivateKey(key));
});
});

[
{ name: 'key without beginning and end', key: 'test' },
{ name: 'key with missing beginning', key: 'test\n-----END PRIVATE KEY-----' },
{
name: 'key with missing ending',
// pragma: allowlist nextline secret
key: ' -----BEGIN PRIVATE KEY-----\ntest'
},
{
name: 'key with invalid beginning',
key: '-----BEGIN PUBLIC KEY-----\ntest\n-----END PRIVATE KEY-----\n\n\n'
},
{
name: 'key with invalid end',
// pragma: allowlist nextline secret
key: '-----BEGIN PRIVATE KEY-----\ntest\n-----END PUBLIC KEY-----\n\n\n'
},
].forEach(({ name, key }) => {
it(`${name} is invalid`, () => {
assert.ok(!Util.isPrivateKey(key));
});
});
});
});
Loading