diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 08a074571..26b813283 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -29,14 +29,14 @@ jobs: name: Build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - name: Build shell: bash env: WHITESOURCE_API_KEY: ${{ secrets.WHITESOURCE_API_KEY }} run: ./ci/build.sh - name: Upload Build Artifact - uses: actions/upload-artifact@v1 + uses: actions/upload-artifact@v3 with: name: artifacts path: artifacts @@ -49,19 +49,20 @@ jobs: fail-fast: false matrix: cloud: [ 'AWS', 'AZURE', 'GCP' ] - nodeVersion: [ '14.x', '16.x', '18.x'] + nodeVersion: [ '14.x', '16.x', '18.x', '20.x'] steps: - - uses: actions/checkout@v1 - - uses: actions/setup-node@v1 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v3 with: node-version: ${{ matrix.nodeVersion }} - - uses: actions/setup-python@v1 + - uses: actions/setup-python@v4 with: python-version: '3.7' - name: Download Build Artifacts - uses: actions/download-artifact@v1 + uses: actions/download-artifact@v3 with: name: artifacts + path: artifacts - name: Install Homebrew Bash shell: bash run: brew install bash @@ -86,20 +87,21 @@ jobs: fail-fast: false matrix: cloud: [ 'AWS', 'AZURE', 'GCP' ] - nodeVersion: [ '14.x', '16.x', '18.x'] + nodeVersion: [ '14.x', '16.x', '18.x', '20.x'] steps: - - uses: actions/checkout@v1 - - uses: actions/setup-node@v1 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v3 with: node-version: ${{ matrix.nodeVersion }} - - uses: actions/setup-python@v1 + - uses: actions/setup-python@v4 with: python-version: '3.7' architecture: 'x64' - name: Download Build Artifacts - uses: actions/download-artifact@v1 + uses: actions/download-artifact@v3 with: name: artifacts + path: artifacts - name: Tests shell: cmd env: @@ -117,11 +119,12 @@ jobs: image: [ 'nodejs-centos7-node14', 'nodejs-centos7-fips'] cloud: [ 'AWS', 'AZURE', 'GCP' ] steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - name: Download Build Artifacts - uses: actions/download-artifact@v1 + uses: actions/download-artifact@v3 with: name: artifacts + path: artifacts - name: Tests shell: bash env: @@ -129,3 +132,38 @@ jobs: CLOUD_PROVIDER: ${{ matrix.cloud }} TARGET_DOCKER_TEST_IMAGE: ${{ matrix.image }} run: ./ci/test.sh + + test-ubuntu: + needs: build + name: Tests on Ubuntu + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + cloud: [ 'AWS', 'AZURE', 'GCP' ] + nodeVersion: ['18.x', '20.x'] + steps: + - uses: actions/checkout@v4 + - name: Download Build Artifacts + uses: actions/download-artifact@v3 + with: + name: artifacts + path: artifacts + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - name: Tests + shell: bash + env: + PARAMETERS_SECRET: ${{ secrets.PARAMETERS_SECRET }} + CLOUD_PROVIDER: ${{ matrix.cloud }} + run: ./ci/test_ubuntu.sh + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 + with: + # without the token code cov may fail because of Github limits https://github.com/codecov/codecov-action/issues/557 + token: ${{ secrets.CODE_COV_UPLOAD_TOKEN }} + fail_ci_if_error: true + + diff --git a/ci/test_mac.sh b/ci/test_mac.sh index b20bd03d5..1affe52f8 100755 --- a/ci/test_mac.sh +++ b/ci/test_mac.sh @@ -2,11 +2,15 @@ # # Test NodeJS for Mac # + +echo "DOWNLOADED" +echo $(ls /Users/runner/work/snowflake-connector-nodejs/snowflake-connector-nodejs/) set -o pipefail THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source $THIS_DIR/_init.sh source $THIS_DIR/scripts/set_git_info.sh + export WORKSPACE=$GITHUB_WORKSPACE export SOURCE_ROOT=$GITHUB_WORKSPACE export SHOULD_GENERATE_COVERAGE_REPORT=1 diff --git a/ci/test_ubuntu.sh b/ci/test_ubuntu.sh new file mode 100755 index 000000000..1bc6a65a8 --- /dev/null +++ b/ci/test_ubuntu.sh @@ -0,0 +1,23 @@ +#!/bin/bash -e +# +# Test NodeJS for Ubuntu +# + +echo "DOWNLOADED" +echo $(ls /Users/runner/work/snowflake-connector-nodejs/snowflake-connector-nodejs/) +set -o pipefail +THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source $THIS_DIR/_init.sh +source $THIS_DIR/scripts/set_git_info.sh + +export WORKSPACE=$GITHUB_WORKSPACE +export SOURCE_ROOT=$GITHUB_WORKSPACE +export SHOULD_GENERATE_COVERAGE_REPORT=1 +export SHOULD_SKIP_PROXY_TESTS=1 + +python3 --version +python3 -m venv venv +source venv/bin/activate +pip3 install -U pip +pip3 install -U snowflake-connector-python +$THIS_DIR/container/test_component.sh $SHOULD_GENERATE_COVERAGE_REPORT diff --git a/samples/README.md b/samples/README.md index eb5b4fa84..f78075d61 100644 --- a/samples/README.md +++ b/samples/README.md @@ -51,4 +51,10 @@ npm run jsonParserComparison 300000 300000 Function or ``` npm run jsonParserComparison 300000 300000 JSON -``` \ No newline at end of file +``` + +Run query reading all rows vs streaming the rows +---------------------------------------------------------------------- + +1. Set your query in [`rowsVsStreamingQuery.js`](./rowsVsStreamingQuery.js)` +2. Run `npm run rowsVsStreamingQuery` diff --git a/samples/helpers.js b/samples/helpers.js index 1d8c0e0b8..9ee68f955 100644 --- a/samples/helpers.js +++ b/samples/helpers.js @@ -1,4 +1,5 @@ const snowflake = require('snowflake-sdk'); + exports.executeQuery = async function (connection, query, binds) { await new Promise((resolve, reject) => { connection.execute({ @@ -53,4 +54,15 @@ exports.connectUsingEnv = async () => { } ); }); -}; \ No newline at end of file +}; + +exports.destroyAsync = connection => new Promise((resolve, reject) => { + connection.destroy(err => { + if (err) { + reject(err); + } else { + resolve(); + } + } + ); +}); diff --git a/samples/package.json b/samples/package.json index 891a6a75a..63bf53a09 100644 --- a/samples/package.json +++ b/samples/package.json @@ -5,10 +5,11 @@ "dependencies": { "better-eval": "^1.3.0", "blocked-at": "^1.2.0", - "snowflake-sdk": "^1.8.0", + "snowflake-sdk": "^1.9.0", "vm": "^0.1.0" }, "scripts": { - "jsonParserComparison": "node jsonParserComparison.js" + "jsonParserComparison": "node jsonParserComparison.js", + "rowsVsStreamingQuery": "node rowsVsStreamingQuery.js" } } diff --git a/samples/rowsVsStreamingQuery.js b/samples/rowsVsStreamingQuery.js new file mode 100644 index 000000000..f80836400 --- /dev/null +++ b/samples/rowsVsStreamingQuery.js @@ -0,0 +1,55 @@ +/* eslint-disable no-console */ +const snowflake = require('snowflake-sdk'); +const { connectUsingEnv, destroyAsync } = require('./helpers'); + +const executeQuery = (connection, query, binds = undefined) => new Promise((resolve, reject) => { + connection.execute({ + sqlText: query, + binds: binds, + complete: function (err, stmt, rows) { + if (!err) { + resolve(rows); + } else { + reject(err); + } + } + }); +}); + +const executeQueryStreaming = (connection, query, binds = undefined) => new Promise((resolve, reject) => { + const stmt = connection.execute({ + sqlText: query, + binds: binds, + streamResult: true, + }); + stmt.streamRows() + .on('error', err => reject(err)) + .on('data', () => {}) + .on('end', () => resolve()); +}); + +async function runQueryReadingResultsFromRows(query){ + const connection = await connectUsingEnv(); + console.time('without streaming'); + await executeQuery(connection, query); + console.timeEnd('without streaming'); + await destroyAsync(connection); +} + +async function runQueryReadingResultsFromStream(query){ + const connection = await connectUsingEnv(); + console.time('with streaming'); + await executeQueryStreaming(connection, query); + console.timeEnd('with streaming'); + await destroyAsync(connection); +} + +async function main() { + const query = 'Select 1'; // Set your query here + snowflake.configure({ logLevel: 'ERROR' }); + console.log(`Executing query: ${query}`); + await runQueryReadingResultsFromRows(query); + await runQueryReadingResultsFromStream(query); +} + +main(); diff --git a/test/integration/testConnectionWithOCSP.js b/test/integration/testConnectionWithOCSP.js index 51ac0db75..739a1537c 100644 --- a/test/integration/testConnectionWithOCSP.js +++ b/test/integration/testConnectionWithOCSP.js @@ -1,11 +1,10 @@ /* * Copyright (c) 2015-2019 Snowflake Computing Inc. All rights reserved. */ -const async = require('async'); const assert = require('assert'); const snowflake = require('./../../lib/snowflake'); -const Errors = require('./../../lib/errors') +const Errors = require('./../../lib/errors'); const SocketUtil = require('./../../lib/agent/socket_util'); const OcspResponseCache = require('./../../lib/agent/ocsp_response_cache'); @@ -30,374 +29,252 @@ const testRevokedConnectionOptions = { account: 'fakeaccount' }; -function getConnectionOptions() -{ +function getConnectionOptions() { // use unique hostname to avoid connection cache in tests. // If connection is cached, the test result is not consistent. - let objCopy = Object.assign({}, testConnectionOptions); + const objCopy = Object.assign({}, testConnectionOptions); objCopy['accessUrl'] = 'https://fakeaccount' + (testCounter) + '.snowflakecomputing.com'; testCounter++; return objCopy; } -describe('Connection with OCSP test', function () -{ - function deleteCache() - { +describe('Connection with OCSP test', function () { + function cleanupOcspState() { OcspResponseCache.deleteCache(); + snowflake.configure({ ocspFailOpen: true }); + SocketUtil.variables.OCSP_RESPONSE_CACHE = undefined; + SocketUtil.variables.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED = true; } - it('OCSP NOP - Fail Open', function (done) - { - deleteCache(); - snowflake.configure({ocspFailOpen: true}); + beforeEach(() => { + cleanupOcspState(); + }); + + afterEach(() => { + cleanupOcspState(); + [ + 'SF_OCSP_RESPONDER_URL', + 'SF_OCSP_RESPONSE_CACHE_SERVER_URL', + 'SF_OCSP_TEST_INJECT_UNKNOWN_STATUS', + 'SF_OCSP_TEST_INJECT_VALIDITY_ERROR', + 'SF_OCSP_TEST_OCSP_RESPONDER_TIMEOUT', + 'SF_OCSP_TEST_OCSP_RESPONSE_CACHE_SERVER_TIMEOUT', + ].forEach(envVariable => delete process.env[envVariable]); + }); + + it('OCSP NOP - Fail Open', function (done) { const connection = snowflake.createConnection(getConnectionOptions()); - async.series([ - function (callback) - { - connection.connect(function (err) - { - assert.strictEqual(err.code, Errors.codes.ERR_SF_RESPONSE_FAILURE); - callback(); - }); - } - ], - done - ); + connection.connect(function (err) { + try { + assert.strictEqual(err.code, Errors.codes.ERR_SF_RESPONSE_FAILURE); + done(); + } catch (error) { + done(error); + } + }); }); - it('OCSP Validity Error - Fail Open', function (done) - { - deleteCache(); - SocketUtil.variables.OCSP_RESPONSE_CACHE = undefined; + it('OCSP Validity Error - Fail Open', function (done) { SocketUtil.variables.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED = false; // inject validity error process.env.SF_OCSP_TEST_INJECT_VALIDITY_ERROR = 'true'; - snowflake.configure({ocspFailOpen: true}); const connection = snowflake.createConnection(getConnectionOptions()); - async.series([ - function (callback) - { - connection.connect(function (err) - { - assert.strictEqual(err.code, Errors.codes.ERR_SF_RESPONSE_FAILURE); - callback(); - }); - }, - function (callback) - { - delete process.env['SF_OCSP_TEST_INJECT_VALIDITY_ERROR']; - callback(); - } - ], - done - ); + connection.connect(function (err) { + try { + assert.strictEqual(err.code, Errors.codes.ERR_SF_RESPONSE_FAILURE); + done(); + } catch (error) { + done(error); + } + }); }); - it('OCSP Validity Error - Fail Closed', function (done) - { - deleteCache(); - SocketUtil.variables.OCSP_RESPONSE_CACHE = undefined; + it('OCSP Validity Error - Fail Closed', function (done) { SocketUtil.variables.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED = false; // inject validity error process.env.SF_OCSP_TEST_INJECT_VALIDITY_ERROR = 'true'; - snowflake.configure({ocspFailOpen: false}); + snowflake.configure({ ocspFailOpen: false }); const connection = snowflake.createConnection(getConnectionOptions()); - async.series([ - function (callback) - { - connection.connect(function (err) - { - assert.strictEqual(err.code, Errors.codes.ERR_SF_NETWORK_COULD_NOT_CONNECT); - assert.strictEqual(err.cause.code, Errors.codes.ERR_OCSP_INVALID_VALIDITY); - callback(); - }); - }, - function (callback) - { - delete process.env['SF_OCSP_TEST_INJECT_VALIDITY_ERROR']; - snowflake.configure({ocspFailOpen: true}); - callback(); - } - ], - done - ); + connection.connect(function (err) { + try { + assert.strictEqual(err.code, Errors.codes.ERR_SF_NETWORK_COULD_NOT_CONNECT); + assert.strictEqual(err.cause.code, Errors.codes.ERR_OCSP_INVALID_VALIDITY); + done(); + } catch (error) { + done(error); + } + }); }); - it('OCSP Unknown Cert - Fail Open', function (done) - { - deleteCache(); - SocketUtil.variables.OCSP_RESPONSE_CACHE = undefined; + it('OCSP Unknown Cert - Fail Open', function (done) { SocketUtil.variables.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED = false; // inject validity error process.env.SF_OCSP_TEST_INJECT_UNKNOWN_STATUS = 'true'; - snowflake.configure({ocspFailOpen: true}); const connection = snowflake.createConnection(getConnectionOptions()); - async.series([ - function (callback) - { - connection.connect(function (err) - { - assert.strictEqual(err.code, Errors.codes.ERR_SF_RESPONSE_FAILURE); - callback(); - }); - }, - function (callback) - { - delete process.env['SF_OCSP_TEST_INJECT_UNKNOWN_STATUS']; - callback(); - } - ], - done - ); + connection.connect(function (err) { + try { + assert.strictEqual(err.code, Errors.codes.ERR_SF_RESPONSE_FAILURE); + done(); + } catch (error) { + done(error); + } + }); }); - it('OCSP Unknown Cert - Fail Closed', function (done) - { - deleteCache(); - SocketUtil.variables.OCSP_RESPONSE_CACHE = undefined; + it('OCSP Unknown Cert - Fail Closed', function (done) { SocketUtil.variables.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED = false; // inject validity error process.env.SF_OCSP_TEST_INJECT_UNKNOWN_STATUS = 'true'; - snowflake.configure({ocspFailOpen: false}); + snowflake.configure({ ocspFailOpen: false }); const connection = snowflake.createConnection(getConnectionOptions()); - async.series([ - function (callback) - { - connection.connect(function (err) - { - if (err.code !== Errors.codes.ERR_SF_NETWORK_COULD_NOT_CONNECT) - { - console.log(err); - } - assert.strictEqual(err.code, Errors.codes.ERR_SF_NETWORK_COULD_NOT_CONNECT); - assert.strictEqual(err.cause.code, Errors.codes.ERR_OCSP_UNKNOWN); - callback(); - }); - }, - function (callback) - { - delete process.env['SF_OCSP_TEST_INJECT_UNKNOWN_STATUS']; - snowflake.configure({ocspFailOpen: true}); - callback(); + connection.connect(function (err) { + try { + if (err.code !== Errors.codes.ERR_SF_NETWORK_COULD_NOT_CONNECT) { + Logger.getInstance().error(JSON.stringify(err)); } - ], - done - ); + assert.strictEqual(err.code, Errors.codes.ERR_SF_NETWORK_COULD_NOT_CONNECT); + assert.strictEqual(err.cause.code, Errors.codes.ERR_OCSP_UNKNOWN); + done(); + } catch (error) { + done(error); + } + }); }); - /* - it('OCSP Revoked Cert - Fail Open', function (done) - { - snowflake.configure({ocspFailOpen: true}); + + // TODO SNOW-930797 Fix and enable Revoked Cert tests + it.skip('OCSP Revoked Cert - Fail Open', function (done) { const connection = snowflake.createConnection(testRevokedConnectionOptions); - async.series([ - function (callback) - { - connection.connect(function (err) - { - assert.strictEqual(err.cause.code, Errors.codes.ERR_OCSP_REVOKED); - callback(); - }); - } - ], - done - ); + connection.connect(function (err) { + try { + assert.strictEqual(err.cause.code, Errors.codes.ERR_OCSP_REVOKED); + done(); + } catch (error) { + done(error); + } + }); }); - it('OCSP Revoked Cert - Fail Closed', function (done) - { - snowflake.configure({ocspFailOpen: false}); + // TODO SNOW-930797 Fix and enable Revoked Cert tests + it.skip('OCSP Revoked Cert - Fail Closed', function (done) { + snowflake.configure({ ocspFailOpen: false }); const connection = snowflake.createConnection(testRevokedConnectionOptions); - async.series([ - function (callback) - { - connection.connect(function (err) - { - assert.strictEqual(err.cause.code, Errors.codes.ERR_OCSP_REVOKED); - callback(); - }); - }, - function (callback) - { - snowflake.configure({ocspFailOpen: true}); - callback(); - } - ], - done - ); - });*/ - - it('OCSP Cache Server Timeout - Fail Open', function (done) - { - deleteCache(); - SocketUtil.variables.OCSP_RESPONSE_CACHE = undefined; + connection.connect(function (err) { + try { + assert.strictEqual(err.cause.code, Errors.codes.ERR_OCSP_REVOKED); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('OCSP Cache Server Timeout - Fail Open', function (done) { // cache server is used SocketUtil.variables.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED = true; // fake OCSP responder. process.env.SF_OCSP_RESPONSE_CACHE_SERVER_URL = `${hangWebServerUrl}/hang`; process.env.SF_OCSP_TEST_OCSP_RESPONSE_CACHE_SERVER_TIMEOUT = 1000; - snowflake.configure({ocspFailOpen: true}); const connection = snowflake.createConnection(getConnectionOptions()); - async.series([ - function (callback) - { - connection.connect(function (err) - { - // read error is expected as the account name is fake. - // This just should not be OCSP error. - assert.strictEqual(err.code, Errors.codes.ERR_SF_RESPONSE_FAILURE); - callback(); - }); - }, - function (callback) - { - delete process.env['SF_OCSP_RESPONSE_CACHE_SERVER_URL']; - delete process.env['SF_OCSP_TEST_OCSP_RESPONSE_CACHE_SERVER_TIMEOUT']; - snowflake.configure({ocspFailOpen: true}); - callback(); - } - ], - done - ); + connection.connect(function (err) { + // read error is expected as the account name is fake. + // This just should not be OCSP error. + try { + assert.strictEqual(err.code, Errors.codes.ERR_SF_RESPONSE_FAILURE); + done(); + } catch (error) { + done(error); + } + }); }); - it('OCSP Cache Server Timeout - Fail Closed', function (done) - { - deleteCache(); - SocketUtil.variables.OCSP_RESPONSE_CACHE = undefined; + it('OCSP Cache Server Timeout - Fail Closed', function (done) { // cache server is used SocketUtil.variables.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED = true; // fake OCSP responder. process.env.SF_OCSP_RESPONSE_CACHE_SERVER_URL = `${hangWebServerUrl}/hang`; process.env.SF_OCSP_TEST_OCSP_RESPONSE_CACHE_SERVER_TIMEOUT = 1000; - snowflake.configure({ocspFailOpen: false}); + snowflake.configure({ ocspFailOpen: false }); const connection = snowflake.createConnection(getConnectionOptions()); - async.series([ - function (callback) - { - connection.connect(function (err) - { - // read error is expected as the account name is fake. - // This just should not be OCSP error. - if (err.code !== Errors.codes.ERR_SF_RESPONSE_FAILURE) - { - console.log(err); - } - assert.strictEqual(err.code, Errors.codes.ERR_SF_RESPONSE_FAILURE); - callback(); - }); - }, - function (callback) - { - delete process.env['SF_OCSP_TEST_OCSP_RESPONSE_CACHE_SERVER_TIMEOUT']; - delete process.env['SF_OCSP_RESPONSE_CACHE_SERVER_URL']; - snowflake.configure({ocspFailOpen: true}); - callback(); + connection.connect(function (err) { + try { + // read error is expected as the account name is fake. + // This just should not be OCSP error. + if (err.code !== Errors.codes.ERR_SF_RESPONSE_FAILURE) { + Logger.getInstance().error(JSON.stringify(err)); } - ], - done - ); + assert.strictEqual(err.code, Errors.codes.ERR_SF_RESPONSE_FAILURE); + done(); + } catch (error) { + done(error); + } + }); }); - it('OCSP Responder Timeout - Fail Open', function (done) - { - deleteCache(); - SocketUtil.variables.OCSP_RESPONSE_CACHE = undefined; + it('OCSP Responder Timeout - Fail Open', function (done) { // no cache server is used SocketUtil.variables.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED = false; // fake OCSP responder. process.env.SF_OCSP_RESPONDER_URL = `${hangWebServerUrl}/hang`; process.env.SF_OCSP_TEST_OCSP_RESPONDER_TIMEOUT = 1000; - snowflake.configure({ocspFailOpen: true}); const connection = snowflake.createConnection(getConnectionOptions()); - async.series([ - function (callback) - { - connection.connect(function (err) - { - // read error is expected as the account name is fake. - // This just should not be OCSP error. - assert.strictEqual(err.code, Errors.codes.ERR_SF_RESPONSE_FAILURE); - callback(); - }); - }, - function (callback) - { - delete process.env['SF_OCSP_RESPONDER_URL']; - delete process.env['SF_OCSP_TEST_OCSP_RESPONDER_TIMEOUT']; - snowflake.configure({ocspFailOpen: true}); - callback(); - } - ], - done - ); + connection.connect(function (err) { + try { + // read error is expected as the account name is fake. + // This just should not be OCSP error. + assert.strictEqual(err.code, Errors.codes.ERR_SF_RESPONSE_FAILURE); + done(); + } catch (error) { + done(error); + } + }); }); - it('OCSP Responder Timeout - Fail Closed', function (done) - { - deleteCache(); - SocketUtil.variables.OCSP_RESPONSE_CACHE = undefined; + it('OCSP Responder Timeout - Fail Closed', function (done) { // no cache server is used SocketUtil.variables.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED = false; // fake OCSP responder. process.env.SF_OCSP_RESPONDER_URL = `${hangWebServerUrl}/hang`; process.env.SF_OCSP_TEST_OCSP_RESPONDER_TIMEOUT = 1000; - snowflake.configure({ocspFailOpen: false}); + snowflake.configure({ ocspFailOpen: false }); const connection = snowflake.createConnection(getConnectionOptions()); - async.series([ - function (callback) - { - connection.connect(function (err) - { - // should be OCSP timeout error. - if (err.code !== Errors.codes.ERR_SF_NETWORK_COULD_NOT_CONNECT) - { - console.log(err); - } - assert.strictEqual(err.code, Errors.codes.ERR_SF_NETWORK_COULD_NOT_CONNECT); - if (err.cause.code === 'ECONNREFUSED') - { - console.log("run hang_webserver.py") - } - assert.strictEqual(err.cause.code, Errors.codes.ERR_OCSP_RESPONDER_TIMEOUT); - callback(); - }); - }, - function (callback) - { - delete process.env['SF_OCSP_RESPONDER_URL']; - delete process.env['SF_OCSP_TEST_OCSP_RESPONDER_TIMEOUT']; - snowflake.configure({ocspFailOpen: true}); - callback(); + connection.connect(function (err) { + try { + // should be OCSP timeout error. + if (err.code !== Errors.codes.ERR_SF_NETWORK_COULD_NOT_CONNECT) { + Logger.getInstance().error(JSON.stringify(err)); } - ], - done - ); + assert.strictEqual(err.code, Errors.codes.ERR_SF_NETWORK_COULD_NOT_CONNECT); + if (err.cause.code === 'ECONNREFUSED') { + Logger.getInstance().error('run hang_webserver.py'); + } + assert.strictEqual(err.cause.code, Errors.codes.ERR_OCSP_RESPONDER_TIMEOUT); + done(); + } catch (error) { + done(error); + } + }); }); - it('OCSP Cache Server and Responder Timeout - Fail Open', function (done) - { - deleteCache(); - SocketUtil.variables.OCSP_RESPONSE_CACHE = undefined; + it('OCSP Cache Server and Responder Timeout - Fail Open', function (done) { // no cache server is used SocketUtil.variables.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED = true; // fake OCSP responder. @@ -406,143 +283,87 @@ describe('Connection with OCSP test', function () process.env.SF_OCSP_TEST_OCSP_RESPONDER_TIMEOUT = 1000; process.env.SF_OCSP_TEST_OCSP_RESPONSE_CACHE_SERVER_TIMEOUT = 1000; - snowflake.configure({ocspFailOpen: true}); const connection = snowflake.createConnection(getConnectionOptions()); - async.series([ - function (callback) - { - connection.connect(function (err) - { - // should be 403 - assert.strictEqual(err.code, Errors.codes.ERR_SF_RESPONSE_FAILURE); - callback(); - }); - }, - function (callback) - { - delete process.env['SF_OCSP_RESPONSE_CACHE_SERVER_URL']; - delete process.env['SF_OCSP_RESPONDER_URL']; - delete process.env['SF_OCSP_TEST_OCSP_RESPONDER_TIMEOUT']; - delete process.env['SF_OCSP_TEST_OCSP_RESPONSE_CACHE_SERVER_TIMEOUT']; - callback(); - } - ], - done - ); + connection.connect(function (err) { + try { + // should be 403 + assert.strictEqual(err.code, Errors.codes.ERR_SF_RESPONSE_FAILURE); + done(); + } catch (error) { + done(error); + } + }); }); - it('OCSP Responder 403 - Fail Closed', function (done) - { - deleteCache(); - SocketUtil.variables.OCSP_RESPONSE_CACHE = undefined; + it('OCSP Responder 403 - Fail Closed', function (done) { // no cache server is used SocketUtil.variables.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED = false; // fake OCSP responder. process.env.SF_OCSP_RESPONDER_URL = `${hangWebServerUrl}/403`; - snowflake.configure({ocspFailOpen: false}); + snowflake.configure({ ocspFailOpen: false }); const connection = snowflake.createConnection(getConnectionOptions()); - async.series([ - function (callback) - { - connection.connect(function (err) - { - // should be OCSP timeout error. - if (err.code !== Errors.codes.ERR_SF_NETWORK_COULD_NOT_CONNECT) - { - console.log(err); - } - assert.strictEqual(err.code, Errors.codes.ERR_SF_NETWORK_COULD_NOT_CONNECT); - if (err.cause.code === 'ECONNREFUSED') - { - console.log("run hang_webserver.py") - } - assert.strictEqual(err.cause.code, Errors.codes.ERR_OCSP_FAILED_OBTAIN_OCSP_RESPONSE); - callback(); - }); - }, - function (callback) - { - delete process.env['SF_OCSP_RESPONDER_URL']; - snowflake.configure({ocspFailOpen: true}); - callback(); + connection.connect(function (err) { + try { + // should be OCSP timeout error. + if (err.code !== Errors.codes.ERR_SF_NETWORK_COULD_NOT_CONNECT) { + Logger.getInstance().error(JSON.stringify(err)); } - ], - done - ); + assert.strictEqual(err.code, Errors.codes.ERR_SF_NETWORK_COULD_NOT_CONNECT); + if (err.cause.code === 'ECONNREFUSED') { + Logger.getInstance().error('run hang_webserver.py'); + } + assert.strictEqual(err.cause.code, Errors.codes.ERR_OCSP_FAILED_OBTAIN_OCSP_RESPONSE); + done(); + } catch (error) { + done(error); + } + }); }); - it('OCSP Responder 403 - Fail Open', function (done) - { - deleteCache(); - SocketUtil.variables.OCSP_RESPONSE_CACHE = undefined; + it('OCSP Responder 403 - Fail Open', function (done) { // no cache server is used SocketUtil.variables.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED = false; // fake OCSP responder. process.env.SF_OCSP_RESPONDER_URL = `${hangWebServerUrl}/403`; - snowflake.configure({ocspFailOpen: true}); const connection = snowflake.createConnection(getConnectionOptions()); - async.series([ - function (callback) - { - connection.connect(function (err) - { - // should be OCSP timeout error. - assert.strictEqual(err.code, Errors.codes.ERR_SF_RESPONSE_FAILURE); - callback(); - }); - }, - function (callback) - { - delete process.env['SF_OCSP_RESPONDER_URL']; - snowflake.configure({ocspFailOpen: true}); - callback(); - } - ], - done - ); + connection.connect(function (err) { + try { + // should be OCSP timeout error. + assert.strictEqual(err.code, Errors.codes.ERR_SF_RESPONSE_FAILURE); + done(); + } catch (error) { + done(error); + } + }); }); - it('OCSP Responder 404 - Fail Closed', function (done) - { - deleteCache(); - SocketUtil.variables.OCSP_RESPONSE_CACHE = undefined; + it('OCSP Responder 404 - Fail Closed', function (done) { // no cache server is used SocketUtil.variables.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED = false; // fake OCSP responder. process.env.SF_OCSP_RESPONDER_URL = `${hangWebServerUrl}/404`; - snowflake.configure({ocspFailOpen: false}); + snowflake.configure({ ocspFailOpen: false }); const connection = snowflake.createConnection(getConnectionOptions()); - async.series([ - function (callback) - { - connection.connect(function (err) - { - // should be OCSP timeout error. - assert.strictEqual(err.code, Errors.codes.ERR_SF_NETWORK_COULD_NOT_CONNECT); - if (err.cause.code === 'ECONNREFUSED') - { - console.log("run hang_webserver.py") - } - assert.strictEqual(err.cause.code, Errors.codes.ERR_OCSP_FAILED_OBTAIN_OCSP_RESPONSE); - callback(); - }); - }, - function (callback) - { - delete process.env['SF_OCSP_RESPONDER_URL']; - snowflake.configure({ocspFailOpen: true}); - callback(); + connection.connect(function (err) { + try { + // should be OCSP timeout error. + assert.strictEqual(err.code, Errors.codes.ERR_SF_NETWORK_COULD_NOT_CONNECT); + if (err.cause.code === 'ECONNREFUSED') { + Logger.getInstance().error('run hang_webserver.py'); } - ], - done - ); + assert.strictEqual(err.cause.code, Errors.codes.ERR_OCSP_FAILED_OBTAIN_OCSP_RESPONSE); + done(); + } catch (error) { + done(error); + } + }); }); const testInvalidCertConnectionOptions = [ @@ -570,36 +391,28 @@ describe('Connection with OCSP test', function () */ ]; - function connectToHttpsEndpoint(testOptions, i, connection, done) - { - connection.connect(function (err) - { + function connectToHttpsEndpoint(testOptions, i, connection, done) { + connection.connect(function (err) { assert.ok(err); - if (err) - { + if (err) { assert.strictEqual(err.code, Errors.codes.ERR_SF_NETWORK_COULD_NOT_CONNECT); assert.strictEqual(err.cause.code, testInvalidCertConnectionOptions[i].errorCode); } - if (i === testInvalidCertConnectionOptions.length - 1) - { + if (i === testInvalidCertConnectionOptions.length - 1) { done(); - } - else - { + } else { testOptions(i + 1); } }); } - it('OCSP Invalid Certificate', function (done) - { - const testOptions = function (i) - { - console.log('==> ' + testInvalidCertConnectionOptions[i].connectString.accessUrl); + it('OCSP Invalid Certificate', function (done) { + const testOptions = function (i) { + Logger.getInstance().error('==> ' + testInvalidCertConnectionOptions[i].connectString.accessUrl); const connection = snowflake.createConnection( testInvalidCertConnectionOptions[i].connectString); - connectToHttpsEndpoint(testOptions, i, connection, done) + connectToHttpsEndpoint(testOptions, i, connection, done); }; testOptions(0); }); diff --git a/test/integration/testProxyExecute.js b/test/integration/testProxyExecute.js index 866dfe43f..2ae7c291e 100644 --- a/test/integration/testProxyExecute.js +++ b/test/integration/testProxyExecute.js @@ -8,7 +8,7 @@ const os = require('os'); describe('Execute proxy test', function () { const platform = os.platform(); - if (platform === 'linux') { + if (platform === 'linux' && !process.env.SHOULD_SKIP_PROXY_TESTS) { let connection; const createNodeTSQL = 'create or replace table NodeT(colA number, colB varchar)'; const selectAllSQL = 'select * from NodeT';