fix(Snowflake Node): Fix key-pair credentials (#16635)

Co-authored-by: Elias Meire <elias@meire.dev>
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
This commit is contained in:
Michael Kret
2025-06-25 21:23:01 +03:00
committed by GitHub
parent 7c33292483
commit 8e6de34bc3
3 changed files with 72 additions and 7 deletions

View File

@@ -1,5 +1,9 @@
import crypto from 'crypto';
import { getConnectionOptions } from '../GenericFunctions';
jest.mock('crypto');
describe('getConnectionOptions', () => {
const commonOptions = {
account: 'test-account',
@@ -29,12 +33,43 @@ describe('getConnectionOptions', () => {
it('with private key for keyPair authentication', () => {
const result = getConnectionOptions({
...commonOptions,
username: 'test-username',
authentication: 'keyPair',
privateKey: 'test-private-key',
});
expect(result).toEqual({
...commonOptions,
username: 'test-username',
authenticator: 'SNOWFLAKE_JWT',
privateKey: 'test-private-key',
});
});
it('with private key for keyPair authentication and passphrase', () => {
const createPrivateKeySpy = jest.spyOn(crypto, 'createPrivateKey').mockImplementation(
() =>
({
export: () => 'test-private-key',
}) as unknown as crypto.KeyObject,
);
const result = getConnectionOptions({
...commonOptions,
username: 'test-username',
authentication: 'keyPair',
privateKey: 'encrypted-private-key',
passphrase: 'test-passphrase',
});
expect(createPrivateKeySpy).toHaveBeenCalledWith({
key: 'encrypted-private-key',
format: 'pem',
passphrase: 'test-passphrase',
});
expect(result).toEqual({
...commonOptions,
username: 'test-username',
authenticator: 'SNOWFLAKE_JWT',
privateKey: 'test-private-key',
});