first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
import crypto from 'crypto';
|
||||
|
||||
import { getConnectionOptions } from '../GenericFunctions';
|
||||
|
||||
jest.mock('crypto');
|
||||
|
||||
describe('getConnectionOptions', () => {
|
||||
const commonOptions = {
|
||||
account: 'test-account',
|
||||
database: 'test-database',
|
||||
schema: 'test-schema',
|
||||
warehouse: 'test-warehouse',
|
||||
role: 'test-role',
|
||||
clientSessionKeepAlive: true,
|
||||
};
|
||||
|
||||
describe('should return connection options', () => {
|
||||
it('with username and password for password authentication', () => {
|
||||
const result = getConnectionOptions({
|
||||
...commonOptions,
|
||||
authentication: 'password',
|
||||
username: 'test-username',
|
||||
password: 'test-password',
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
...commonOptions,
|
||||
username: 'test-username',
|
||||
password: 'test-password',
|
||||
});
|
||||
});
|
||||
|
||||
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',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user