From 4440197c092010be36ce0a23e41bafb05a9216c9 Mon Sep 17 00:00:00 2001 From: sfc-gh-ext-simba-ll Date: Thu, 27 Jul 2023 14:20:17 -0700 Subject: [PATCH 1/5] Add manual test script for connectAsync --- EnableConnectAsyncTests.py | 15 +++++++++++++++ README.md | 22 ++++++++++++++++++++-- package.json | 3 ++- 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 EnableConnectAsyncTests.py diff --git a/EnableConnectAsyncTests.py b/EnableConnectAsyncTests.py new file mode 100644 index 000000000..fd4c21d91 --- /dev/null +++ b/EnableConnectAsyncTests.py @@ -0,0 +1,15 @@ +import os +f = open("test/integration/testConnection.js", "r") +data = f.read() +data = data.replace("describe(", "describe.skip(") +data = data.replace("describe.skip('Connection test - external browser'", "describe('Connection test - external browser'") +data = data.replace("describe.skip('Connection test - oauth'", "describe('Connection test - oauth'") +data = data.replace("describe.skip('Connection test - okta'", "describe('Connection test - okta'") +data = data.replace("const connOption = require('./connectionOptions');", "const connOption = require('../integration/connectionOptions');") +data = data.replace("const testUtil = require('./testUtil');", "const testUtil = require('../integration/testUtil');") + +if not os.path.exists('test/manual'): + os.makedirs('test/manual') + +f = open("test/manual/testConnection.js", "w") +f.write(data) \ No newline at end of file diff --git a/README.md b/README.md index 4cbada655..8209f682a 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ npm test ``` or ``` -npm test:unit +npm run test:unit ``` To run single test file use `test:single` script, e.g. run tests in `test/unit/snowflake_test.js` only: @@ -80,7 +80,25 @@ npm run test:single -- test/unit/snowflake_test.js Run integration tests: ``` -npm test:integration +npm run test:integration +``` + +Manual test +---------------------------------------------------------------------- + +Specify env variables: + +``` +export SNOWFLAKE_TEST_OKTA_USER= +export SNOWFLAKE_TEST_OKTA_PASS= +export SNOWFLAKE_TEST_OKTA_AUTH= +export SNOWFLAKE_TEST_OAUTH_TOKEN= +export SNOWFLAKE_TEST_BROWSER_USER= +``` + +Run manual connection test for different authenticators +``` +npm run test:manual ``` Getting the code coverage diff --git a/package.json b/package.json index 74dfe75c4..73be505d4 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,8 @@ "test:ci": "mocha -timeout 180000 --recursive --full-trace test/**/*.js", "test:ci:coverage": "nyc npm run test:ci", "test:ci:withSystemTests": "mocha -timeout 180000 --recursive --full-trace test/**/*.js system_test/*.js", - "test:ci:withSystemTests:coverage": "nyc npm run test:ci:withSystemTests" + "test:ci:withSystemTests:coverage": "nyc npm run test:ci:withSystemTests", + "test:manual": "python EnableConnectAsyncTests.py && mocha -timeout 180000 --full-trace --full-trace test/manual/testConnection.js" }, "author": { "name": "Snowflake Computing, Inc.", From 86af289a1b11020fd5e2850955cdef638a704598 Mon Sep 17 00:00:00 2001 From: sfc-gh-ext-simba-ll Date: Fri, 28 Jul 2023 09:47:46 -0700 Subject: [PATCH 2/5] Use env var instead of python script --- EnableConnectAsyncTests.py | 15 - README.md | 1 + package.json | 2 +- test/integration/testConnection.js | 2003 +++++++++++++++------------- 4 files changed, 1078 insertions(+), 943 deletions(-) delete mode 100644 EnableConnectAsyncTests.py diff --git a/EnableConnectAsyncTests.py b/EnableConnectAsyncTests.py deleted file mode 100644 index fd4c21d91..000000000 --- a/EnableConnectAsyncTests.py +++ /dev/null @@ -1,15 +0,0 @@ -import os -f = open("test/integration/testConnection.js", "r") -data = f.read() -data = data.replace("describe(", "describe.skip(") -data = data.replace("describe.skip('Connection test - external browser'", "describe('Connection test - external browser'") -data = data.replace("describe.skip('Connection test - oauth'", "describe('Connection test - oauth'") -data = data.replace("describe.skip('Connection test - okta'", "describe('Connection test - okta'") -data = data.replace("const connOption = require('./connectionOptions');", "const connOption = require('../integration/connectionOptions');") -data = data.replace("const testUtil = require('./testUtil');", "const testUtil = require('../integration/testUtil');") - -if not os.path.exists('test/manual'): - os.makedirs('test/manual') - -f = open("test/manual/testConnection.js", "w") -f.write(data) \ No newline at end of file diff --git a/README.md b/README.md index 8209f682a..d51db11e5 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ Manual test Specify env variables: ``` +export RUN_MANUAL_TESTS_ONLY=true export SNOWFLAKE_TEST_OKTA_USER= export SNOWFLAKE_TEST_OKTA_PASS= export SNOWFLAKE_TEST_OKTA_AUTH= diff --git a/package.json b/package.json index 73be505d4..5bab9a3fb 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "test:ci:coverage": "nyc npm run test:ci", "test:ci:withSystemTests": "mocha -timeout 180000 --recursive --full-trace test/**/*.js system_test/*.js", "test:ci:withSystemTests:coverage": "nyc npm run test:ci:withSystemTests", - "test:manual": "python EnableConnectAsyncTests.py && mocha -timeout 180000 --full-trace --full-trace test/manual/testConnection.js" + "test:manual": "mocha -timeout 180000 --full-trace --full-trace test/integration/testConnection.js" }, "author": { "name": "Snowflake Computing, Inc.", diff --git a/test/integration/testConnection.js b/test/integration/testConnection.js index 8b3220382..67bcaed29 100644 --- a/test/integration/testConnection.js +++ b/test/integration/testConnection.js @@ -10,1044 +10,1179 @@ const Util = require('./../../lib/util'); const Core = require('./../../lib/core'); const stderr = require("test-console").stderr; -describe('Connection test', function () -{ - it('return tokens in qaMode', function () - { - const coreInst = Core({ - qaMode: true, - httpClientClass: require('./../../lib/http/node'), - loggerClass: require('./../../lib/logger/node'), - client: - { - version: Util.driverVersion, - environment: process.versions +if (process.env.RUN_MANUAL_TESTS_ONLY == 'true') { + describe.only('Run manual tests', function () { + describe('Connection test - external browser', function () { + it('Simple Connect', function (done) { + const connection = snowflake.createConnection(connOption.externalBrowser); + + connection.connectAsync(function (err, connection) { + try { + assert.ok(connection.isUp(), 'not active'); + testUtil.destroyConnection(connection, function (err, r) { + try { + assert.ok(!connection.isUp(), 'not active'); + done(); + } catch (err) { + done(err); + } + }); + } catch (err) { + done(err); } + }); }); - const connection = coreInst.createConnection(connOption.valid); - assert.deepEqual(connection.getTokens(), { - masterToken: undefined, - masterTokenExpirationTime: undefined, - sessionToken: undefined, - sessionTokenExpirationTime: undefined - }); - } - ); - it('does not return tokens when not in qaMode', function () - { - const connection = snowflake.createConnection(connOption.valid); - assert.deepEqual(connection.getTokens(), {}); - } - ) - ; - it('Simple Connect', async function () { - const connection = snowflake.createConnection(connOption.valid); - - await testUtil.connectAsync(connection); - assert.ok(connection.isUp(), "not active"); - await testUtil.destroyConnectionAsync(connection); - assert.ok(!connection.isUp(), "still active"); - }); + it('Connect - external browser timeout', function (done) { + const connection = snowflake.createConnection(connOption.externalBrowserWithShortTimeout); - it('Wrong Username', function (done) - { - var connection = snowflake.createConnection(connOption.wrongUserName); - connection.connect(function (err) - { - assert.ok(err, 'Username is an empty string'); - assert.equal('Incorrect username or password was specified.', err["message"]); - done(); - }); - }); + connection.connectAsync(function (err) { + try { + const browserActionTimeout = connOption.externalBrowserWithShortTimeout.browserActionTimeout; + assert.ok(err, `Browser action timed out after ${browserActionTimeout} ms.`); + done(); + } catch (err) { + done(err); + } + }); + }); - it('Wrong Password', function (done) - { - var connection = snowflake.createConnection(connOption.wrongPwd); - connection.connect(function (err) - { - assert.ok(err, 'Password is an empty string'); - assert.equal('Incorrect username or password was specified.', err["message"]); - done(); + it('Mismatched Username', function (done) { + var connection = snowflake.createConnection(connOption.externalBrowserMismatchUser); + connection.connectAsync(function (err) { + try { + assert.ok(err, 'Logged in with different user than one on connection string'); + assert.equal('The user you were trying to authenticate as differs from the user currently logged in at the IDP.', err['message']); + done(); + } catch (err) { + done(err); + } + }); + }); }); - }); - it('Multiple Client', function (done) - { - const totalConnections = 10; - const connections = []; - for (let i = 0; i < totalConnections; i++) + describe('Connection test - oauth', function () { - connections.push(snowflake.createConnection(connOption.valid)); - } - let completedConnection = 0; - for (let i = 0; i < totalConnections; i++) - { - connections[i].connect(function (err, conn) + it('Simple Connect', function (done) { - testUtil.checkError(err); - conn.execute({ - sqlText: 'select 1', - complete: function (err) + var connection = snowflake.createConnection(connOption.oauth); + + async.series([ + function (callback) { - testUtil.checkError(err); - testUtil.destroyConnection(conn, function () + connection.connect(function (err) { + done(err); + assert.ok(!err, JSON.stringify(err)); + callback(); }); - completedConnection++; + }, + function (callback) + { + assert.ok(connection.isUp(), "not active"); + callback(); + }, + function (callback) + { + connection.destroy(function (err) + { + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) + { + assert.ok(!connection.isUp(), "still active"); + callback(); + }, + ], + ); + }); + + it('Mismatched Username', function (done) + { + var connection = snowflake.createConnection(connOption.oauthMismatchUser); + connection.connect(function (err) + { + try + { + assert.ok(err, 'Logged in with different user than one on connection string'); + assert.equal('The user you were trying to authenticate as differs from the user tied to the access token.', err["message"]); + done(); } - }); + catch (err) + { + done(err); + } + }) }); - } - const sleepMs = 500; - const maxSleep = 60000; - let sleepFromStartChecking = 0; + }); - const timeout = () => setTimeout(() => + describe('Connection test - okta', function () { - sleepFromStartChecking += sleepMs; - if (completedConnection === totalConnections) + it('Simple Connect', function (done) { - done(); - } - else if (sleepFromStartChecking <= maxSleep) + var connection = snowflake.createConnection(connOption.okta); + + async.series([ + function (callback) + { + connection.connectAsync(function (err) + { + done(err); + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) + { + assert.ok(connection.isUp(), "not active"); + callback(); + }, + function (callback) + { + connection.destroy(function (err) + { + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) + { + assert.ok(!connection.isUp(), "still active"); + callback(); + }, + ], + ); + }); + }); + }) +} else { + describe('Connection test', function () + { + it('return tokens in qaMode', function () { - timeout(); + const coreInst = Core({ + qaMode: true, + httpClientClass: require('./../../lib/http/node'), + loggerClass: require('./../../lib/logger/node'), + client: + { + version: Util.driverVersion, + environment: process.versions + } + }); + const connection = coreInst.createConnection(connOption.valid); + assert.deepEqual(connection.getTokens(), { + masterToken: undefined, + masterTokenExpirationTime: undefined, + sessionToken: undefined, + sessionTokenExpirationTime: undefined + }); } - else + ); + + it('does not return tokens when not in qaMode', function () { - done(`Max after ${maxSleep} it's expected to complete ${totalConnections} but completed ${completedConnection}`) + const connection = snowflake.createConnection(connOption.valid); + assert.deepEqual(connection.getTokens(), {}); } - }, sleepMs); + ) + ; + it('Simple Connect', async function () { + const connection = snowflake.createConnection(connOption.valid); - timeout(); - }); -}); + await testUtil.connectAsync(connection); + assert.ok(connection.isUp(), "not active"); + await testUtil.destroyConnectionAsync(connection); + assert.ok(!connection.isUp(), "still active"); + }); -// Skipped - requires manual interaction to enter credentials on browser -describe.skip('Connection test - external browser', function () { - this.timeout(10000); + it('Wrong Username', function (done) + { + var connection = snowflake.createConnection(connOption.wrongUserName); + connection.connect(function (err) + { + assert.ok(err, 'Username is an empty string'); + assert.equal('Incorrect username or password was specified.', err["message"]); + done(); + }); + }); - it('Simple Connect', function (done) { - const connection = snowflake.createConnection(connOption.externalBrowser); + it('Wrong Password', function (done) + { + var connection = snowflake.createConnection(connOption.wrongPwd); + connection.connect(function (err) + { + assert.ok(err, 'Password is an empty string'); + assert.equal('Incorrect username or password was specified.', err["message"]); + done(); + }); + }); - connection.connectAsync(function (err, connection) { - try { - assert.ok(connection.isUp(), 'not active'); - testUtil.destroyConnection(connection, function (err, r) { - try { - assert.ok(!connection.isUp(), 'not active'); - done(); - } catch (err) { - done(err); - } + it('Multiple Client', function (done) + { + const totalConnections = 10; + const connections = []; + for (let i = 0; i < totalConnections; i++) + { + connections.push(snowflake.createConnection(connOption.valid)); + } + let completedConnection = 0; + for (let i = 0; i < totalConnections; i++) + { + connections[i].connect(function (err, conn) + { + testUtil.checkError(err); + conn.execute({ + sqlText: 'select 1', + complete: function (err) + { + testUtil.checkError(err); + testUtil.destroyConnection(conn, function () + { + }); + completedConnection++; + } + }); }); - } catch (err) { - done(err); } + const sleepMs = 500; + const maxSleep = 60000; + let sleepFromStartChecking = 0; + + const timeout = () => setTimeout(() => + { + sleepFromStartChecking += sleepMs; + if (completedConnection === totalConnections) + { + done(); + } + else if (sleepFromStartChecking <= maxSleep) + { + timeout(); + } + else + { + done(`Max after ${maxSleep} it's expected to complete ${totalConnections} but completed ${completedConnection}`) + } + }, sleepMs); + + timeout(); }); }); + // Skipped - requires manual interaction to enter credentials on browser + describe.skip('Connection test - external browser', function () { + this.timeout(10000); + + it('Simple Connect', function (done) { + const connection = snowflake.createConnection(connOption.externalBrowser); + + connection.connectAsync(function (err, connection) { + try { + assert.ok(connection.isUp(), 'not active'); + testUtil.destroyConnection(connection, function (err, r) { + try { + assert.ok(!connection.isUp(), 'not active'); + done(); + } catch (err) { + done(err); + } + }); + } catch (err) { + done(err); + } + }); + }); + - it('Connect - external browser timeout', function (done) { - const connection = snowflake.createConnection(connOption.externalBrowserWithShortTimeout); + it('Connect - external browser timeout', function (done) { + const connection = snowflake.createConnection(connOption.externalBrowserWithShortTimeout); - connection.connectAsync(function (err) { - try { - const browserActionTimeout = connOption.externalBrowserWithShortTimeout.browserActionTimeout; - assert.ok(err, `Browser action timed out after ${browserActionTimeout} ms.`); - done(); - } catch (err) { - done(err); - } + connection.connectAsync(function (err) { + try { + const browserActionTimeout = connOption.externalBrowserWithShortTimeout.browserActionTimeout; + assert.ok(err, `Browser action timed out after ${browserActionTimeout} ms.`); + done(); + } catch (err) { + done(err); + } + }); }); - }); - it('Mismatched Username', function (done) { - var connection = snowflake.createConnection(connOption.externalBrowserMismatchUser); - connection.connectAsync(function (err) { - try { - assert.ok(err, 'Logged in with different user than one on connection string'); - assert.equal('The user you were trying to authenticate as differs from the user currently logged in at the IDP.', err['message']); - done(); - } catch (err) { - done(err); - } + it('Mismatched Username', function (done) { + var connection = snowflake.createConnection(connOption.externalBrowserMismatchUser); + connection.connectAsync(function (err) { + try { + assert.ok(err, 'Logged in with different user than one on connection string'); + assert.equal('The user you were trying to authenticate as differs from the user currently logged in at the IDP.', err['message']); + done(); + } catch (err) { + done(err); + } + }); }); }); -}); -describe.skip('Connection test - keypair', function () -{ - it('Simple Connect - specify private key', function (done) + describe.skip('Connection test - keypair', function () { - var connection = snowflake.createConnection(connOption.keypairPrivateKey); + it('Simple Connect - specify private key', function (done) + { + var connection = snowflake.createConnection(connOption.keypairPrivateKey); - async.series([ - function (callback) - { - connection.connect(function (err) + async.series([ + function (callback) { - done(err); - assert.ok(!err, JSON.stringify(err)); + connection.connect(function (err) + { + done(err); + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) + { + assert.ok(connection.isUp(), "not active"); callback(); - }); - }, - function (callback) - { - assert.ok(connection.isUp(), "not active"); - callback(); - }, - function (callback) - { - connection.destroy(function (err) + }, + function (callback) + { + connection.destroy(function (err) + { + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) { - assert.ok(!err, JSON.stringify(err)); + assert.ok(!connection.isUp(), "still active"); callback(); - }); - }, - function (callback) - { - assert.ok(!connection.isUp(), "still active"); - callback(); - }, - ], - ); - }); + }, + ], + ); + }); - it.skip('Simple Connect - specify encrypted private key path and passphrase', function (done) - { - var connection = snowflake.createConnection(connOption.keypairPathEncrypted); + it.skip('Simple Connect - specify encrypted private key path and passphrase', function (done) + { + var connection = snowflake.createConnection(connOption.keypairPathEncrypted); - async.series([ - function (callback) - { - connection.connect(function (err) + async.series([ + function (callback) { - done(err); - assert.ok(!err, JSON.stringify(err)); + connection.connect(function (err) + { + done(err); + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) + { + assert.ok(connection.isUp(), "not active"); callback(); - }); - }, - function (callback) - { - assert.ok(connection.isUp(), "not active"); - callback(); - }, - function (callback) - { - connection.destroy(function (err) + }, + function (callback) { - assert.ok(!err, JSON.stringify(err)); + connection.destroy(function (err) + { + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) + { + assert.ok(!connection.isUp(), "still active"); callback(); - }); - }, - function (callback) - { - assert.ok(!connection.isUp(), "still active"); - callback(); - }, - ], - ); - }); + }, + ], + ); + }); - it.skip('Simple Connect - specify unencrypted private key path without passphrase', function (done) - { - var connection = snowflake.createConnection(connOption.keypairPathEncrypted); + it.skip('Simple Connect - specify unencrypted private key path without passphrase', function (done) + { + var connection = snowflake.createConnection(connOption.keypairPathEncrypted); - async.series([ - function (callback) - { - connection.connect(function (err) + async.series([ + function (callback) { - done(err); - assert.ok(!err, JSON.stringify(err)); + connection.connect(function (err) + { + done(err); + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) + { + assert.ok(connection.isUp(), "not active"); callback(); - }); - }, - function (callback) - { - assert.ok(connection.isUp(), "not active"); - callback(); - }, - function (callback) - { - connection.destroy(function (err) + }, + function (callback) { - assert.ok(!err, JSON.stringify(err)); + connection.destroy(function (err) + { + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) + { + assert.ok(!connection.isUp(), "still active"); callback(); - }); - }, - function (callback) - { - assert.ok(!connection.isUp(), "still active"); - callback(); - }, - ], - ); - }); + }, + ], + ); + }); - it('Wrong JWT token', function (done) - { - var connection = snowflake.createConnection(connOption.keypairWrongToken); - connection.connect(function (err) + it('Wrong JWT token', function (done) { - try - { - assert.ok(err, 'Incorrect JWT token is passed.'); - assert.equal('JWT token is invalid.', err["message"]); - done(); - } - catch (err) + var connection = snowflake.createConnection(connOption.keypairWrongToken); + connection.connect(function (err) { - done(err); - } - }) + try + { + assert.ok(err, 'Incorrect JWT token is passed.'); + assert.equal('JWT token is invalid.', err["message"]); + done(); + } + catch (err) + { + done(err); + } + }) + }); }); -}); -// Skipped - requires manual interaction to obtain oauth token -describe.skip('Connection test - oauth', function () -{ - it('Simple Connect', function (done) + // Skipped - requires manual interaction to obtain oauth token + describe.skip('Connection test - oauth', function () { - var connection = snowflake.createConnection(connOption.oauth); + it('Simple Connect', function (done) + { + var connection = snowflake.createConnection(connOption.oauth); - async.series([ - function (callback) - { - connection.connect(function (err) + async.series([ + function (callback) { - done(err); - assert.ok(!err, JSON.stringify(err)); + connection.connect(function (err) + { + done(err); + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) + { + assert.ok(connection.isUp(), "not active"); callback(); - }); - }, - function (callback) - { - assert.ok(connection.isUp(), "not active"); - callback(); - }, - function (callback) - { - connection.destroy(function (err) + }, + function (callback) { - assert.ok(!err, JSON.stringify(err)); + connection.destroy(function (err) + { + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) + { + assert.ok(!connection.isUp(), "still active"); callback(); - }); - }, - function (callback) - { - assert.ok(!connection.isUp(), "still active"); - callback(); - }, - ], - ); - }); + }, + ], + ); + }); - it('Mismatched Username', function (done) - { - var connection = snowflake.createConnection(connOption.oauthMismatchUser); - connection.connect(function (err) + it('Mismatched Username', function (done) { - try + var connection = snowflake.createConnection(connOption.oauthMismatchUser); + connection.connect(function (err) { - assert.ok(err, 'Logged in with different user than one on connection string'); - assert.equal('The user you were trying to authenticate as differs from the user tied to the access token.', err["message"]); - done(); - } - catch (err) - { - done(err); - } - }) + try + { + assert.ok(err, 'Logged in with different user than one on connection string'); + assert.equal('The user you were trying to authenticate as differs from the user tied to the access token.', err["message"]); + done(); + } + catch (err) + { + done(err); + } + }) + }); }); -}); -describe.skip('Connection test - okta', function () -{ - it('Simple Connect', function (done) + describe.skip('Connection test - okta', function () { - var connection = snowflake.createConnection(connOption.okta); + it('Simple Connect', function (done) + { + var connection = snowflake.createConnection(connOption.okta); - async.series([ - function (callback) - { - connection.connectAsync(function (err) + async.series([ + function (callback) { - done(err); - assert.ok(!err, JSON.stringify(err)); + connection.connectAsync(function (err) + { + done(err); + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) + { + assert.ok(connection.isUp(), "not active"); callback(); - }); - }, - function (callback) - { - assert.ok(connection.isUp(), "not active"); - callback(); - }, - function (callback) - { - connection.destroy(function (err) + }, + function (callback) + { + connection.destroy(function (err) + { + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) { - assert.ok(!err, JSON.stringify(err)); + assert.ok(!connection.isUp(), "still active"); callback(); - }); - }, - function (callback) - { - assert.ok(!connection.isUp(), "still active"); - callback(); - }, - ], - ); + }, + ], + ); + }); }); -}); -describe('Connection test - validate default parameters', function () -{ - it('Valid "warehouse" parameter', function () + describe('Connection test - validate default parameters', function () { - const output = stderr.inspectSync(() => + it('Valid "warehouse" parameter', function () { - snowflake.createConnection({ - account: connOption.valid.account, - username: connOption.valid.username, - password: connOption.valid.password, - warehouse: 'testWarehouse', - validateDefaultParameters: true + const output = stderr.inspectSync(() => + { + snowflake.createConnection({ + account: connOption.valid.account, + username: connOption.valid.username, + password: connOption.valid.password, + warehouse: 'testWarehouse', + validateDefaultParameters: true + }); }); + assert.deepEqual(output, []); }); - assert.deepEqual(output, []); - }); - it('Invalid "warehouse" parameter', function () - { - const output = stderr.inspectSync(() => + it('Invalid "warehouse" parameter', function () { - snowflake.createConnection({ - account: connOption.valid.account, - username: connOption.valid.username, - password: connOption.valid.password, - waerhouse: 'testWarehouse', - validateDefaultParameters: true + const output = stderr.inspectSync(() => + { + snowflake.createConnection({ + account: connOption.valid.account, + username: connOption.valid.username, + password: connOption.valid.password, + waerhouse: 'testWarehouse', + validateDefaultParameters: true + }); }); + assert.deepEqual(output, + [ + "\"waerhouse\" is an unknown connection parameter\n", + "Did you mean \"warehouse\"\n" + ]); }); - assert.deepEqual(output, - [ - "\"waerhouse\" is an unknown connection parameter\n", - "Did you mean \"warehouse\"\n" - ]); - }); - it('Valid "database" parameter', function () - { - const output = stderr.inspectSync(() => + it('Valid "database" parameter', function () { - snowflake.createConnection({ - account: connOption.valid.account, - username: connOption.valid.username, - password: connOption.valid.password, - database: 'testDatabase', - validateDefaultParameters: true + const output = stderr.inspectSync(() => + { + snowflake.createConnection({ + account: connOption.valid.account, + username: connOption.valid.username, + password: connOption.valid.password, + database: 'testDatabase', + validateDefaultParameters: true + }); }); + assert.deepEqual(output, []); }); - assert.deepEqual(output, []); - }); - it('Invalid "db" parameter', function () - { - const output = stderr.inspectSync(() => + it('Invalid "db" parameter', function () { - snowflake.createConnection({ - account: connOption.valid.account, - username: connOption.valid.username, - password: connOption.valid.password, - db: 'testDb', - validateDefaultParameters: true + const output = stderr.inspectSync(() => + { + snowflake.createConnection({ + account: connOption.valid.account, + username: connOption.valid.username, + password: connOption.valid.password, + db: 'testDb', + validateDefaultParameters: true + }); }); + assert.deepEqual(output, + [ + "\"db\" is an unknown connection parameter\n" + ]); }); - assert.deepEqual(output, - [ - "\"db\" is an unknown connection parameter\n" - ]); - }); - it('Invalid "database" parameter', function () - { - const output = stderr.inspectSync(() => + it('Invalid "database" parameter', function () { - snowflake.createConnection({ - account: connOption.valid.account, - username: connOption.valid.username, - password: connOption.valid.password, - datbse: 'testDatabase', - validateDefaultParameters: true + const output = stderr.inspectSync(() => + { + snowflake.createConnection({ + account: connOption.valid.account, + username: connOption.valid.username, + password: connOption.valid.password, + datbse: 'testDatabase', + validateDefaultParameters: true + }); }); + assert.deepEqual(output, + [ + "\"datbse\" is an unknown connection parameter\n", + "Did you mean \"database\"\n" + ]); }); - assert.deepEqual(output, - [ - "\"datbse\" is an unknown connection parameter\n", - "Did you mean \"database\"\n" - ]); - }); - it('Valid "schema" parameter', function () - { - const output = stderr.inspectSync(() => + it('Valid "schema" parameter', function () { - snowflake.createConnection({ - account: connOption.valid.account, - username: connOption.valid.username, - password: connOption.valid.password, - schema: 'testSchema', - validateDefaultParameters: true + const output = stderr.inspectSync(() => + { + snowflake.createConnection({ + account: connOption.valid.account, + username: connOption.valid.username, + password: connOption.valid.password, + schema: 'testSchema', + validateDefaultParameters: true + }); }); + assert.deepEqual(output, []); }); - assert.deepEqual(output, []); - }); - it('Invalid "schema" parameter', function () - { - const output = stderr.inspectSync(() => + it('Invalid "schema" parameter', function () { - snowflake.createConnection({ - account: connOption.valid.account, - username: connOption.valid.username, - password: connOption.valid.password, - shcema: 'testSchema', - validateDefaultParameters: true + const output = stderr.inspectSync(() => + { + snowflake.createConnection({ + account: connOption.valid.account, + username: connOption.valid.username, + password: connOption.valid.password, + shcema: 'testSchema', + validateDefaultParameters: true + }); }); + assert.deepEqual(output, + [ + "\"shcema\" is an unknown connection parameter\n", + "Did you mean \"schema\"\n" + ]); }); - assert.deepEqual(output, - [ - "\"shcema\" is an unknown connection parameter\n", - "Did you mean \"schema\"\n" - ]); }); -}); -describe('Connection test - connection pool', function () -{ - this.timeout(30000); - - it('1 min connection', function (done) + describe('Connection test - connection pool', function () { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 10, - min: 1 - }); + this.timeout(30000); - assert.equal(connectionPool.max, 10); - assert.equal(connectionPool.min, 1); - assert.equal(connectionPool.size, 1); + it('1 min connection', function (done) + { + var connectionPool = snowflake.createPool(connOption.valid, + { + max: 10, + min: 1 + }); - done(); - }); + assert.equal(connectionPool.max, 10); + assert.equal(connectionPool.min, 1); + assert.equal(connectionPool.size, 1); - it('5 min connection', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 10, - min: 5 - }); + done(); + }); - assert.equal(connectionPool.max, 10); - assert.equal(connectionPool.min, 5); - assert.equal(connectionPool.size, 5); + it('5 min connection', function (done) + { + var connectionPool = snowflake.createPool(connOption.valid, + { + max: 10, + min: 5 + }); - done(); - }); + assert.equal(connectionPool.max, 10); + assert.equal(connectionPool.min, 5); + assert.equal(connectionPool.size, 5); - it('10 min connection', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 10, - min: 10 - }); + done(); + }); - assert.equal(connectionPool.max, 10); - assert.equal(connectionPool.min, 10); - assert.equal(connectionPool.size, 10); + it('10 min connection', function (done) + { + var connectionPool = snowflake.createPool(connOption.valid, + { + max: 10, + min: 10 + }); - done(); - }); + assert.equal(connectionPool.max, 10); + assert.equal(connectionPool.min, 10); + assert.equal(connectionPool.size, 10); - it('min greater than max connection', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 5, - min: 10 - }); + done(); + }); - assert.equal(connectionPool.max, 5); - assert.equal(connectionPool.min, 5); - assert.equal(connectionPool.size, 5); + it('min greater than max connection', function (done) + { + var connectionPool = snowflake.createPool(connOption.valid, + { + max: 5, + min: 10 + }); - done(); - }); + assert.equal(connectionPool.max, 5); + assert.equal(connectionPool.min, 5); + assert.equal(connectionPool.size, 5); - it('1 max connection', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 1, - min: 0 - }); + done(); + }); + + it('1 max connection', function (done) + { + var connectionPool = snowflake.createPool(connOption.valid, + { + max: 1, + min: 0 + }); + + assert.equal(connectionPool.max, 1); + assert.equal(connectionPool.min, 0); + + // Acquire a connection + const resourcePromise1 = connectionPool.acquire(); + assert.equal(connectionPool.size, 1); + + done(); + }); + + it('1 max connection and acquire() more than 1', function (done) + { + var connectionPool = snowflake.createPool(connOption.valid, + { + max: 1, + min: 0 + }); + + assert.equal(connectionPool.max, 1); + assert.equal(connectionPool.min, 0); + + // Acquire 2 connections + const resourcePromise1 = connectionPool.acquire(); + assert.equal(connectionPool.size, 1); + const resourcePromise2 = connectionPool.acquire(); + assert.equal(connectionPool.size, 1); + + done(); + }); + + it('5 max connection', function (done) + { + var connectionPool = snowflake.createPool(connOption.valid, + { + max: 5, + min: 0 + }); - assert.equal(connectionPool.max, 1); - assert.equal(connectionPool.min, 0); + assert.equal(connectionPool.max, 5); + assert.equal(connectionPool.min, 0); - // Acquire a connection - const resourcePromise1 = connectionPool.acquire(); - assert.equal(connectionPool.size, 1); + // Acquire 5 connections + const resourcePromise1 = connectionPool.acquire(); + assert.equal(connectionPool.size, 1); + const resourcePromise2 = connectionPool.acquire(); + assert.equal(connectionPool.size, 2); + const resourcePromise3 = connectionPool.acquire(); + assert.equal(connectionPool.size, 3); + const resourcePromise4 = connectionPool.acquire(); + assert.equal(connectionPool.size, 4); + const resourcePromise5 = connectionPool.acquire(); + assert.equal(connectionPool.size, 5); - done(); - }); + done(); + }); - it('1 max connection and acquire() more than 1', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 1, - min: 0 - }); + it('5 max connections and acquire() more than 5', function (done) + { + var connectionPool = snowflake.createPool(connOption.valid, + { + max: 5, + min: 0 + }); - assert.equal(connectionPool.max, 1); - assert.equal(connectionPool.min, 0); + assert.equal(connectionPool.max, 5); + assert.equal(connectionPool.min, 0); - // Acquire 2 connections - const resourcePromise1 = connectionPool.acquire(); - assert.equal(connectionPool.size, 1); - const resourcePromise2 = connectionPool.acquire(); - assert.equal(connectionPool.size, 1); + // Acquire 6 connections + const resourcePromise1 = connectionPool.acquire(); + assert.equal(connectionPool.size, 1); + const resourcePromise2 = connectionPool.acquire(); + assert.equal(connectionPool.size, 2); + const resourcePromise3 = connectionPool.acquire(); + assert.equal(connectionPool.size, 3); + const resourcePromise4 = connectionPool.acquire(); + assert.equal(connectionPool.size, 4); + const resourcePromise5 = connectionPool.acquire(); + assert.equal(connectionPool.size, 5); + const resourcePromise6 = connectionPool.acquire(); + assert.equal(connectionPool.size, 5); - done(); - }); + done(); + }); - it('5 max connection', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 5, - min: 0 - }); + it('10 max connection', function (done) + { + var connectionPool = snowflake.createPool(connOption.valid, + { + max: 10, + min: 0 + }); - assert.equal(connectionPool.max, 5); - assert.equal(connectionPool.min, 0); - - // Acquire 5 connections - const resourcePromise1 = connectionPool.acquire(); - assert.equal(connectionPool.size, 1); - const resourcePromise2 = connectionPool.acquire(); - assert.equal(connectionPool.size, 2); - const resourcePromise3 = connectionPool.acquire(); - assert.equal(connectionPool.size, 3); - const resourcePromise4 = connectionPool.acquire(); - assert.equal(connectionPool.size, 4); - const resourcePromise5 = connectionPool.acquire(); - assert.equal(connectionPool.size, 5); - - done(); - }); + assert.equal(connectionPool.max, 10); + assert.equal(connectionPool.min, 0); - it('5 max connections and acquire() more than 5', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 5, - min: 0 - }); + // Acquire 10 connections + const resourcePromise1 = connectionPool.acquire(); + assert.equal(connectionPool.size, 1); + const resourcePromise2 = connectionPool.acquire(); + assert.equal(connectionPool.size, 2); + const resourcePromise3 = connectionPool.acquire(); + assert.equal(connectionPool.size, 3); + const resourcePromise4 = connectionPool.acquire(); + assert.equal(connectionPool.size, 4); + const resourcePromise5 = connectionPool.acquire(); + assert.equal(connectionPool.size, 5); + const resourcePromise6 = connectionPool.acquire(); + assert.equal(connectionPool.size, 6); + const resourcePromise7 = connectionPool.acquire(); + assert.equal(connectionPool.size, 7); + const resourcePromise8 = connectionPool.acquire(); + assert.equal(connectionPool.size, 8); + const resourcePromise9 = connectionPool.acquire(); + assert.equal(connectionPool.size, 9); + const resourcePromise10 = connectionPool.acquire(); + assert.equal(connectionPool.size, 10); - assert.equal(connectionPool.max, 5); - assert.equal(connectionPool.min, 0); - - // Acquire 6 connections - const resourcePromise1 = connectionPool.acquire(); - assert.equal(connectionPool.size, 1); - const resourcePromise2 = connectionPool.acquire(); - assert.equal(connectionPool.size, 2); - const resourcePromise3 = connectionPool.acquire(); - assert.equal(connectionPool.size, 3); - const resourcePromise4 = connectionPool.acquire(); - assert.equal(connectionPool.size, 4); - const resourcePromise5 = connectionPool.acquire(); - assert.equal(connectionPool.size, 5); - const resourcePromise6 = connectionPool.acquire(); - assert.equal(connectionPool.size, 5); - - done(); - }); + done(); + }); - it('10 max connection', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 10, - min: 0 - }); + it('10 max connections and acquire() more than 10', function (done) + { + var connectionPool = snowflake.createPool(connOption.valid, + { + max: 10, + min: 0 + }); - assert.equal(connectionPool.max, 10); - assert.equal(connectionPool.min, 0); - - // Acquire 10 connections - const resourcePromise1 = connectionPool.acquire(); - assert.equal(connectionPool.size, 1); - const resourcePromise2 = connectionPool.acquire(); - assert.equal(connectionPool.size, 2); - const resourcePromise3 = connectionPool.acquire(); - assert.equal(connectionPool.size, 3); - const resourcePromise4 = connectionPool.acquire(); - assert.equal(connectionPool.size, 4); - const resourcePromise5 = connectionPool.acquire(); - assert.equal(connectionPool.size, 5); - const resourcePromise6 = connectionPool.acquire(); - assert.equal(connectionPool.size, 6); - const resourcePromise7 = connectionPool.acquire(); - assert.equal(connectionPool.size, 7); - const resourcePromise8 = connectionPool.acquire(); - assert.equal(connectionPool.size, 8); - const resourcePromise9 = connectionPool.acquire(); - assert.equal(connectionPool.size, 9); - const resourcePromise10 = connectionPool.acquire(); - assert.equal(connectionPool.size, 10); - - done(); - }); + assert.equal(connectionPool.max, 10); + assert.equal(connectionPool.min, 0); - it('10 max connections and acquire() more than 10', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 10, - min: 0 - }); + // Acquire 11 connections + const resourcePromise1 = connectionPool.acquire(); + assert.equal(connectionPool.size, 1); + const resourcePromise2 = connectionPool.acquire(); + assert.equal(connectionPool.size, 2); + const resourcePromise3 = connectionPool.acquire(); + assert.equal(connectionPool.size, 3); + const resourcePromise4 = connectionPool.acquire(); + assert.equal(connectionPool.size, 4); + const resourcePromise5 = connectionPool.acquire(); + assert.equal(connectionPool.size, 5); + const resourcePromise6 = connectionPool.acquire(); + assert.equal(connectionPool.size, 6); + const resourcePromise7 = connectionPool.acquire(); + assert.equal(connectionPool.size, 7); + const resourcePromise8 = connectionPool.acquire(); + assert.equal(connectionPool.size, 8); + const resourcePromise9 = connectionPool.acquire(); + assert.equal(connectionPool.size, 9); + const resourcePromise10 = connectionPool.acquire(); + assert.equal(connectionPool.size, 10); + const resourcePromise11 = connectionPool.acquire(); + assert.equal(connectionPool.size, 10); - assert.equal(connectionPool.max, 10); - assert.equal(connectionPool.min, 0); - - // Acquire 11 connections - const resourcePromise1 = connectionPool.acquire(); - assert.equal(connectionPool.size, 1); - const resourcePromise2 = connectionPool.acquire(); - assert.equal(connectionPool.size, 2); - const resourcePromise3 = connectionPool.acquire(); - assert.equal(connectionPool.size, 3); - const resourcePromise4 = connectionPool.acquire(); - assert.equal(connectionPool.size, 4); - const resourcePromise5 = connectionPool.acquire(); - assert.equal(connectionPool.size, 5); - const resourcePromise6 = connectionPool.acquire(); - assert.equal(connectionPool.size, 6); - const resourcePromise7 = connectionPool.acquire(); - assert.equal(connectionPool.size, 7); - const resourcePromise8 = connectionPool.acquire(); - assert.equal(connectionPool.size, 8); - const resourcePromise9 = connectionPool.acquire(); - assert.equal(connectionPool.size, 9); - const resourcePromise10 = connectionPool.acquire(); - assert.equal(connectionPool.size, 10); - const resourcePromise11 = connectionPool.acquire(); - assert.equal(connectionPool.size, 10); - - done(); - }); + done(); + }); - it('acquire() 1 connection and release()', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 5, - min: 0 - }); + it('acquire() 1 connection and release()', function (done) + { + var connectionPool = snowflake.createPool(connOption.valid, + { + max: 5, + min: 0 + }); - // Acquire one connection - const resourcePromise1 = connectionPool.acquire(); + // Acquire one connection + const resourcePromise1 = connectionPool.acquire(); - assert.equal(connectionPool.size, 1); - assert.equal(connectionPool.pending, 1); - assert.equal(connectionPool.spareResourceCapacity, 4); + assert.equal(connectionPool.size, 1); + assert.equal(connectionPool.pending, 1); + assert.equal(connectionPool.spareResourceCapacity, 4); - async.series( - [ - function (callback) - { - // Once acquired, release the connection - resourcePromise1.then(function (connection) + async.series( + [ + function (callback) { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.pending, 0); - - connectionPool.release(connection).then(() => + // Once acquired, release the connection + resourcePromise1.then(function (connection) { - // One connection should be available for use - assert.equal(connectionPool.available, 1); - callback(); + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.pending, 0); + + connectionPool.release(connection).then(() => + { + // One connection should be available for use + assert.equal(connectionPool.available, 1); + callback(); + }); }); - }); - } - ], - done); - }); + } + ], + done); + }); - it('acquire() 5 connections and release()', function (done) - { - // Create the connection pool - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 5, - min: 0 - }); + it('acquire() 5 connections and release()', function (done) + { + // Create the connection pool + var connectionPool = snowflake.createPool(connOption.valid, + { + max: 5, + min: 0 + }); - // Acquire 5 connections - const resourcePromise1 = connectionPool.acquire(); - const resourcePromise2 = connectionPool.acquire(); - const resourcePromise3 = connectionPool.acquire(); - const resourcePromise4 = connectionPool.acquire(); - const resourcePromise5 = connectionPool.acquire(); + // Acquire 5 connections + const resourcePromise1 = connectionPool.acquire(); + const resourcePromise2 = connectionPool.acquire(); + const resourcePromise3 = connectionPool.acquire(); + const resourcePromise4 = connectionPool.acquire(); + const resourcePromise5 = connectionPool.acquire(); - assert.equal(connectionPool.size, 5); - assert.equal(connectionPool.pending, 5); - assert.equal(connectionPool.spareResourceCapacity, 0); + assert.equal(connectionPool.size, 5); + assert.equal(connectionPool.pending, 5); + assert.equal(connectionPool.spareResourceCapacity, 0); - async.series( - [ - function (callback) - { - // Once acquired, release the connection - resourcePromise1.then(function (connection) + async.series( + [ + function (callback) { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.pending, 4); - - connectionPool.release(connection).then(() => + // Once acquired, release the connection + resourcePromise1.then(function (connection) { - assert.equal(connectionPool.available, 0); - callback(); + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.pending, 4); + + connectionPool.release(connection).then(() => + { + assert.equal(connectionPool.available, 0); + callback(); + }); }); - }); - }, - function (callback) - { - // Once acquired, release the connection - resourcePromise2.then(function (connection) + }, + function (callback) { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.pending, 3); - - connectionPool.release(connection).then(() => + // Once acquired, release the connection + resourcePromise2.then(function (connection) { - assert.equal(connectionPool.available, 0); - callback(); + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.pending, 3); + + connectionPool.release(connection).then(() => + { + assert.equal(connectionPool.available, 0); + callback(); + }); }); - }); - }, - function (callback) - { - // Once acquired, release the connection - resourcePromise3.then(function (connection) + }, + function (callback) { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.pending, 2); - - connectionPool.release(connection).then(() => + // Once acquired, release the connection + resourcePromise3.then(function (connection) { - assert.equal(connectionPool.available, 0); - callback(); + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.pending, 2); + + connectionPool.release(connection).then(() => + { + assert.equal(connectionPool.available, 0); + callback(); + }); }); - }); - }, - function (callback) - { - // Once acquired, release the connection - resourcePromise4.then(function (connection) + }, + function (callback) { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.pending, 1); - - connectionPool.release(connection).then(() => + // Once acquired, release the connection + resourcePromise4.then(function (connection) { - assert.equal(connectionPool.available, 0); - callback(); + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.pending, 1); + + connectionPool.release(connection).then(() => + { + assert.equal(connectionPool.available, 0); + callback(); + }); }); - }); - }, - function (callback) - { - // Once acquired, release the connection - resourcePromise5.then(function (connection) + }, + function (callback) { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.pending, 0); - - connectionPool.release(connection).then(() => + // Once acquired, release the connection + resourcePromise5.then(function (connection) { - assert.equal(connectionPool.available, 1); - callback(); + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.pending, 0); + + connectionPool.release(connection).then(() => + { + assert.equal(connectionPool.available, 1); + callback(); + }); }); - }); - }, - ], - done); - }); - - it('acquire() 1 connection and destroy()', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 5, - min: 0 - }); + }, + ], + done); + }); - // Acquire a connection - const resourcePromise1 = connectionPool.acquire(); + it('acquire() 1 connection and destroy()', function (done) + { + var connectionPool = snowflake.createPool(connOption.valid, + { + max: 5, + min: 0 + }); - assert.equal(connectionPool.size, 1); - assert.equal(connectionPool.pending, 1); - assert.equal(connectionPool.spareResourceCapacity, 4); + // Acquire a connection + const resourcePromise1 = connectionPool.acquire(); - // Once acquired, destroy the connection - resourcePromise1.then(function (connection) - { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.pending, 0); + assert.equal(connectionPool.size, 1); + assert.equal(connectionPool.pending, 1); + assert.equal(connectionPool.spareResourceCapacity, 4); - connectionPool.destroy(connection).then(() => + // Once acquired, destroy the connection + resourcePromise1.then(function (connection) { - // No connection should be available for use - assert.equal(connectionPool.available, 0); - done(); + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.pending, 0); + + connectionPool.destroy(connection).then(() => + { + // No connection should be available for use + assert.equal(connectionPool.available, 0); + done(); + }); }); }); - }); - it('acquire() 5 connections and destroy()', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 5, - min: 0 - }); + it('acquire() 5 connections and destroy()', function (done) + { + var connectionPool = snowflake.createPool(connOption.valid, + { + max: 5, + min: 0 + }); - // Acquire 5 connections - const resourcePromise1 = connectionPool.acquire(); - const resourcePromise2 = connectionPool.acquire(); - const resourcePromise3 = connectionPool.acquire(); - const resourcePromise4 = connectionPool.acquire(); - const resourcePromise5 = connectionPool.acquire(); + // Acquire 5 connections + const resourcePromise1 = connectionPool.acquire(); + const resourcePromise2 = connectionPool.acquire(); + const resourcePromise3 = connectionPool.acquire(); + const resourcePromise4 = connectionPool.acquire(); + const resourcePromise5 = connectionPool.acquire(); - assert.equal(connectionPool.size, 5); - assert.equal(connectionPool.pending, 5); - assert.equal(connectionPool.spareResourceCapacity, 0); + assert.equal(connectionPool.size, 5); + assert.equal(connectionPool.pending, 5); + assert.equal(connectionPool.spareResourceCapacity, 0); - async.series( - [ - function (callback) - { - // Once acquired, destroy the connection - resourcePromise1.then(function (connection) + async.series( + [ + function (callback) { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.pending, 4); - - connectionPool.destroy(connection).then(() => + // Once acquired, destroy the connection + resourcePromise1.then(function (connection) { - assert.equal(connectionPool.available, 0); - callback(); + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.pending, 4); + + connectionPool.destroy(connection).then(() => + { + assert.equal(connectionPool.available, 0); + callback(); + }); }); - }); - }, - function (callback) - { - // Once acquired, destroy the connection - resourcePromise2.then(function (connection) + }, + function (callback) { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.pending, 3); - - connectionPool.destroy(connection).then(() => + // Once acquired, destroy the connection + resourcePromise2.then(function (connection) { - assert.equal(connectionPool.available, 0); - callback(); + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.pending, 3); + + connectionPool.destroy(connection).then(() => + { + assert.equal(connectionPool.available, 0); + callback(); + }); }); - }); - }, - function (callback) - { - // Once acquired, destroy the connection - resourcePromise3.then(function (connection) + }, + function (callback) { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.pending, 2); - - connectionPool.destroy(connection).then(() => + // Once acquired, destroy the connection + resourcePromise3.then(function (connection) { - assert.equal(connectionPool.available, 0); - callback(); + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.pending, 2); + + connectionPool.destroy(connection).then(() => + { + assert.equal(connectionPool.available, 0); + callback(); + }); }); - }); - }, - function (callback) - { - // Once acquired, destroy the connection - resourcePromise4.then(function (connection) + }, + function (callback) { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.pending, 1); - - connectionPool.destroy(connection).then(() => + // Once acquired, destroy the connection + resourcePromise4.then(function (connection) { - assert.equal(connectionPool.available, 0); - callback(); + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.pending, 1); + + connectionPool.destroy(connection).then(() => + { + assert.equal(connectionPool.available, 0); + callback(); + }); }); - }); - }, - function (callback) - { - // Once acquired, destroy the connection - resourcePromise5.then(function (connection) + }, + function (callback) { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.pending, 0); - - connectionPool.destroy(connection).then(() => + // Once acquired, destroy the connection + resourcePromise5.then(function (connection) { - assert.equal(connectionPool.available, 0); - callback(); + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.pending, 0); + + connectionPool.destroy(connection).then(() => + { + assert.equal(connectionPool.available, 0); + callback(); + }); }); - }); - }, - ], - done); - }); - - it('use()', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 5, - min: 0 - }); - - assert.equal(connectionPool.size, 0); + }, + ], + done); + }); - // Use the connection pool, automatically creates a new connection - connectionPool.use(async (connection) => - { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.size, 1); - assert.equal(connectionPool.pending, 0); - assert.equal(connectionPool.spareResourceCapacity, 4); - assert.equal(connectionPool.available, 0); - }).then(() => + it('use()', function (done) { - assert.equal(connectionPool.size, 1); - assert.equal(connectionPool.available, 1); + var connectionPool = snowflake.createPool(connOption.valid, + { + max: 5, + min: 0 + }); - // Use the connection pool, will use the existing connection + assert.equal(connectionPool.size, 0); + + // Use the connection pool, automatically creates a new connection connectionPool.use(async (connection) => { assert.ok(connection.isUp(), "not active"); @@ -1059,40 +1194,26 @@ describe('Connection test - connection pool', function () { assert.equal(connectionPool.size, 1); assert.equal(connectionPool.available, 1); - done(); - }); - }); - }); - it('wrong password - use', async function () - { - var connectionPool = snowflake.createPool(connOption.wrongPwd, - { - max: 10, - min: 1 + // Use the connection pool, will use the existing connection + connectionPool.use(async (connection) => + { + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.size, 1); + assert.equal(connectionPool.pending, 0); + assert.equal(connectionPool.spareResourceCapacity, 4); + assert.equal(connectionPool.available, 0); + }).then(() => + { + assert.equal(connectionPool.size, 1); + assert.equal(connectionPool.available, 1); + done(); + }); }); + }); - assert.equal(connectionPool.max, 10); - assert.equal(connectionPool.min, 1); - assert.equal(connectionPool.size, 1); - - try - { - // Use the connection pool, automatically creates a new connection - await connectionPool.use(async (connection) => - { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.size, 1); - }); - } - catch (err) + it('wrong password - use', async function () { - assert.strictEqual(err.message, "Incorrect username or password was specified."); - } - }); - - it('wrong password - acquire', async function () - { var connectionPool = snowflake.createPool(connOption.wrongPwd, { max: 10, @@ -1105,80 +1226,108 @@ describe('Connection test - connection pool', function () try { - await connectionPool.acquire(); + // Use the connection pool, automatically creates a new connection + await connectionPool.use(async (connection) => + { + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.size, 1); + }); } catch (err) { assert.strictEqual(err.message, "Incorrect username or password was specified."); } }); -}); -describe('Connection Test - Heartbeat', () => -{ - let connection; + it('wrong password - acquire', async function () + { + var connectionPool = snowflake.createPool(connOption.wrongPwd, + { + max: 10, + min: 1 + }); - before(async () => - { - connection = snowflake.createConnection(connOption.valid); - await testUtil.connectAsync(connection); - }); + assert.equal(connectionPool.max, 10); + assert.equal(connectionPool.min, 1); + assert.equal(connectionPool.size, 1); - after(async () => - { - await testUtil.destroyConnectionAsync(connection); + try + { + await connectionPool.acquire(); + } + catch (err) + { + assert.strictEqual(err.message, "Incorrect username or password was specified."); + } + }); }); - it('call heartbeat url with default callback', () => + describe('Connection Test - Heartbeat', () => { - connection.heartbeat(); - }); + let connection; - it('call heartbeat url with callback', done => - { - connection.heartbeat(err => err ? done(err) : done()); - }); + before(async () => + { + connection = snowflake.createConnection(connOption.valid); + await testUtil.connectAsync(connection); + }); - it('call heartbeat url as promise', async () => - { - const rows = await connection.heartbeatAsync(); - assert.deepEqual(rows, [ { '1': 1 } ]); - }); -}); + after(async () => + { + await testUtil.destroyConnectionAsync(connection); + }); -describe('Connection Test - isValid', () => -{ - let connection; + it('call heartbeat url with default callback', () => + { + connection.heartbeat(); + }); - beforeEach(async () => - { - connection = snowflake.createConnection(connOption.valid); - await testUtil.connectAsync(connection); - }); + it('call heartbeat url with callback', done => + { + connection.heartbeat(err => err ? done(err) : done()); + }); - afterEach(async () => - { - if (connection.isUp()) + it('call heartbeat url as promise', async () => { - await testUtil.destroyConnectionAsync(connection); - } + const rows = await connection.heartbeatAsync(); + assert.deepEqual(rows, [ { '1': 1 } ]); + }); }); - it('connection is valid after connect', async () => + describe('Connection Test - isValid', () => { - const result = await connection.isValidAsync(); + let connection; - assert.equal(result, true); - }); + beforeEach(async () => + { + connection = snowflake.createConnection(connOption.valid); + await testUtil.connectAsync(connection); + }); - it('connection is invalid after destroy', async () => - { - await testUtil.destroyConnectionAsync(connection); + afterEach(async () => + { + if (connection.isUp()) + { + await testUtil.destroyConnectionAsync(connection); + } + }); - const result = await connection.isValidAsync(); + it('connection is valid after connect', async () => + { + const result = await connection.isValidAsync(); - assert.equal(result, false); - }); + assert.equal(result, true); + }); + + it('connection is invalid after destroy', async () => + { + await testUtil.destroyConnectionAsync(connection); - // there is no way to test heartbeat fail to running instance of snowflake -}); + const result = await connection.isValidAsync(); + + assert.equal(result, false); + }); + + // there is no way to test heartbeat fail to running instance of snowflake + }); +} From 2039f909e81adf66b2fa5497d8343dfc9eedf7bd Mon Sep 17 00:00:00 2001 From: John Yun Date: Mon, 31 Jul 2023 16:56:52 -0700 Subject: [PATCH 3/5] Moved the skipped test in testConnection to testManualConnection.js --- test/integration/testConnection.js | 1830 ++++++++-------------- test/integration/testManualConnection.js | 404 +++++ 2 files changed, 1047 insertions(+), 1187 deletions(-) create mode 100644 test/integration/testManualConnection.js diff --git a/test/integration/testConnection.js b/test/integration/testConnection.js index 67bcaed29..aa8c978f6 100644 --- a/test/integration/testConnection.js +++ b/test/integration/testConnection.js @@ -1,1333 +1,789 @@ /* * Copyright (c) 2015-2019 Snowflake Computing Inc. All rights reserved. */ -const snowflake = require('./../../lib/snowflake'); -const async = require('async'); -const assert = require('assert'); -const connOption = require('./connectionOptions'); -const testUtil = require('./testUtil'); -const Util = require('./../../lib/util'); -const Core = require('./../../lib/core'); +const snowflake = require("./../../lib/snowflake"); +const async = require("async"); +const assert = require("assert"); +const connOption = require("./connectionOptions"); +const testUtil = require("./testUtil"); +const Util = require("./../../lib/util"); +const Core = require("./../../lib/core"); const stderr = require("test-console").stderr; -if (process.env.RUN_MANUAL_TESTS_ONLY == 'true') { - describe.only('Run manual tests', function () { - describe('Connection test - external browser', function () { - it('Simple Connect', function (done) { - const connection = snowflake.createConnection(connOption.externalBrowser); - - connection.connectAsync(function (err, connection) { - try { - assert.ok(connection.isUp(), 'not active'); - testUtil.destroyConnection(connection, function (err, r) { - try { - assert.ok(!connection.isUp(), 'not active'); - done(); - } catch (err) { - done(err); - } - }); - } catch (err) { - done(err); - } - }); - }); +describe("Connection test", function () { + it("return tokens in qaMode", function () { + const coreInst = Core({ + qaMode: true, + httpClientClass: require("./../../lib/http/node"), + loggerClass: require("./../../lib/logger/node"), + client: { + version: Util.driverVersion, + environment: process.versions, + }, + }); + const connection = coreInst.createConnection(connOption.valid); + assert.deepEqual(connection.getTokens(), { + masterToken: undefined, + masterTokenExpirationTime: undefined, + sessionToken: undefined, + sessionTokenExpirationTime: undefined, + }); + }); - it('Connect - external browser timeout', function (done) { - const connection = snowflake.createConnection(connOption.externalBrowserWithShortTimeout); + it("does not return tokens when not in qaMode", function () { + const connection = snowflake.createConnection(connOption.valid); + assert.deepEqual(connection.getTokens(), {}); + }); + it("Simple Connect", async function () { + const connection = snowflake.createConnection(connOption.valid); - connection.connectAsync(function (err) { - try { - const browserActionTimeout = connOption.externalBrowserWithShortTimeout.browserActionTimeout; - assert.ok(err, `Browser action timed out after ${browserActionTimeout} ms.`); - done(); - } catch (err) { - done(err); - } - }); - }); + await testUtil.connectAsync(connection); + assert.ok(connection.isUp(), "not active"); + await testUtil.destroyConnectionAsync(connection); + assert.ok(!connection.isUp(), "still active"); + }); - it('Mismatched Username', function (done) { - var connection = snowflake.createConnection(connOption.externalBrowserMismatchUser); - connection.connectAsync(function (err) { - try { - assert.ok(err, 'Logged in with different user than one on connection string'); - assert.equal('The user you were trying to authenticate as differs from the user currently logged in at the IDP.', err['message']); - done(); - } catch (err) { - done(err); - } - }); - }); + it("Wrong Username", function (done) { + var connection = snowflake.createConnection(connOption.wrongUserName); + connection.connect(function (err) { + assert.ok(err, "Username is an empty string"); + assert.equal( + "Incorrect username or password was specified.", + err["message"] + ); + done(); }); + }); - describe('Connection test - oauth', function () - { - it('Simple Connect', function (done) - { - var connection = snowflake.createConnection(connOption.oauth); - - async.series([ - function (callback) - { - connection.connect(function (err) - { - done(err); - assert.ok(!err, JSON.stringify(err)); - callback(); - }); - }, - function (callback) - { - assert.ok(connection.isUp(), "not active"); - callback(); - }, - function (callback) - { - connection.destroy(function (err) - { - assert.ok(!err, JSON.stringify(err)); - callback(); - }); - }, - function (callback) - { - assert.ok(!connection.isUp(), "still active"); - callback(); - }, - ], - ); - }); - - it('Mismatched Username', function (done) - { - var connection = snowflake.createConnection(connOption.oauthMismatchUser); - connection.connect(function (err) - { - try - { - assert.ok(err, 'Logged in with different user than one on connection string'); - assert.equal('The user you were trying to authenticate as differs from the user tied to the access token.', err["message"]); - done(); - } - catch (err) - { - done(err); - } - }) - }); + it("Wrong Password", function (done) { + var connection = snowflake.createConnection(connOption.wrongPwd); + connection.connect(function (err) { + assert.ok(err, "Password is an empty string"); + assert.equal( + "Incorrect username or password was specified.", + err["message"] + ); + done(); }); + }); - describe('Connection test - okta', function () - { - it('Simple Connect', function (done) - { - var connection = snowflake.createConnection(connOption.okta); - - async.series([ - function (callback) - { - connection.connectAsync(function (err) - { - done(err); - assert.ok(!err, JSON.stringify(err)); - callback(); - }); - }, - function (callback) - { - assert.ok(connection.isUp(), "not active"); - callback(); + it("Multiple Client", function (done) { + const totalConnections = 10; + const connections = []; + for (let i = 0; i < totalConnections; i++) { + connections.push(snowflake.createConnection(connOption.valid)); + } + let completedConnection = 0; + for (let i = 0; i < totalConnections; i++) { + connections[i].connect(function (err, conn) { + testUtil.checkError(err); + conn.execute({ + sqlText: "select 1", + complete: function (err) { + testUtil.checkError(err); + testUtil.destroyConnection(conn, function () {}); + completedConnection++; }, - function (callback) - { - connection.destroy(function (err) - { - assert.ok(!err, JSON.stringify(err)); - callback(); - }); - }, - function (callback) - { - assert.ok(!connection.isUp(), "still active"); - callback(); - }, - ], - ); - }); - }); - }) -} else { - describe('Connection test', function () - { - it('return tokens in qaMode', function () - { - const coreInst = Core({ - qaMode: true, - httpClientClass: require('./../../lib/http/node'), - loggerClass: require('./../../lib/logger/node'), - client: - { - version: Util.driverVersion, - environment: process.versions - } - }); - const connection = coreInst.createConnection(connOption.valid); - assert.deepEqual(connection.getTokens(), { - masterToken: undefined, - masterTokenExpirationTime: undefined, - sessionToken: undefined, - sessionTokenExpirationTime: undefined }); - } - ); - - it('does not return tokens when not in qaMode', function () - { - const connection = snowflake.createConnection(connOption.valid); - assert.deepEqual(connection.getTokens(), {}); - } - ) - ; - it('Simple Connect', async function () { - const connection = snowflake.createConnection(connOption.valid); - - await testUtil.connectAsync(connection); - assert.ok(connection.isUp(), "not active"); - await testUtil.destroyConnectionAsync(connection); - assert.ok(!connection.isUp(), "still active"); - }); - - it('Wrong Username', function (done) - { - var connection = snowflake.createConnection(connOption.wrongUserName); - connection.connect(function (err) - { - assert.ok(err, 'Username is an empty string'); - assert.equal('Incorrect username or password was specified.', err["message"]); - done(); - }); - }); - - it('Wrong Password', function (done) - { - var connection = snowflake.createConnection(connOption.wrongPwd); - connection.connect(function (err) - { - assert.ok(err, 'Password is an empty string'); - assert.equal('Incorrect username or password was specified.', err["message"]); - done(); }); - }); - - it('Multiple Client', function (done) - { - const totalConnections = 10; - const connections = []; - for (let i = 0; i < totalConnections; i++) - { - connections.push(snowflake.createConnection(connOption.valid)); - } - let completedConnection = 0; - for (let i = 0; i < totalConnections; i++) - { - connections[i].connect(function (err, conn) - { - testUtil.checkError(err); - conn.execute({ - sqlText: 'select 1', - complete: function (err) - { - testUtil.checkError(err); - testUtil.destroyConnection(conn, function () - { - }); - completedConnection++; - } - }); - }); - } - const sleepMs = 500; - const maxSleep = 60000; - let sleepFromStartChecking = 0; + } + const sleepMs = 500; + const maxSleep = 60000; + let sleepFromStartChecking = 0; - const timeout = () => setTimeout(() => - { + const timeout = () => + setTimeout(() => { sleepFromStartChecking += sleepMs; - if (completedConnection === totalConnections) - { + if (completedConnection === totalConnections) { done(); - } - else if (sleepFromStartChecking <= maxSleep) - { + } else if (sleepFromStartChecking <= maxSleep) { timeout(); - } - else - { - done(`Max after ${maxSleep} it's expected to complete ${totalConnections} but completed ${completedConnection}`) + } else { + done( + `Max after ${maxSleep} it's expected to complete ${totalConnections} but completed ${completedConnection}` + ); } }, sleepMs); - timeout(); - }); + timeout(); }); - - // Skipped - requires manual interaction to enter credentials on browser - describe.skip('Connection test - external browser', function () { - this.timeout(10000); - - it('Simple Connect', function (done) { - const connection = snowflake.createConnection(connOption.externalBrowser); - - connection.connectAsync(function (err, connection) { - try { - assert.ok(connection.isUp(), 'not active'); - testUtil.destroyConnection(connection, function (err, r) { - try { - assert.ok(!connection.isUp(), 'not active'); - done(); - } catch (err) { - done(err); - } - }); - } catch (err) { - done(err); - } - }); - }); - - - it('Connect - external browser timeout', function (done) { - const connection = snowflake.createConnection(connOption.externalBrowserWithShortTimeout); - - connection.connectAsync(function (err) { - try { - const browserActionTimeout = connOption.externalBrowserWithShortTimeout.browserActionTimeout; - assert.ok(err, `Browser action timed out after ${browserActionTimeout} ms.`); - done(); - } catch (err) { - done(err); - } - }); - }); - - it('Mismatched Username', function (done) { - var connection = snowflake.createConnection(connOption.externalBrowserMismatchUser); - connection.connectAsync(function (err) { - try { - assert.ok(err, 'Logged in with different user than one on connection string'); - assert.equal('The user you were trying to authenticate as differs from the user currently logged in at the IDP.', err['message']); - done(); - } catch (err) { - done(err); - } +}); + +describe("Connection test - validate default parameters", function () { + it('Valid "warehouse" parameter', function () { + const output = stderr.inspectSync(() => { + snowflake.createConnection({ + account: connOption.valid.account, + username: connOption.valid.username, + password: connOption.valid.password, + warehouse: "testWarehouse", + validateDefaultParameters: true, }); }); + assert.deepEqual(output, []); }); - describe.skip('Connection test - keypair', function () - { - it('Simple Connect - specify private key', function (done) - { - var connection = snowflake.createConnection(connOption.keypairPrivateKey); - - async.series([ - function (callback) - { - connection.connect(function (err) - { - done(err); - assert.ok(!err, JSON.stringify(err)); - callback(); - }); - }, - function (callback) - { - assert.ok(connection.isUp(), "not active"); - callback(); - }, - function (callback) - { - connection.destroy(function (err) - { - assert.ok(!err, JSON.stringify(err)); - callback(); - }); - }, - function (callback) - { - assert.ok(!connection.isUp(), "still active"); - callback(); - }, - ], - ); - }); - - it.skip('Simple Connect - specify encrypted private key path and passphrase', function (done) - { - var connection = snowflake.createConnection(connOption.keypairPathEncrypted); - - async.series([ - function (callback) - { - connection.connect(function (err) - { - done(err); - assert.ok(!err, JSON.stringify(err)); - callback(); - }); - }, - function (callback) - { - assert.ok(connection.isUp(), "not active"); - callback(); - }, - function (callback) - { - connection.destroy(function (err) - { - assert.ok(!err, JSON.stringify(err)); - callback(); - }); - }, - function (callback) - { - assert.ok(!connection.isUp(), "still active"); - callback(); - }, - ], - ); - }); - - it.skip('Simple Connect - specify unencrypted private key path without passphrase', function (done) - { - var connection = snowflake.createConnection(connOption.keypairPathEncrypted); - - async.series([ - function (callback) - { - connection.connect(function (err) - { - done(err); - assert.ok(!err, JSON.stringify(err)); - callback(); - }); - }, - function (callback) - { - assert.ok(connection.isUp(), "not active"); - callback(); - }, - function (callback) - { - connection.destroy(function (err) - { - assert.ok(!err, JSON.stringify(err)); - callback(); - }); - }, - function (callback) - { - assert.ok(!connection.isUp(), "still active"); - callback(); - }, - ], - ); - }); - - it('Wrong JWT token', function (done) - { - var connection = snowflake.createConnection(connOption.keypairWrongToken); - connection.connect(function (err) - { - try - { - assert.ok(err, 'Incorrect JWT token is passed.'); - assert.equal('JWT token is invalid.', err["message"]); - done(); - } - catch (err) - { - done(err); - } - }) + it('Invalid "warehouse" parameter', function () { + const output = stderr.inspectSync(() => { + snowflake.createConnection({ + account: connOption.valid.account, + username: connOption.valid.username, + password: connOption.valid.password, + waerhouse: "testWarehouse", + validateDefaultParameters: true, + }); }); + assert.deepEqual(output, [ + '"waerhouse" is an unknown connection parameter\n', + 'Did you mean "warehouse"\n', + ]); }); - // Skipped - requires manual interaction to obtain oauth token - describe.skip('Connection test - oauth', function () - { - it('Simple Connect', function (done) - { - var connection = snowflake.createConnection(connOption.oauth); - - async.series([ - function (callback) - { - connection.connect(function (err) - { - done(err); - assert.ok(!err, JSON.stringify(err)); - callback(); - }); - }, - function (callback) - { - assert.ok(connection.isUp(), "not active"); - callback(); - }, - function (callback) - { - connection.destroy(function (err) - { - assert.ok(!err, JSON.stringify(err)); - callback(); - }); - }, - function (callback) - { - assert.ok(!connection.isUp(), "still active"); - callback(); - }, - ], - ); - }); - - it('Mismatched Username', function (done) - { - var connection = snowflake.createConnection(connOption.oauthMismatchUser); - connection.connect(function (err) - { - try - { - assert.ok(err, 'Logged in with different user than one on connection string'); - assert.equal('The user you were trying to authenticate as differs from the user tied to the access token.', err["message"]); - done(); - } - catch (err) - { - done(err); - } - }) + it('Valid "database" parameter', function () { + const output = stderr.inspectSync(() => { + snowflake.createConnection({ + account: connOption.valid.account, + username: connOption.valid.username, + password: connOption.valid.password, + database: "testDatabase", + validateDefaultParameters: true, + }); }); + assert.deepEqual(output, []); }); - describe.skip('Connection test - okta', function () - { - it('Simple Connect', function (done) - { - var connection = snowflake.createConnection(connOption.okta); - - async.series([ - function (callback) - { - connection.connectAsync(function (err) - { - done(err); - assert.ok(!err, JSON.stringify(err)); - callback(); - }); - }, - function (callback) - { - assert.ok(connection.isUp(), "not active"); - callback(); - }, - function (callback) - { - connection.destroy(function (err) - { - assert.ok(!err, JSON.stringify(err)); - callback(); - }); - }, - function (callback) - { - assert.ok(!connection.isUp(), "still active"); - callback(); - }, - ], - ); + it('Invalid "db" parameter', function () { + const output = stderr.inspectSync(() => { + snowflake.createConnection({ + account: connOption.valid.account, + username: connOption.valid.username, + password: connOption.valid.password, + db: "testDb", + validateDefaultParameters: true, + }); }); + assert.deepEqual(output, ['"db" is an unknown connection parameter\n']); }); - describe('Connection test - validate default parameters', function () - { - it('Valid "warehouse" parameter', function () - { - const output = stderr.inspectSync(() => - { - snowflake.createConnection({ - account: connOption.valid.account, - username: connOption.valid.username, - password: connOption.valid.password, - warehouse: 'testWarehouse', - validateDefaultParameters: true - }); + it('Invalid "database" parameter', function () { + const output = stderr.inspectSync(() => { + snowflake.createConnection({ + account: connOption.valid.account, + username: connOption.valid.username, + password: connOption.valid.password, + datbse: "testDatabase", + validateDefaultParameters: true, }); - assert.deepEqual(output, []); }); + assert.deepEqual(output, [ + '"datbse" is an unknown connection parameter\n', + 'Did you mean "database"\n', + ]); + }); - it('Invalid "warehouse" parameter', function () - { - const output = stderr.inspectSync(() => - { - snowflake.createConnection({ - account: connOption.valid.account, - username: connOption.valid.username, - password: connOption.valid.password, - waerhouse: 'testWarehouse', - validateDefaultParameters: true - }); + it('Valid "schema" parameter', function () { + const output = stderr.inspectSync(() => { + snowflake.createConnection({ + account: connOption.valid.account, + username: connOption.valid.username, + password: connOption.valid.password, + schema: "testSchema", + validateDefaultParameters: true, }); - assert.deepEqual(output, - [ - "\"waerhouse\" is an unknown connection parameter\n", - "Did you mean \"warehouse\"\n" - ]); }); + assert.deepEqual(output, []); + }); - it('Valid "database" parameter', function () - { - const output = stderr.inspectSync(() => - { - snowflake.createConnection({ - account: connOption.valid.account, - username: connOption.valid.username, - password: connOption.valid.password, - database: 'testDatabase', - validateDefaultParameters: true - }); + it('Invalid "schema" parameter', function () { + const output = stderr.inspectSync(() => { + snowflake.createConnection({ + account: connOption.valid.account, + username: connOption.valid.username, + password: connOption.valid.password, + shcema: "testSchema", + validateDefaultParameters: true, }); - assert.deepEqual(output, []); }); + assert.deepEqual(output, [ + '"shcema" is an unknown connection parameter\n', + 'Did you mean "schema"\n', + ]); + }); +}); - it('Invalid "db" parameter', function () - { - const output = stderr.inspectSync(() => - { - snowflake.createConnection({ - account: connOption.valid.account, - username: connOption.valid.username, - password: connOption.valid.password, - db: 'testDb', - validateDefaultParameters: true - }); - }); - assert.deepEqual(output, - [ - "\"db\" is an unknown connection parameter\n" - ]); - }); +describe("Connection test - connection pool", function () { + this.timeout(30000); - it('Invalid "database" parameter', function () - { - const output = stderr.inspectSync(() => - { - snowflake.createConnection({ - account: connOption.valid.account, - username: connOption.valid.username, - password: connOption.valid.password, - datbse: 'testDatabase', - validateDefaultParameters: true - }); - }); - assert.deepEqual(output, - [ - "\"datbse\" is an unknown connection parameter\n", - "Did you mean \"database\"\n" - ]); + it("1 min connection", function (done) { + var connectionPool = snowflake.createPool(connOption.valid, { + max: 10, + min: 1, }); - it('Valid "schema" parameter', function () - { - const output = stderr.inspectSync(() => - { - snowflake.createConnection({ - account: connOption.valid.account, - username: connOption.valid.username, - password: connOption.valid.password, - schema: 'testSchema', - validateDefaultParameters: true - }); - }); - assert.deepEqual(output, []); - }); + assert.equal(connectionPool.max, 10); + assert.equal(connectionPool.min, 1); + assert.equal(connectionPool.size, 1); - it('Invalid "schema" parameter', function () - { - const output = stderr.inspectSync(() => - { - snowflake.createConnection({ - account: connOption.valid.account, - username: connOption.valid.username, - password: connOption.valid.password, - shcema: 'testSchema', - validateDefaultParameters: true - }); - }); - assert.deepEqual(output, - [ - "\"shcema\" is an unknown connection parameter\n", - "Did you mean \"schema\"\n" - ]); - }); + done(); }); - describe('Connection test - connection pool', function () - { - this.timeout(30000); - - it('1 min connection', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 10, - min: 1 - }); - - assert.equal(connectionPool.max, 10); - assert.equal(connectionPool.min, 1); - assert.equal(connectionPool.size, 1); - - done(); + it("5 min connection", function (done) { + var connectionPool = snowflake.createPool(connOption.valid, { + max: 10, + min: 5, }); - it('5 min connection', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 10, - min: 5 - }); + assert.equal(connectionPool.max, 10); + assert.equal(connectionPool.min, 5); + assert.equal(connectionPool.size, 5); - assert.equal(connectionPool.max, 10); - assert.equal(connectionPool.min, 5); - assert.equal(connectionPool.size, 5); + done(); + }); - done(); + it("10 min connection", function (done) { + var connectionPool = snowflake.createPool(connOption.valid, { + max: 10, + min: 10, }); - it('10 min connection', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 10, - min: 10 - }); + assert.equal(connectionPool.max, 10); + assert.equal(connectionPool.min, 10); + assert.equal(connectionPool.size, 10); - assert.equal(connectionPool.max, 10); - assert.equal(connectionPool.min, 10); - assert.equal(connectionPool.size, 10); + done(); + }); - done(); + it("min greater than max connection", function (done) { + var connectionPool = snowflake.createPool(connOption.valid, { + max: 5, + min: 10, }); - it('min greater than max connection', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 5, - min: 10 - }); + assert.equal(connectionPool.max, 5); + assert.equal(connectionPool.min, 5); + assert.equal(connectionPool.size, 5); - assert.equal(connectionPool.max, 5); - assert.equal(connectionPool.min, 5); - assert.equal(connectionPool.size, 5); + done(); + }); - done(); + it("1 max connection", function (done) { + var connectionPool = snowflake.createPool(connOption.valid, { + max: 1, + min: 0, }); - it('1 max connection', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 1, - min: 0 - }); + assert.equal(connectionPool.max, 1); + assert.equal(connectionPool.min, 0); - assert.equal(connectionPool.max, 1); - assert.equal(connectionPool.min, 0); + // Acquire a connection + const resourcePromise1 = connectionPool.acquire(); + assert.equal(connectionPool.size, 1); - // Acquire a connection - const resourcePromise1 = connectionPool.acquire(); - assert.equal(connectionPool.size, 1); + done(); + }); - done(); + it("1 max connection and acquire() more than 1", function (done) { + var connectionPool = snowflake.createPool(connOption.valid, { + max: 1, + min: 0, }); - it('1 max connection and acquire() more than 1', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 1, - min: 0 - }); + assert.equal(connectionPool.max, 1); + assert.equal(connectionPool.min, 0); - assert.equal(connectionPool.max, 1); - assert.equal(connectionPool.min, 0); + // Acquire 2 connections + const resourcePromise1 = connectionPool.acquire(); + assert.equal(connectionPool.size, 1); + const resourcePromise2 = connectionPool.acquire(); + assert.equal(connectionPool.size, 1); - // Acquire 2 connections - const resourcePromise1 = connectionPool.acquire(); - assert.equal(connectionPool.size, 1); - const resourcePromise2 = connectionPool.acquire(); - assert.equal(connectionPool.size, 1); + done(); + }); - done(); + it("5 max connection", function (done) { + var connectionPool = snowflake.createPool(connOption.valid, { + max: 5, + min: 0, }); - it('5 max connection', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 5, - min: 0 - }); + assert.equal(connectionPool.max, 5); + assert.equal(connectionPool.min, 0); - assert.equal(connectionPool.max, 5); - assert.equal(connectionPool.min, 0); - - // Acquire 5 connections - const resourcePromise1 = connectionPool.acquire(); - assert.equal(connectionPool.size, 1); - const resourcePromise2 = connectionPool.acquire(); - assert.equal(connectionPool.size, 2); - const resourcePromise3 = connectionPool.acquire(); - assert.equal(connectionPool.size, 3); - const resourcePromise4 = connectionPool.acquire(); - assert.equal(connectionPool.size, 4); - const resourcePromise5 = connectionPool.acquire(); - assert.equal(connectionPool.size, 5); + // Acquire 5 connections + const resourcePromise1 = connectionPool.acquire(); + assert.equal(connectionPool.size, 1); + const resourcePromise2 = connectionPool.acquire(); + assert.equal(connectionPool.size, 2); + const resourcePromise3 = connectionPool.acquire(); + assert.equal(connectionPool.size, 3); + const resourcePromise4 = connectionPool.acquire(); + assert.equal(connectionPool.size, 4); + const resourcePromise5 = connectionPool.acquire(); + assert.equal(connectionPool.size, 5); - done(); - }); - - it('5 max connections and acquire() more than 5', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 5, - min: 0 - }); - - assert.equal(connectionPool.max, 5); - assert.equal(connectionPool.min, 0); - - // Acquire 6 connections - const resourcePromise1 = connectionPool.acquire(); - assert.equal(connectionPool.size, 1); - const resourcePromise2 = connectionPool.acquire(); - assert.equal(connectionPool.size, 2); - const resourcePromise3 = connectionPool.acquire(); - assert.equal(connectionPool.size, 3); - const resourcePromise4 = connectionPool.acquire(); - assert.equal(connectionPool.size, 4); - const resourcePromise5 = connectionPool.acquire(); - assert.equal(connectionPool.size, 5); - const resourcePromise6 = connectionPool.acquire(); - assert.equal(connectionPool.size, 5); + done(); + }); - done(); - }); + it("5 max connections and acquire() more than 5", function (done) { + var connectionPool = snowflake.createPool(connOption.valid, { + max: 5, + min: 0, + }); + + assert.equal(connectionPool.max, 5); + assert.equal(connectionPool.min, 0); + + // Acquire 6 connections + const resourcePromise1 = connectionPool.acquire(); + assert.equal(connectionPool.size, 1); + const resourcePromise2 = connectionPool.acquire(); + assert.equal(connectionPool.size, 2); + const resourcePromise3 = connectionPool.acquire(); + assert.equal(connectionPool.size, 3); + const resourcePromise4 = connectionPool.acquire(); + assert.equal(connectionPool.size, 4); + const resourcePromise5 = connectionPool.acquire(); + assert.equal(connectionPool.size, 5); + const resourcePromise6 = connectionPool.acquire(); + assert.equal(connectionPool.size, 5); + + done(); + }); - it('10 max connection', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 10, - min: 0 - }); + it("10 max connection", function (done) { + var connectionPool = snowflake.createPool(connOption.valid, { + max: 10, + min: 0, + }); + + assert.equal(connectionPool.max, 10); + assert.equal(connectionPool.min, 0); + + // Acquire 10 connections + const resourcePromise1 = connectionPool.acquire(); + assert.equal(connectionPool.size, 1); + const resourcePromise2 = connectionPool.acquire(); + assert.equal(connectionPool.size, 2); + const resourcePromise3 = connectionPool.acquire(); + assert.equal(connectionPool.size, 3); + const resourcePromise4 = connectionPool.acquire(); + assert.equal(connectionPool.size, 4); + const resourcePromise5 = connectionPool.acquire(); + assert.equal(connectionPool.size, 5); + const resourcePromise6 = connectionPool.acquire(); + assert.equal(connectionPool.size, 6); + const resourcePromise7 = connectionPool.acquire(); + assert.equal(connectionPool.size, 7); + const resourcePromise8 = connectionPool.acquire(); + assert.equal(connectionPool.size, 8); + const resourcePromise9 = connectionPool.acquire(); + assert.equal(connectionPool.size, 9); + const resourcePromise10 = connectionPool.acquire(); + assert.equal(connectionPool.size, 10); + + done(); + }); - assert.equal(connectionPool.max, 10); - assert.equal(connectionPool.min, 0); - - // Acquire 10 connections - const resourcePromise1 = connectionPool.acquire(); - assert.equal(connectionPool.size, 1); - const resourcePromise2 = connectionPool.acquire(); - assert.equal(connectionPool.size, 2); - const resourcePromise3 = connectionPool.acquire(); - assert.equal(connectionPool.size, 3); - const resourcePromise4 = connectionPool.acquire(); - assert.equal(connectionPool.size, 4); - const resourcePromise5 = connectionPool.acquire(); - assert.equal(connectionPool.size, 5); - const resourcePromise6 = connectionPool.acquire(); - assert.equal(connectionPool.size, 6); - const resourcePromise7 = connectionPool.acquire(); - assert.equal(connectionPool.size, 7); - const resourcePromise8 = connectionPool.acquire(); - assert.equal(connectionPool.size, 8); - const resourcePromise9 = connectionPool.acquire(); - assert.equal(connectionPool.size, 9); - const resourcePromise10 = connectionPool.acquire(); - assert.equal(connectionPool.size, 10); + it("10 max connections and acquire() more than 10", function (done) { + var connectionPool = snowflake.createPool(connOption.valid, { + max: 10, + min: 0, + }); + + assert.equal(connectionPool.max, 10); + assert.equal(connectionPool.min, 0); + + // Acquire 11 connections + const resourcePromise1 = connectionPool.acquire(); + assert.equal(connectionPool.size, 1); + const resourcePromise2 = connectionPool.acquire(); + assert.equal(connectionPool.size, 2); + const resourcePromise3 = connectionPool.acquire(); + assert.equal(connectionPool.size, 3); + const resourcePromise4 = connectionPool.acquire(); + assert.equal(connectionPool.size, 4); + const resourcePromise5 = connectionPool.acquire(); + assert.equal(connectionPool.size, 5); + const resourcePromise6 = connectionPool.acquire(); + assert.equal(connectionPool.size, 6); + const resourcePromise7 = connectionPool.acquire(); + assert.equal(connectionPool.size, 7); + const resourcePromise8 = connectionPool.acquire(); + assert.equal(connectionPool.size, 8); + const resourcePromise9 = connectionPool.acquire(); + assert.equal(connectionPool.size, 9); + const resourcePromise10 = connectionPool.acquire(); + assert.equal(connectionPool.size, 10); + const resourcePromise11 = connectionPool.acquire(); + assert.equal(connectionPool.size, 10); + + done(); + }); - done(); + it("acquire() 1 connection and release()", function (done) { + var connectionPool = snowflake.createPool(connOption.valid, { + max: 5, + min: 0, }); - it('10 max connections and acquire() more than 10', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 10, - min: 0 - }); - - assert.equal(connectionPool.max, 10); - assert.equal(connectionPool.min, 0); - - // Acquire 11 connections - const resourcePromise1 = connectionPool.acquire(); - assert.equal(connectionPool.size, 1); - const resourcePromise2 = connectionPool.acquire(); - assert.equal(connectionPool.size, 2); - const resourcePromise3 = connectionPool.acquire(); - assert.equal(connectionPool.size, 3); - const resourcePromise4 = connectionPool.acquire(); - assert.equal(connectionPool.size, 4); - const resourcePromise5 = connectionPool.acquire(); - assert.equal(connectionPool.size, 5); - const resourcePromise6 = connectionPool.acquire(); - assert.equal(connectionPool.size, 6); - const resourcePromise7 = connectionPool.acquire(); - assert.equal(connectionPool.size, 7); - const resourcePromise8 = connectionPool.acquire(); - assert.equal(connectionPool.size, 8); - const resourcePromise9 = connectionPool.acquire(); - assert.equal(connectionPool.size, 9); - const resourcePromise10 = connectionPool.acquire(); - assert.equal(connectionPool.size, 10); - const resourcePromise11 = connectionPool.acquire(); - assert.equal(connectionPool.size, 10); + // Acquire one connection + const resourcePromise1 = connectionPool.acquire(); - done(); - }); + assert.equal(connectionPool.size, 1); + assert.equal(connectionPool.pending, 1); + assert.equal(connectionPool.spareResourceCapacity, 4); - it('acquire() 1 connection and release()', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 5, - min: 0 - }); + async.series( + [ + function (callback) { + // Once acquired, release the connection + resourcePromise1.then(function (connection) { + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.pending, 0); - // Acquire one connection - const resourcePromise1 = connectionPool.acquire(); - - assert.equal(connectionPool.size, 1); - assert.equal(connectionPool.pending, 1); - assert.equal(connectionPool.spareResourceCapacity, 4); - - async.series( - [ - function (callback) - { - // Once acquired, release the connection - resourcePromise1.then(function (connection) - { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.pending, 0); - - connectionPool.release(connection).then(() => - { - // One connection should be available for use - assert.equal(connectionPool.available, 1); - callback(); - }); + connectionPool.release(connection).then(() => { + // One connection should be available for use + assert.equal(connectionPool.available, 1); + callback(); }); - } - ], - done); - }); + }); + }, + ], + done + ); + }); - it('acquire() 5 connections and release()', function (done) - { - // Create the connection pool - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 5, - min: 0 - }); + it("acquire() 5 connections and release()", function (done) { + // Create the connection pool + var connectionPool = snowflake.createPool(connOption.valid, { + max: 5, + min: 0, + }); + + // Acquire 5 connections + const resourcePromise1 = connectionPool.acquire(); + const resourcePromise2 = connectionPool.acquire(); + const resourcePromise3 = connectionPool.acquire(); + const resourcePromise4 = connectionPool.acquire(); + const resourcePromise5 = connectionPool.acquire(); + + assert.equal(connectionPool.size, 5); + assert.equal(connectionPool.pending, 5); + assert.equal(connectionPool.spareResourceCapacity, 0); + + async.series( + [ + function (callback) { + // Once acquired, release the connection + resourcePromise1.then(function (connection) { + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.pending, 4); - // Acquire 5 connections - const resourcePromise1 = connectionPool.acquire(); - const resourcePromise2 = connectionPool.acquire(); - const resourcePromise3 = connectionPool.acquire(); - const resourcePromise4 = connectionPool.acquire(); - const resourcePromise5 = connectionPool.acquire(); - - assert.equal(connectionPool.size, 5); - assert.equal(connectionPool.pending, 5); - assert.equal(connectionPool.spareResourceCapacity, 0); - - async.series( - [ - function (callback) - { - // Once acquired, release the connection - resourcePromise1.then(function (connection) - { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.pending, 4); - - connectionPool.release(connection).then(() => - { - assert.equal(connectionPool.available, 0); - callback(); - }); + connectionPool.release(connection).then(() => { + assert.equal(connectionPool.available, 0); + callback(); }); - }, - function (callback) - { - // Once acquired, release the connection - resourcePromise2.then(function (connection) - { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.pending, 3); - - connectionPool.release(connection).then(() => - { - assert.equal(connectionPool.available, 0); - callback(); - }); + }); + }, + function (callback) { + // Once acquired, release the connection + resourcePromise2.then(function (connection) { + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.pending, 3); + + connectionPool.release(connection).then(() => { + assert.equal(connectionPool.available, 0); + callback(); }); - }, - function (callback) - { - // Once acquired, release the connection - resourcePromise3.then(function (connection) - { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.pending, 2); - - connectionPool.release(connection).then(() => - { - assert.equal(connectionPool.available, 0); - callback(); - }); + }); + }, + function (callback) { + // Once acquired, release the connection + resourcePromise3.then(function (connection) { + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.pending, 2); + + connectionPool.release(connection).then(() => { + assert.equal(connectionPool.available, 0); + callback(); }); - }, - function (callback) - { - // Once acquired, release the connection - resourcePromise4.then(function (connection) - { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.pending, 1); - - connectionPool.release(connection).then(() => - { - assert.equal(connectionPool.available, 0); - callback(); - }); + }); + }, + function (callback) { + // Once acquired, release the connection + resourcePromise4.then(function (connection) { + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.pending, 1); + + connectionPool.release(connection).then(() => { + assert.equal(connectionPool.available, 0); + callback(); }); - }, - function (callback) - { - // Once acquired, release the connection - resourcePromise5.then(function (connection) - { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.pending, 0); - - connectionPool.release(connection).then(() => - { - assert.equal(connectionPool.available, 1); - callback(); - }); + }); + }, + function (callback) { + // Once acquired, release the connection + resourcePromise5.then(function (connection) { + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.pending, 0); + + connectionPool.release(connection).then(() => { + assert.equal(connectionPool.available, 1); + callback(); }); - }, - ], - done); - }); + }); + }, + ], + done + ); + }); - it('acquire() 1 connection and destroy()', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 5, - min: 0 - }); + it("acquire() 1 connection and destroy()", function (done) { + var connectionPool = snowflake.createPool(connOption.valid, { + max: 5, + min: 0, + }); - // Acquire a connection - const resourcePromise1 = connectionPool.acquire(); + // Acquire a connection + const resourcePromise1 = connectionPool.acquire(); - assert.equal(connectionPool.size, 1); - assert.equal(connectionPool.pending, 1); - assert.equal(connectionPool.spareResourceCapacity, 4); + assert.equal(connectionPool.size, 1); + assert.equal(connectionPool.pending, 1); + assert.equal(connectionPool.spareResourceCapacity, 4); - // Once acquired, destroy the connection - resourcePromise1.then(function (connection) - { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.pending, 0); + // Once acquired, destroy the connection + resourcePromise1.then(function (connection) { + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.pending, 0); - connectionPool.destroy(connection).then(() => - { - // No connection should be available for use - assert.equal(connectionPool.available, 0); - done(); - }); + connectionPool.destroy(connection).then(() => { + // No connection should be available for use + assert.equal(connectionPool.available, 0); + done(); }); }); + }); + + it("acquire() 5 connections and destroy()", function (done) { + var connectionPool = snowflake.createPool(connOption.valid, { + max: 5, + min: 0, + }); - it('acquire() 5 connections and destroy()', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 5, - min: 0 - }); + // Acquire 5 connections + const resourcePromise1 = connectionPool.acquire(); + const resourcePromise2 = connectionPool.acquire(); + const resourcePromise3 = connectionPool.acquire(); + const resourcePromise4 = connectionPool.acquire(); + const resourcePromise5 = connectionPool.acquire(); + + assert.equal(connectionPool.size, 5); + assert.equal(connectionPool.pending, 5); + assert.equal(connectionPool.spareResourceCapacity, 0); + + async.series( + [ + function (callback) { + // Once acquired, destroy the connection + resourcePromise1.then(function (connection) { + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.pending, 4); - // Acquire 5 connections - const resourcePromise1 = connectionPool.acquire(); - const resourcePromise2 = connectionPool.acquire(); - const resourcePromise3 = connectionPool.acquire(); - const resourcePromise4 = connectionPool.acquire(); - const resourcePromise5 = connectionPool.acquire(); - - assert.equal(connectionPool.size, 5); - assert.equal(connectionPool.pending, 5); - assert.equal(connectionPool.spareResourceCapacity, 0); - - async.series( - [ - function (callback) - { - // Once acquired, destroy the connection - resourcePromise1.then(function (connection) - { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.pending, 4); - - connectionPool.destroy(connection).then(() => - { - assert.equal(connectionPool.available, 0); - callback(); - }); + connectionPool.destroy(connection).then(() => { + assert.equal(connectionPool.available, 0); + callback(); }); - }, - function (callback) - { - // Once acquired, destroy the connection - resourcePromise2.then(function (connection) - { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.pending, 3); - - connectionPool.destroy(connection).then(() => - { - assert.equal(connectionPool.available, 0); - callback(); - }); + }); + }, + function (callback) { + // Once acquired, destroy the connection + resourcePromise2.then(function (connection) { + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.pending, 3); + + connectionPool.destroy(connection).then(() => { + assert.equal(connectionPool.available, 0); + callback(); }); - }, - function (callback) - { - // Once acquired, destroy the connection - resourcePromise3.then(function (connection) - { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.pending, 2); - - connectionPool.destroy(connection).then(() => - { - assert.equal(connectionPool.available, 0); - callback(); - }); + }); + }, + function (callback) { + // Once acquired, destroy the connection + resourcePromise3.then(function (connection) { + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.pending, 2); + + connectionPool.destroy(connection).then(() => { + assert.equal(connectionPool.available, 0); + callback(); }); - }, - function (callback) - { - // Once acquired, destroy the connection - resourcePromise4.then(function (connection) - { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.pending, 1); - - connectionPool.destroy(connection).then(() => - { - assert.equal(connectionPool.available, 0); - callback(); - }); + }); + }, + function (callback) { + // Once acquired, destroy the connection + resourcePromise4.then(function (connection) { + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.pending, 1); + + connectionPool.destroy(connection).then(() => { + assert.equal(connectionPool.available, 0); + callback(); }); - }, - function (callback) - { - // Once acquired, destroy the connection - resourcePromise5.then(function (connection) - { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.pending, 0); - - connectionPool.destroy(connection).then(() => - { - assert.equal(connectionPool.available, 0); - callback(); - }); + }); + }, + function (callback) { + // Once acquired, destroy the connection + resourcePromise5.then(function (connection) { + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.pending, 0); + + connectionPool.destroy(connection).then(() => { + assert.equal(connectionPool.available, 0); + callback(); }); - }, - ], - done); - }); + }); + }, + ], + done + ); + }); - it('use()', function (done) - { - var connectionPool = snowflake.createPool(connOption.valid, - { - max: 5, - min: 0 - }); + it("use()", function (done) { + var connectionPool = snowflake.createPool(connOption.valid, { + max: 5, + min: 0, + }); - assert.equal(connectionPool.size, 0); + assert.equal(connectionPool.size, 0); - // Use the connection pool, automatically creates a new connection - connectionPool.use(async (connection) => - { + // Use the connection pool, automatically creates a new connection + connectionPool + .use(async (connection) => { assert.ok(connection.isUp(), "not active"); assert.equal(connectionPool.size, 1); assert.equal(connectionPool.pending, 0); assert.equal(connectionPool.spareResourceCapacity, 4); assert.equal(connectionPool.available, 0); - }).then(() => - { + }) + .then(() => { assert.equal(connectionPool.size, 1); assert.equal(connectionPool.available, 1); // Use the connection pool, will use the existing connection - connectionPool.use(async (connection) => - { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.size, 1); - assert.equal(connectionPool.pending, 0); - assert.equal(connectionPool.spareResourceCapacity, 4); - assert.equal(connectionPool.available, 0); - }).then(() => - { - assert.equal(connectionPool.size, 1); - assert.equal(connectionPool.available, 1); - done(); - }); + connectionPool + .use(async (connection) => { + assert.ok(connection.isUp(), "not active"); + assert.equal(connectionPool.size, 1); + assert.equal(connectionPool.pending, 0); + assert.equal(connectionPool.spareResourceCapacity, 4); + assert.equal(connectionPool.available, 0); + }) + .then(() => { + assert.equal(connectionPool.size, 1); + assert.equal(connectionPool.available, 1); + done(); + }); }); - }); - - it('wrong password - use', async function () - { - var connectionPool = snowflake.createPool(connOption.wrongPwd, - { - max: 10, - min: 1 - }); + }); - assert.equal(connectionPool.max, 10); - assert.equal(connectionPool.min, 1); - assert.equal(connectionPool.size, 1); - - try - { - // Use the connection pool, automatically creates a new connection - await connectionPool.use(async (connection) => - { - assert.ok(connection.isUp(), "not active"); - assert.equal(connectionPool.size, 1); - }); - } - catch (err) - { - assert.strictEqual(err.message, "Incorrect username or password was specified."); - } + it("wrong password - use", async function () { + var connectionPool = snowflake.createPool(connOption.wrongPwd, { + max: 10, + min: 1, }); - it('wrong password - acquire', async function () - { - var connectionPool = snowflake.createPool(connOption.wrongPwd, - { - max: 10, - min: 1 - }); + assert.equal(connectionPool.max, 10); + assert.equal(connectionPool.min, 1); + assert.equal(connectionPool.size, 1); - assert.equal(connectionPool.max, 10); - assert.equal(connectionPool.min, 1); + try { + // Use the connection pool, automatically creates a new connection + await connectionPool.use(async (connection) => { + assert.ok(connection.isUp(), "not active"); assert.equal(connectionPool.size, 1); - - try - { - await connectionPool.acquire(); - } - catch (err) - { - assert.strictEqual(err.message, "Incorrect username or password was specified."); - } }); + } catch (err) { + assert.strictEqual( + err.message, + "Incorrect username or password was specified." + ); + } }); - describe('Connection Test - Heartbeat', () => - { - let connection; - - before(async () => - { - connection = snowflake.createConnection(connOption.valid); - await testUtil.connectAsync(connection); + it("wrong password - acquire", async function () { + var connectionPool = snowflake.createPool(connOption.wrongPwd, { + max: 10, + min: 1, }); - after(async () => - { - await testUtil.destroyConnectionAsync(connection); - }); + assert.equal(connectionPool.max, 10); + assert.equal(connectionPool.min, 1); + assert.equal(connectionPool.size, 1); - it('call heartbeat url with default callback', () => - { - connection.heartbeat(); - }); + try { + await connectionPool.acquire(); + } catch (err) { + assert.strictEqual( + err.message, + "Incorrect username or password was specified." + ); + } + }); +}); - it('call heartbeat url with callback', done => - { - connection.heartbeat(err => err ? done(err) : done()); - }); +describe("Connection Test - Heartbeat", () => { + let connection; - it('call heartbeat url as promise', async () => - { - const rows = await connection.heartbeatAsync(); - assert.deepEqual(rows, [ { '1': 1 } ]); - }); + before(async () => { + connection = snowflake.createConnection(connOption.valid); + await testUtil.connectAsync(connection); }); - describe('Connection Test - isValid', () => - { - let connection; + after(async () => { + await testUtil.destroyConnectionAsync(connection); + }); - beforeEach(async () => - { - connection = snowflake.createConnection(connOption.valid); - await testUtil.connectAsync(connection); - }); + it("call heartbeat url with default callback", () => { + connection.heartbeat(); + }); - afterEach(async () => - { - if (connection.isUp()) - { - await testUtil.destroyConnectionAsync(connection); - } - }); + it("call heartbeat url with callback", (done) => { + connection.heartbeat((err) => (err ? done(err) : done())); + }); - it('connection is valid after connect', async () => - { - const result = await connection.isValidAsync(); + it("call heartbeat url as promise", async () => { + const rows = await connection.heartbeatAsync(); + assert.deepEqual(rows, [{ 1: 1 }]); + }); +}); - assert.equal(result, true); - }); +describe("Connection Test - isValid", () => { + let connection; - it('connection is invalid after destroy', async () => - { + beforeEach(async () => { + connection = snowflake.createConnection(connOption.valid); + await testUtil.connectAsync(connection); + }); + + afterEach(async () => { + if (connection.isUp()) { await testUtil.destroyConnectionAsync(connection); + } + }); - const result = await connection.isValidAsync(); + it("connection is valid after connect", async () => { + const result = await connection.isValidAsync(); - assert.equal(result, false); - }); + assert.equal(result, true); + }); + + it("connection is invalid after destroy", async () => { + await testUtil.destroyConnectionAsync(connection); - // there is no way to test heartbeat fail to running instance of snowflake + const result = await connection.isValidAsync(); + + assert.equal(result, false); }); -} + + // there is no way to test heartbeat fail to running instance of snowflake +}); diff --git a/test/integration/testManualConnection.js b/test/integration/testManualConnection.js new file mode 100644 index 000000000..4b7c88bbd --- /dev/null +++ b/test/integration/testManualConnection.js @@ -0,0 +1,404 @@ +const snowflake = require("./../../lib/snowflake"); +const async = require("async"); +const assert = require("assert"); +const connOption = require("./connectionOptions"); +const testUtil = require("./testUtil"); + +if (process.env.RUN_MANUAL_TESTS_ONLY == "true") { + describe.only("Run manual tests", function () { + describe("Connection test - external browser", function () { + it("Simple Connect", function (done) { + const connection = snowflake.createConnection( + connOption.externalBrowser + ); + + connection.connectAsync(function (err, connection) { + try { + assert.ok(connection.isUp(), "not active"); + testUtil.destroyConnection(connection, function (err, r) { + try { + assert.ok(!connection.isUp(), "not active"); + done(); + } catch (err) { + done(err); + } + }); + } catch (err) { + done(err); + } + }); + }); + + it("Connect - external browser timeout", function (done) { + const connection = snowflake.createConnection( + connOption.externalBrowserWithShortTimeout + ); + + connection.connectAsync(function (err) { + try { + const browserActionTimeout = + connOption.externalBrowserWithShortTimeout.browserActionTimeout; + assert.ok( + err, + `Browser action timed out after ${browserActionTimeout} ms.` + ); + done(); + } catch (err) { + done(err); + } + }); + }); + + it("Mismatched Username", function (done) { + var connection = snowflake.createConnection( + connOption.externalBrowserMismatchUser + ); + connection.connectAsync(function (err) { + try { + assert.ok( + err, + "Logged in with different user than one on connection string" + ); + assert.equal( + "The user you were trying to authenticate as differs from the user currently logged in at the IDP.", + err["message"] + ); + done(); + } catch (err) { + done(err); + } + }); + }); + }); + + describe("Connection test - oauth", function () { + it("Simple Connect", function (done) { + var connection = snowflake.createConnection(connOption.oauth); + + async.series([ + function (callback) { + connection.connect(function (err) { + done(err); + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) { + assert.ok(connection.isUp(), "not active"); + callback(); + }, + function (callback) { + connection.destroy(function (err) { + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) { + assert.ok(!connection.isUp(), "still active"); + callback(); + }, + ]); + }); + + it("Mismatched Username", function (done) { + var connection = snowflake.createConnection( + connOption.oauthMismatchUser + ); + connection.connect(function (err) { + try { + assert.ok( + err, + "Logged in with different user than one on connection string" + ); + assert.equal( + "The user you were trying to authenticate as differs from the user tied to the access token.", + err["message"] + ); + done(); + } catch (err) { + done(err); + } + }); + }); + }); + + describe("Connection test - okta", function () { + it("Simple Connect", function (done) { + var connection = snowflake.createConnection(connOption.okta); + + async.series([ + function (callback) { + connection.connectAsync(function (err) { + done(err); + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) { + assert.ok(connection.isUp(), "not active"); + callback(); + }, + function (callback) { + connection.destroy(function (err) { + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) { + assert.ok(!connection.isUp(), "still active"); + callback(); + }, + ]); + }); + }); + }); +} + +// Skipped - requires manual interaction to enter credentials on browser +describe.skip("Connection test - external browser", function () { + this.timeout(10000); + + it("Simple Connect", function (done) { + const connection = snowflake.createConnection(connOption.externalBrowser); + + connection.connectAsync(function (err, connection) { + try { + assert.ok(connection.isUp(), "not active"); + testUtil.destroyConnection(connection, function (err, r) { + try { + assert.ok(!connection.isUp(), "not active"); + done(); + } catch (err) { + done(err); + } + }); + } catch (err) { + done(err); + } + }); + }); + + it("Connect - external browser timeout", function (done) { + const connection = snowflake.createConnection( + connOption.externalBrowserWithShortTimeout + ); + + connection.connectAsync(function (err) { + try { + const browserActionTimeout = + connOption.externalBrowserWithShortTimeout.browserActionTimeout; + assert.ok( + err, + `Browser action timed out after ${browserActionTimeout} ms.` + ); + done(); + } catch (err) { + done(err); + } + }); + }); + + it("Mismatched Username", function (done) { + var connection = snowflake.createConnection( + connOption.externalBrowserMismatchUser + ); + connection.connectAsync(function (err) { + try { + assert.ok( + err, + "Logged in with different user than one on connection string" + ); + assert.equal( + "The user you were trying to authenticate as differs from the user currently logged in at the IDP.", + err["message"] + ); + done(); + } catch (err) { + done(err); + } + }); + }); +}); + +describe.skip("Connection test - keypair", function () { + it("Simple Connect - specify private key", function (done) { + var connection = snowflake.createConnection(connOption.keypairPrivateKey); + + async.series([ + function (callback) { + connection.connect(function (err) { + done(err); + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) { + assert.ok(connection.isUp(), "not active"); + callback(); + }, + function (callback) { + connection.destroy(function (err) { + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) { + assert.ok(!connection.isUp(), "still active"); + callback(); + }, + ]); + }); + + it.skip("Simple Connect - specify encrypted private key path and passphrase", function (done) { + var connection = snowflake.createConnection( + connOption.keypairPathEncrypted + ); + + async.series([ + function (callback) { + connection.connect(function (err) { + done(err); + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) { + assert.ok(connection.isUp(), "not active"); + callback(); + }, + function (callback) { + connection.destroy(function (err) { + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) { + assert.ok(!connection.isUp(), "still active"); + callback(); + }, + ]); + }); + + it.skip("Simple Connect - specify unencrypted private key path without passphrase", function (done) { + var connection = snowflake.createConnection( + connOption.keypairPathEncrypted + ); + + async.series([ + function (callback) { + connection.connect(function (err) { + done(err); + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) { + assert.ok(connection.isUp(), "not active"); + callback(); + }, + function (callback) { + connection.destroy(function (err) { + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) { + assert.ok(!connection.isUp(), "still active"); + callback(); + }, + ]); + }); + + it("Wrong JWT token", function (done) { + var connection = snowflake.createConnection(connOption.keypairWrongToken); + connection.connect(function (err) { + try { + assert.ok(err, "Incorrect JWT token is passed."); + assert.equal("JWT token is invalid.", err["message"]); + done(); + } catch (err) { + done(err); + } + }); + }); +}); + +// Skipped - requires manual interaction to obtain oauth token +describe.skip("Connection test - oauth", function () { + it("Simple Connect", function (done) { + var connection = snowflake.createConnection(connOption.oauth); + + async.series([ + function (callback) { + connection.connect(function (err) { + done(err); + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) { + assert.ok(connection.isUp(), "not active"); + callback(); + }, + function (callback) { + connection.destroy(function (err) { + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) { + assert.ok(!connection.isUp(), "still active"); + callback(); + }, + ]); + }); + + it("Mismatched Username", function (done) { + var connection = snowflake.createConnection(connOption.oauthMismatchUser); + connection.connect(function (err) { + try { + assert.ok( + err, + "Logged in with different user than one on connection string" + ); + assert.equal( + "The user you were trying to authenticate as differs from the user tied to the access token.", + err["message"] + ); + done(); + } catch (err) { + done(err); + } + }); + }); +}); + +describe.skip("Connection test - okta", function () { + it("Simple Connect", function (done) { + var connection = snowflake.createConnection(connOption.okta); + + async.series([ + function (callback) { + connection.connectAsync(function (err) { + done(err); + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) { + assert.ok(connection.isUp(), "not active"); + callback(); + }, + function (callback) { + connection.destroy(function (err) { + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) { + assert.ok(!connection.isUp(), "still active"); + callback(); + }, + ]); + }); +}); From 2033ab2769299d21e17d7fb08ef8fbd391a3f319 Mon Sep 17 00:00:00 2001 From: John Yun Date: Tue, 1 Aug 2023 12:52:37 -0700 Subject: [PATCH 4/5] Moved Skipped test into the if branch for the manual test --- test/integration/testManualConnection.js | 400 ++++++++--------------- 1 file changed, 129 insertions(+), 271 deletions(-) diff --git a/test/integration/testManualConnection.js b/test/integration/testManualConnection.js index 4b7c88bbd..d83ed62cd 100644 --- a/test/integration/testManualConnection.js +++ b/test/integration/testManualConnection.js @@ -1,23 +1,23 @@ -const snowflake = require("./../../lib/snowflake"); -const async = require("async"); -const assert = require("assert"); -const connOption = require("./connectionOptions"); -const testUtil = require("./testUtil"); +const snowflake = require('./../../lib/snowflake'); +const async = require('async'); +const assert = require('assert'); +const connOption = require('./connectionOptions'); +const testUtil = require('./testUtil'); -if (process.env.RUN_MANUAL_TESTS_ONLY == "true") { - describe.only("Run manual tests", function () { - describe("Connection test - external browser", function () { - it("Simple Connect", function (done) { +if (process.env.RUN_MANUAL_TESTS_ONLY == 'true') { + describe.only('Run manual tests', function () { + describe('Connection test - external browser', function () { + it('Simple Connect', function (done) { const connection = snowflake.createConnection( connOption.externalBrowser ); connection.connectAsync(function (err, connection) { try { - assert.ok(connection.isUp(), "not active"); + assert.ok(connection.isUp(), 'not active'); testUtil.destroyConnection(connection, function (err, r) { try { - assert.ok(!connection.isUp(), "not active"); + assert.ok(!connection.isUp(), 'not active'); done(); } catch (err) { done(err); @@ -29,7 +29,7 @@ if (process.env.RUN_MANUAL_TESTS_ONLY == "true") { }); }); - it("Connect - external browser timeout", function (done) { + it('Connect - external browser timeout', function (done) { const connection = snowflake.createConnection( connOption.externalBrowserWithShortTimeout ); @@ -49,19 +49,19 @@ if (process.env.RUN_MANUAL_TESTS_ONLY == "true") { }); }); - it("Mismatched Username", function (done) { - var connection = snowflake.createConnection( + it('Mismatched Username', function (done) { + const connection = snowflake.createConnection( connOption.externalBrowserMismatchUser ); connection.connectAsync(function (err) { try { assert.ok( err, - "Logged in with different user than one on connection string" + 'Logged in with different user than one on connection string' ); assert.equal( - "The user you were trying to authenticate as differs from the user currently logged in at the IDP.", - err["message"] + 'The user you were trying to authenticate as differs from the user currently logged in at the IDP.', + err['message'] ); done(); } catch (err) { @@ -71,9 +71,9 @@ if (process.env.RUN_MANUAL_TESTS_ONLY == "true") { }); }); - describe("Connection test - oauth", function () { - it("Simple Connect", function (done) { - var connection = snowflake.createConnection(connOption.oauth); + describe('Connection test - oauth', function () { + it('Simple Connect', function (done) { + const connection = snowflake.createConnection(connOption.oauth); async.series([ function (callback) { @@ -84,7 +84,7 @@ if (process.env.RUN_MANUAL_TESTS_ONLY == "true") { }); }, function (callback) { - assert.ok(connection.isUp(), "not active"); + assert.ok(connection.isUp(), 'not active'); callback(); }, function (callback) { @@ -94,25 +94,25 @@ if (process.env.RUN_MANUAL_TESTS_ONLY == "true") { }); }, function (callback) { - assert.ok(!connection.isUp(), "still active"); + assert.ok(!connection.isUp(), 'still active'); callback(); }, ]); }); - it("Mismatched Username", function (done) { - var connection = snowflake.createConnection( + it('Mismatched Username', function (done) { + const connection = snowflake.createConnection( connOption.oauthMismatchUser ); connection.connect(function (err) { try { assert.ok( err, - "Logged in with different user than one on connection string" + 'Logged in with different user than one on connection string' ); assert.equal( - "The user you were trying to authenticate as differs from the user tied to the access token.", - err["message"] + 'The user you were trying to authenticate as differs from the user tied to the access token.', + err['message'] ); done(); } catch (err) { @@ -122,9 +122,9 @@ if (process.env.RUN_MANUAL_TESTS_ONLY == "true") { }); }); - describe("Connection test - okta", function () { - it("Simple Connect", function (done) { - var connection = snowflake.createConnection(connOption.okta); + describe('Connection test - okta', function () { + it('Simple Connect', function (done) { + const connection = snowflake.createConnection(connOption.okta); async.series([ function (callback) { @@ -135,7 +135,7 @@ if (process.env.RUN_MANUAL_TESTS_ONLY == "true") { }); }, function (callback) { - assert.ok(connection.isUp(), "not active"); + assert.ok(connection.isUp(), 'not active'); callback(); }, function (callback) { @@ -145,260 +145,118 @@ if (process.env.RUN_MANUAL_TESTS_ONLY == "true") { }); }, function (callback) { - assert.ok(!connection.isUp(), "still active"); + assert.ok(!connection.isUp(), 'still active'); callback(); }, ]); }); }); - }); -} - -// Skipped - requires manual interaction to enter credentials on browser -describe.skip("Connection test - external browser", function () { - this.timeout(10000); - it("Simple Connect", function (done) { - const connection = snowflake.createConnection(connOption.externalBrowser); - - connection.connectAsync(function (err, connection) { - try { - assert.ok(connection.isUp(), "not active"); - testUtil.destroyConnection(connection, function (err, r) { - try { - assert.ok(!connection.isUp(), "not active"); - done(); - } catch (err) { - done(err); - } - }); - } catch (err) { - done(err); - } - }); - }); - - it("Connect - external browser timeout", function (done) { - const connection = snowflake.createConnection( - connOption.externalBrowserWithShortTimeout - ); - - connection.connectAsync(function (err) { - try { - const browserActionTimeout = - connOption.externalBrowserWithShortTimeout.browserActionTimeout; - assert.ok( - err, - `Browser action timed out after ${browserActionTimeout} ms.` - ); - done(); - } catch (err) { - done(err); - } - }); - }); - - it("Mismatched Username", function (done) { - var connection = snowflake.createConnection( - connOption.externalBrowserMismatchUser - ); - connection.connectAsync(function (err) { - try { - assert.ok( - err, - "Logged in with different user than one on connection string" - ); - assert.equal( - "The user you were trying to authenticate as differs from the user currently logged in at the IDP.", - err["message"] + describe.skip('Connection test - keypair', function () { + it('Simple Connect - specify private key', function (done) { + const connection = snowflake.createConnection( + connOption.keypairPrivateKey ); - done(); - } catch (err) { - done(err); - } - }); - }); -}); - -describe.skip("Connection test - keypair", function () { - it("Simple Connect - specify private key", function (done) { - var connection = snowflake.createConnection(connOption.keypairPrivateKey); - async.series([ - function (callback) { - connection.connect(function (err) { - done(err); - assert.ok(!err, JSON.stringify(err)); - callback(); - }); - }, - function (callback) { - assert.ok(connection.isUp(), "not active"); - callback(); - }, - function (callback) { - connection.destroy(function (err) { - assert.ok(!err, JSON.stringify(err)); - callback(); - }); - }, - function (callback) { - assert.ok(!connection.isUp(), "still active"); - callback(); - }, - ]); - }); - - it.skip("Simple Connect - specify encrypted private key path and passphrase", function (done) { - var connection = snowflake.createConnection( - connOption.keypairPathEncrypted - ); - - async.series([ - function (callback) { - connection.connect(function (err) { - done(err); - assert.ok(!err, JSON.stringify(err)); - callback(); - }); - }, - function (callback) { - assert.ok(connection.isUp(), "not active"); - callback(); - }, - function (callback) { - connection.destroy(function (err) { - assert.ok(!err, JSON.stringify(err)); - callback(); - }); - }, - function (callback) { - assert.ok(!connection.isUp(), "still active"); - callback(); - }, - ]); - }); + async.series([ + function (callback) { + connection.connect(function (err) { + done(err); + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) { + assert.ok(connection.isUp(), 'not active'); + callback(); + }, + function (callback) { + connection.destroy(function (err) { + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) { + assert.ok(!connection.isUp(), 'still active'); + callback(); + }, + ]); + }); - it.skip("Simple Connect - specify unencrypted private key path without passphrase", function (done) { - var connection = snowflake.createConnection( - connOption.keypairPathEncrypted - ); + it.skip('Simple Connect - specify encrypted private key path and passphrase', function (done) { + const connection = snowflake.createConnection( + connOption.keypairPathEncrypted + ); - async.series([ - function (callback) { - connection.connect(function (err) { - done(err); - assert.ok(!err, JSON.stringify(err)); - callback(); - }); - }, - function (callback) { - assert.ok(connection.isUp(), "not active"); - callback(); - }, - function (callback) { - connection.destroy(function (err) { - assert.ok(!err, JSON.stringify(err)); - callback(); - }); - }, - function (callback) { - assert.ok(!connection.isUp(), "still active"); - callback(); - }, - ]); - }); + async.series([ + function (callback) { + connection.connect(function (err) { + done(err); + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) { + assert.ok(connection.isUp(), 'not active'); + callback(); + }, + function (callback) { + connection.destroy(function (err) { + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) { + assert.ok(!connection.isUp(), 'still active'); + callback(); + }, + ]); + }); - it("Wrong JWT token", function (done) { - var connection = snowflake.createConnection(connOption.keypairWrongToken); - connection.connect(function (err) { - try { - assert.ok(err, "Incorrect JWT token is passed."); - assert.equal("JWT token is invalid.", err["message"]); - done(); - } catch (err) { - done(err); - } - }); - }); -}); + it.skip('Simple Connect - specify unencrypted private key path without passphrase', function (done) { + const connection = snowflake.createConnection( + connOption.keypairPathEncrypted + ); -// Skipped - requires manual interaction to obtain oauth token -describe.skip("Connection test - oauth", function () { - it("Simple Connect", function (done) { - var connection = snowflake.createConnection(connOption.oauth); + async.series([ + function (callback) { + connection.connect(function (err) { + done(err); + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) { + assert.ok(connection.isUp(), 'not active'); + callback(); + }, + function (callback) { + connection.destroy(function (err) { + assert.ok(!err, JSON.stringify(err)); + callback(); + }); + }, + function (callback) { + assert.ok(!connection.isUp(), 'still active'); + callback(); + }, + ]); + }); - async.series([ - function (callback) { + it('Wrong JWT token', function (done) { + const connection = snowflake.createConnection( + connOption.keypairWrongToken + ); connection.connect(function (err) { - done(err); - assert.ok(!err, JSON.stringify(err)); - callback(); - }); - }, - function (callback) { - assert.ok(connection.isUp(), "not active"); - callback(); - }, - function (callback) { - connection.destroy(function (err) { - assert.ok(!err, JSON.stringify(err)); - callback(); + try { + assert.ok(err, 'Incorrect JWT token is passed.'); + assert.equal('JWT token is invalid.', err['message']); + done(); + } catch (err) { + done(err); + } }); - }, - function (callback) { - assert.ok(!connection.isUp(), "still active"); - callback(); - }, - ]); - }); - - it("Mismatched Username", function (done) { - var connection = snowflake.createConnection(connOption.oauthMismatchUser); - connection.connect(function (err) { - try { - assert.ok( - err, - "Logged in with different user than one on connection string" - ); - assert.equal( - "The user you were trying to authenticate as differs from the user tied to the access token.", - err["message"] - ); - done(); - } catch (err) { - done(err); - } + }); }); }); -}); - -describe.skip("Connection test - okta", function () { - it("Simple Connect", function (done) { - var connection = snowflake.createConnection(connOption.okta); - - async.series([ - function (callback) { - connection.connectAsync(function (err) { - done(err); - assert.ok(!err, JSON.stringify(err)); - callback(); - }); - }, - function (callback) { - assert.ok(connection.isUp(), "not active"); - callback(); - }, - function (callback) { - connection.destroy(function (err) { - assert.ok(!err, JSON.stringify(err)); - callback(); - }); - }, - function (callback) { - assert.ok(!connection.isUp(), "still active"); - callback(); - }, - ]); - }); -}); +} From 49087833324434ec5c2bcb73fce4d7fd78ff1d98 Mon Sep 17 00:00:00 2001 From: John Yun Date: Tue, 1 Aug 2023 14:17:11 -0700 Subject: [PATCH 5/5] remove 'skip' in the key pair test, and revised the 'manual test' script to use testManualConnection. --- package.json | 4 +- test/integration/testManualConnection.js | 82 ++++++++++++------------ 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/package.json b/package.json index 5bab9a3fb..1ee9f7e31 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "test:ci:coverage": "nyc npm run test:ci", "test:ci:withSystemTests": "mocha -timeout 180000 --recursive --full-trace test/**/*.js system_test/*.js", "test:ci:withSystemTests:coverage": "nyc npm run test:ci:withSystemTests", - "test:manual": "mocha -timeout 180000 --full-trace --full-trace test/integration/testConnection.js" + "test:manual": "mocha -timeout 180000 --full-trace --full-trace test/integration/testManualConnection.js" }, "author": { "name": "Snowflake Computing, Inc.", @@ -78,4 +78,4 @@ "url": "https://www.snowflake.com/" }, "license": "Apache-2.0" -} +} \ No newline at end of file diff --git a/test/integration/testManualConnection.js b/test/integration/testManualConnection.js index d83ed62cd..ce05e7ab1 100644 --- a/test/integration/testManualConnection.js +++ b/test/integration/testManualConnection.js @@ -1,23 +1,23 @@ -const snowflake = require('./../../lib/snowflake'); -const async = require('async'); -const assert = require('assert'); -const connOption = require('./connectionOptions'); -const testUtil = require('./testUtil'); +const snowflake = require("./../../lib/snowflake"); +const async = require("async"); +const assert = require("assert"); +const connOption = require("./connectionOptions"); +const testUtil = require("./testUtil"); -if (process.env.RUN_MANUAL_TESTS_ONLY == 'true') { - describe.only('Run manual tests', function () { - describe('Connection test - external browser', function () { - it('Simple Connect', function (done) { +if (process.env.RUN_MANUAL_TESTS_ONLY == "true") { + describe.only("Run manual tests", function () { + describe("Connection test - external browser", function () { + it("Simple Connect", function (done) { const connection = snowflake.createConnection( connOption.externalBrowser ); connection.connectAsync(function (err, connection) { try { - assert.ok(connection.isUp(), 'not active'); + assert.ok(connection.isUp(), "not active"); testUtil.destroyConnection(connection, function (err, r) { try { - assert.ok(!connection.isUp(), 'not active'); + assert.ok(!connection.isUp(), "not active"); done(); } catch (err) { done(err); @@ -29,7 +29,7 @@ if (process.env.RUN_MANUAL_TESTS_ONLY == 'true') { }); }); - it('Connect - external browser timeout', function (done) { + it("Connect - external browser timeout", function (done) { const connection = snowflake.createConnection( connOption.externalBrowserWithShortTimeout ); @@ -49,7 +49,7 @@ if (process.env.RUN_MANUAL_TESTS_ONLY == 'true') { }); }); - it('Mismatched Username', function (done) { + it("Mismatched Username", function (done) { const connection = snowflake.createConnection( connOption.externalBrowserMismatchUser ); @@ -57,11 +57,11 @@ if (process.env.RUN_MANUAL_TESTS_ONLY == 'true') { try { assert.ok( err, - 'Logged in with different user than one on connection string' + "Logged in with different user than one on connection string" ); assert.equal( - 'The user you were trying to authenticate as differs from the user currently logged in at the IDP.', - err['message'] + "The user you were trying to authenticate as differs from the user currently logged in at the IDP.", + err["message"] ); done(); } catch (err) { @@ -71,8 +71,8 @@ if (process.env.RUN_MANUAL_TESTS_ONLY == 'true') { }); }); - describe('Connection test - oauth', function () { - it('Simple Connect', function (done) { + describe("Connection test - oauth", function () { + it("Simple Connect", function (done) { const connection = snowflake.createConnection(connOption.oauth); async.series([ @@ -84,7 +84,7 @@ if (process.env.RUN_MANUAL_TESTS_ONLY == 'true') { }); }, function (callback) { - assert.ok(connection.isUp(), 'not active'); + assert.ok(connection.isUp(), "not active"); callback(); }, function (callback) { @@ -94,13 +94,13 @@ if (process.env.RUN_MANUAL_TESTS_ONLY == 'true') { }); }, function (callback) { - assert.ok(!connection.isUp(), 'still active'); + assert.ok(!connection.isUp(), "still active"); callback(); }, ]); }); - it('Mismatched Username', function (done) { + it("Mismatched Username", function (done) { const connection = snowflake.createConnection( connOption.oauthMismatchUser ); @@ -108,11 +108,11 @@ if (process.env.RUN_MANUAL_TESTS_ONLY == 'true') { try { assert.ok( err, - 'Logged in with different user than one on connection string' + "Logged in with different user than one on connection string" ); assert.equal( - 'The user you were trying to authenticate as differs from the user tied to the access token.', - err['message'] + "The user you were trying to authenticate as differs from the user tied to the access token.", + err["message"] ); done(); } catch (err) { @@ -122,8 +122,8 @@ if (process.env.RUN_MANUAL_TESTS_ONLY == 'true') { }); }); - describe('Connection test - okta', function () { - it('Simple Connect', function (done) { + describe("Connection test - okta", function () { + it("Simple Connect", function (done) { const connection = snowflake.createConnection(connOption.okta); async.series([ @@ -135,7 +135,7 @@ if (process.env.RUN_MANUAL_TESTS_ONLY == 'true') { }); }, function (callback) { - assert.ok(connection.isUp(), 'not active'); + assert.ok(connection.isUp(), "not active"); callback(); }, function (callback) { @@ -145,15 +145,15 @@ if (process.env.RUN_MANUAL_TESTS_ONLY == 'true') { }); }, function (callback) { - assert.ok(!connection.isUp(), 'still active'); + assert.ok(!connection.isUp(), "still active"); callback(); }, ]); }); }); - describe.skip('Connection test - keypair', function () { - it('Simple Connect - specify private key', function (done) { + describe("Connection test - keypair", function () { + it("Simple Connect - specify private key", function (done) { const connection = snowflake.createConnection( connOption.keypairPrivateKey ); @@ -167,7 +167,7 @@ if (process.env.RUN_MANUAL_TESTS_ONLY == 'true') { }); }, function (callback) { - assert.ok(connection.isUp(), 'not active'); + assert.ok(connection.isUp(), "not active"); callback(); }, function (callback) { @@ -177,13 +177,13 @@ if (process.env.RUN_MANUAL_TESTS_ONLY == 'true') { }); }, function (callback) { - assert.ok(!connection.isUp(), 'still active'); + assert.ok(!connection.isUp(), "still active"); callback(); }, ]); }); - it.skip('Simple Connect - specify encrypted private key path and passphrase', function (done) { + it("Simple Connect - specify encrypted private key path and passphrase", function (done) { const connection = snowflake.createConnection( connOption.keypairPathEncrypted ); @@ -197,7 +197,7 @@ if (process.env.RUN_MANUAL_TESTS_ONLY == 'true') { }); }, function (callback) { - assert.ok(connection.isUp(), 'not active'); + assert.ok(connection.isUp(), "not active"); callback(); }, function (callback) { @@ -207,13 +207,13 @@ if (process.env.RUN_MANUAL_TESTS_ONLY == 'true') { }); }, function (callback) { - assert.ok(!connection.isUp(), 'still active'); + assert.ok(!connection.isUp(), "still active"); callback(); }, ]); }); - it.skip('Simple Connect - specify unencrypted private key path without passphrase', function (done) { + it("Simple Connect - specify unencrypted private key path without passphrase", function (done) { const connection = snowflake.createConnection( connOption.keypairPathEncrypted ); @@ -227,7 +227,7 @@ if (process.env.RUN_MANUAL_TESTS_ONLY == 'true') { }); }, function (callback) { - assert.ok(connection.isUp(), 'not active'); + assert.ok(connection.isUp(), "not active"); callback(); }, function (callback) { @@ -237,20 +237,20 @@ if (process.env.RUN_MANUAL_TESTS_ONLY == 'true') { }); }, function (callback) { - assert.ok(!connection.isUp(), 'still active'); + assert.ok(!connection.isUp(), "still active"); callback(); }, ]); }); - it('Wrong JWT token', function (done) { + it("Wrong JWT token", function (done) { const connection = snowflake.createConnection( connOption.keypairWrongToken ); connection.connect(function (err) { try { - assert.ok(err, 'Incorrect JWT token is passed.'); - assert.equal('JWT token is invalid.', err['message']); + assert.ok(err, "Incorrect JWT token is passed."); + assert.equal("JWT token is invalid.", err["message"]); done(); } catch (err) { done(err);