diff --git a/lib/agent/socket_util.js b/lib/agent/socket_util.js index 2d67a6daa..fbeb9dfca 100644 --- a/lib/agent/socket_util.js +++ b/lib/agent/socket_util.js @@ -18,6 +18,8 @@ const ocspFailOpenWarning = 'without OCSP based Certificated Revocation checking as it could not obtain a valid OCSP Response to use from ' + 'the CA OCSP responder. Details: '; +const socketSecuredEvent = 'secureConnect'; + const rawOcspFlag = process.env.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED; @@ -72,7 +74,7 @@ exports.secureSocket = function (socket, host, agent, mock) const validate = function () { // stop listening for the secure event - socket.removeListener('secure', validate); + socket.removeListener(socketSecuredEvent, validate); Logger.getInstance().trace('socket reused = %s', socket.isSessionReused()); @@ -86,10 +88,11 @@ exports.secureSocket = function (socket, host, agent, mock) { if (!socket.authorized) { - return socket; + Logger.getInstance().warn('Socket is not authorized: %s', socket.authorizationError); + return socket.destroy(socket.authorizationError); } // use ocsp to make sure the entire certificate chain can be trusted - const certChain = socket.ssl.getPeerCertificate(true); + const certChain = socket.getPeerCertificate(true); const vcc = mock ? mock.validateCertChain : validateCertChain; vcc(certChain, function (err) @@ -111,7 +114,7 @@ exports.secureSocket = function (socket, host, agent, mock) }; // when the socket is secure, perform additional validation - socket.on('secure', validate); + socket.on(socketSecuredEvent, validate); // block all writes until validation is complete socket.cork(); diff --git a/package.json b/package.json index ca97385cc..f15dbaf76 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "snowflake-sdk", - "version": "1.8.0", + "version": "1.9.0", "description": "Node.js driver for Snowflake", "dependencies": { "@aws-sdk/client-s3": "^3.388.0", diff --git a/test/integration/testHTAP.js b/test/integration/testHTAP.js index fb412747a..febe9b7a1 100644 --- a/test/integration/testHTAP.js +++ b/test/integration/testHTAP.js @@ -7,24 +7,37 @@ const async = require('async'); const connOption = require('./connectionOptions').valid; const testUtil = require('./testUtil'); +function getRandomDBNames() { + const dbName = 'qcc_test_db'; + const arr = []; + const randomNumber = Math.floor(Math.random() * 10000); + for (let i = 0; i < 3; i++){ + arr.push(dbName + (randomNumber + i)); + } + return arr; +} + // Only the AWS servers support the hybrid table in the GitHub action. if (process.env.CLOUD_PROVIDER === 'AWS') { describe('Query Context Cache test', function () { + this.retries(3); let connection; - - before(async () => { + const dbNames = getRandomDBNames(); + + beforeEach(async () => { connection = testUtil.createConnection(connOption); await testUtil.connectAsync(connection); }); after(async () => { + await testUtil.dropDBsIgnoringErrorsAsync(connection, dbNames); await testUtil.destroyConnectionAsync(connection); }); const querySet = [ { sqlTexts: [ - 'create or replace database db1', + `create or replace database ${dbNames[0]}`, 'create or replace hybrid table t1 (a int primary key, b int)', 'insert into t1 values (1, 2), (2, 3), (3, 4)' ], @@ -32,7 +45,7 @@ if (process.env.CLOUD_PROVIDER === 'AWS') { }, { sqlTexts: [ - 'create or replace database db2', + `create or replace database ${dbNames[1]}`, 'create or replace hybrid table t2 (a int primary key, b int)', 'insert into t2 values (1, 2), (2, 3), (3, 4)' ], @@ -40,7 +53,7 @@ if (process.env.CLOUD_PROVIDER === 'AWS') { }, { sqlTexts: [ - 'create or replace database db3', + `create or replace database ${dbNames[2]}`, 'create or replace hybrid table t3 (a int primary key, b int)', 'insert into t3 values (1, 2), (2, 3), (3, 4)' ], @@ -48,9 +61,9 @@ if (process.env.CLOUD_PROVIDER === 'AWS') { }, { sqlTexts: [ - 'select * from db1.public.t1 x, db2.public.t2 y, db3.public.t3 z where x.a = y.a and y.a = z.a;', - 'select * from db1.public.t1 x, db2.public.t2 y where x.a = y.a;', - 'select * from db2.public.t2 y, db3.public.t3 z where y.a = z.a;' + `select * from ${dbNames[0]}.public.t1 x, ${dbNames[1]}.public.t2 y, ${dbNames[2]}.public.t3 z where x.a = y.a and y.a = z.a;`, + `select * from ${dbNames[0]}.public.t1 x, ${dbNames[1]}.public.t2 y where x.a = y.a;`, + `select * from ${dbNames[1]}.public.t2 y, ${dbNames[2]}.public.t3 z where y.a = z.a;` ], QccSize: 4, }, diff --git a/test/integration/testUtil.js b/test/integration/testUtil.js index aa05e6bf6..ce9812077 100644 --- a/test/integration/testUtil.js +++ b/test/integration/testUtil.js @@ -101,6 +101,22 @@ module.exports.dropTablesIgnoringErrorsAsync = async (connection, tableNames) => } }; +/** + * Drop databases one by one if exist - any connection error is ignored + * @param connection Connection + * @param dbNames string[] + * @return {Promise} + */ +module.exports.dropDBsIgnoringErrorsAsync = async (connection, dbNames) => { + for (const dbName of dbNames) { + try { + await executeCmdAsync(connection, `DROP DATABASE IF EXISTS ${dbName}`); + } catch (e) { + console.warn(`Cannot drop database ${dbName}: ${JSON.stringify(e)}`); + } + } +}; + module.exports.checkError = function (err) { assert.ok(!err, JSON.stringify(err)); };