From 436f81ea15aea9a022b62e28ccf3ddca5b0a82de Mon Sep 17 00:00:00 2001 From: Dominik Przybysz Date: Tue, 3 Oct 2023 14:24:58 +0200 Subject: [PATCH] SNOW-929946: Extract before and after each methods --- test/integration/testConnectionWithOCSP.js | 139 ++++----------------- 1 file changed, 24 insertions(+), 115 deletions(-) diff --git a/test/integration/testConnectionWithOCSP.js b/test/integration/testConnectionWithOCSP.js index 51ac0db75..dcf242e25 100644 --- a/test/integration/testConnectionWithOCSP.js +++ b/test/integration/testConnectionWithOCSP.js @@ -42,15 +42,35 @@ function getConnectionOptions() describe('Connection with OCSP test', function () { - function deleteCache() - { + function deleteCache () { OcspResponseCache.deleteCache(); } + function cleanupOcspState () { + OcspResponseCache.deleteCache(); + snowflake.configure({ ocspFailOpen: true }); + SocketUtil.variables.OCSP_RESPONSE_CACHE = undefined; + SocketUtil.variables.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED = 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) { - deleteCache(); - snowflake.configure({ocspFailOpen: true}); const connection = snowflake.createConnection(getConnectionOptions()); async.series([ @@ -69,8 +89,6 @@ describe('Connection with OCSP test', function () it('OCSP Validity Error - Fail Open', function (done) { - deleteCache(); - SocketUtil.variables.OCSP_RESPONSE_CACHE = undefined; SocketUtil.variables.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED = false; // inject validity error process.env.SF_OCSP_TEST_INJECT_VALIDITY_ERROR = 'true'; @@ -87,11 +105,6 @@ describe('Connection with OCSP test', function () callback(); }); }, - function (callback) - { - delete process.env['SF_OCSP_TEST_INJECT_VALIDITY_ERROR']; - callback(); - } ], done ); @@ -99,8 +112,6 @@ describe('Connection with OCSP test', function () it('OCSP Validity Error - Fail Closed', function (done) { - deleteCache(); - SocketUtil.variables.OCSP_RESPONSE_CACHE = undefined; SocketUtil.variables.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED = false; // inject validity error process.env.SF_OCSP_TEST_INJECT_VALIDITY_ERROR = 'true'; @@ -118,12 +129,6 @@ describe('Connection with OCSP test', function () callback(); }); }, - function (callback) - { - delete process.env['SF_OCSP_TEST_INJECT_VALIDITY_ERROR']; - snowflake.configure({ocspFailOpen: true}); - callback(); - } ], done ); @@ -131,13 +136,10 @@ describe('Connection with OCSP test', function () it('OCSP Unknown Cert - Fail Open', function (done) { - deleteCache(); - SocketUtil.variables.OCSP_RESPONSE_CACHE = undefined; 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([ @@ -149,11 +151,6 @@ describe('Connection with OCSP test', function () callback(); }); }, - function (callback) - { - delete process.env['SF_OCSP_TEST_INJECT_UNKNOWN_STATUS']; - callback(); - } ], done ); @@ -161,8 +158,6 @@ describe('Connection with OCSP test', function () it('OCSP Unknown Cert - Fail Closed', function (done) { - deleteCache(); - SocketUtil.variables.OCSP_RESPONSE_CACHE = undefined; SocketUtil.variables.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED = false; // inject validity error process.env.SF_OCSP_TEST_INJECT_UNKNOWN_STATUS = 'true'; @@ -184,12 +179,6 @@ describe('Connection with OCSP test', function () callback(); }); }, - function (callback) - { - delete process.env['SF_OCSP_TEST_INJECT_UNKNOWN_STATUS']; - snowflake.configure({ocspFailOpen: true}); - callback(); - } ], done ); @@ -197,7 +186,6 @@ describe('Connection with OCSP test', function () /* it('OCSP Revoked Cert - Fail Open', function (done) { - snowflake.configure({ocspFailOpen: true}); const connection = snowflake.createConnection(testRevokedConnectionOptions); async.series([ @@ -228,11 +216,6 @@ describe('Connection with OCSP test', function () callback(); }); }, - function (callback) - { - snowflake.configure({ocspFailOpen: true}); - callback(); - } ], done ); @@ -240,15 +223,12 @@ describe('Connection with OCSP test', function () it('OCSP Cache Server Timeout - Fail Open', function (done) { - deleteCache(); - SocketUtil.variables.OCSP_RESPONSE_CACHE = undefined; // 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([ @@ -262,13 +242,6 @@ describe('Connection with OCSP test', function () 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 ); @@ -276,8 +249,6 @@ describe('Connection with OCSP test', function () it('OCSP Cache Server Timeout - Fail Closed', function (done) { - deleteCache(); - SocketUtil.variables.OCSP_RESPONSE_CACHE = undefined; // cache server is used SocketUtil.variables.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED = true; // fake OCSP responder. @@ -302,13 +273,6 @@ describe('Connection with OCSP test', function () 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(); - } ], done ); @@ -316,15 +280,12 @@ describe('Connection with OCSP test', function () it('OCSP Responder Timeout - Fail Open', function (done) { - deleteCache(); - SocketUtil.variables.OCSP_RESPONSE_CACHE = undefined; // 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([ @@ -338,13 +299,6 @@ describe('Connection with OCSP test', function () 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 ); @@ -352,8 +306,6 @@ describe('Connection with OCSP test', function () it('OCSP Responder Timeout - Fail Closed', function (done) { - deleteCache(); - SocketUtil.variables.OCSP_RESPONSE_CACHE = undefined; // no cache server is used SocketUtil.variables.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED = false; // fake OCSP responder. @@ -382,13 +334,6 @@ describe('Connection with OCSP test', function () 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 ); @@ -396,8 +341,6 @@ describe('Connection with OCSP test', function () it('OCSP Cache Server and Responder Timeout - Fail Open', function (done) { - deleteCache(); - SocketUtil.variables.OCSP_RESPONSE_CACHE = undefined; // no cache server is used SocketUtil.variables.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED = true; // fake OCSP responder. @@ -406,7 +349,6 @@ 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([ @@ -419,14 +361,6 @@ describe('Connection with OCSP test', function () 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 ); @@ -434,8 +368,6 @@ describe('Connection with OCSP test', function () it('OCSP Responder 403 - Fail Closed', function (done) { - deleteCache(); - SocketUtil.variables.OCSP_RESPONSE_CACHE = undefined; // no cache server is used SocketUtil.variables.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED = false; // fake OCSP responder. @@ -463,12 +395,6 @@ describe('Connection with OCSP test', function () callback(); }); }, - function (callback) - { - delete process.env['SF_OCSP_RESPONDER_URL']; - snowflake.configure({ocspFailOpen: true}); - callback(); - } ], done ); @@ -476,14 +402,11 @@ describe('Connection with OCSP test', function () it('OCSP Responder 403 - Fail Open', function (done) { - deleteCache(); - SocketUtil.variables.OCSP_RESPONSE_CACHE = undefined; // 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([ @@ -496,12 +419,6 @@ describe('Connection with OCSP test', function () callback(); }); }, - function (callback) - { - delete process.env['SF_OCSP_RESPONDER_URL']; - snowflake.configure({ocspFailOpen: true}); - callback(); - } ], done ); @@ -509,8 +426,6 @@ describe('Connection with OCSP test', function () it('OCSP Responder 404 - Fail Closed', function (done) { - deleteCache(); - SocketUtil.variables.OCSP_RESPONSE_CACHE = undefined; // no cache server is used SocketUtil.variables.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED = false; // fake OCSP responder. @@ -534,12 +449,6 @@ describe('Connection with OCSP test', function () callback(); }); }, - function (callback) - { - delete process.env['SF_OCSP_RESPONDER_URL']; - snowflake.configure({ocspFailOpen: true}); - callback(); - } ], done );