Skip to content

Commit

Permalink
SNOW-929946: Extract before and after each methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dprzybysz committed Oct 3, 2023
1 parent 39abad3 commit 436f81e
Showing 1 changed file with 24 additions and 115 deletions.
139 changes: 24 additions & 115 deletions test/integration/testConnectionWithOCSP.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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';
Expand All @@ -87,20 +105,13 @@ describe('Connection with OCSP test', function ()
callback();
});
},
function (callback)
{
delete process.env['SF_OCSP_TEST_INJECT_VALIDITY_ERROR'];
callback();
}
],
done
);
});

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';
Expand All @@ -118,26 +129,17 @@ describe('Connection with OCSP test', function ()
callback();
});
},
function (callback)
{
delete process.env['SF_OCSP_TEST_INJECT_VALIDITY_ERROR'];
snowflake.configure({ocspFailOpen: true});
callback();
}
],
done
);
});

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([
Expand All @@ -149,20 +151,13 @@ describe('Connection with OCSP test', function ()
callback();
});
},
function (callback)
{
delete process.env['SF_OCSP_TEST_INJECT_UNKNOWN_STATUS'];
callback();
}
],
done
);
});

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';
Expand All @@ -184,20 +179,13 @@ describe('Connection with OCSP test', function ()
callback();
});
},
function (callback)
{
delete process.env['SF_OCSP_TEST_INJECT_UNKNOWN_STATUS'];
snowflake.configure({ocspFailOpen: true});
callback();
}
],
done
);
});
/*
it('OCSP Revoked Cert - Fail Open', function (done)
{
snowflake.configure({ocspFailOpen: true});
const connection = snowflake.createConnection(testRevokedConnectionOptions);
async.series([
Expand Down Expand Up @@ -228,27 +216,19 @@ describe('Connection with OCSP test', function ()
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;
// 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([
Expand All @@ -262,22 +242,13 @@ 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
);
});

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.
Expand All @@ -302,29 +273,19 @@ 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
);
});

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([
Expand All @@ -338,22 +299,13 @@ 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
);
});

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.
Expand Down Expand Up @@ -382,22 +334,13 @@ 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
);
});

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.
Expand All @@ -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([
Expand All @@ -419,23 +361,13 @@ 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
);
});

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.
Expand Down Expand Up @@ -463,27 +395,18 @@ describe('Connection with OCSP test', function ()
callback();
});
},
function (callback)
{
delete process.env['SF_OCSP_RESPONDER_URL'];
snowflake.configure({ocspFailOpen: true});
callback();
}
],
done
);
});

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([
Expand All @@ -496,21 +419,13 @@ describe('Connection with OCSP test', function ()
callback();
});
},
function (callback)
{
delete process.env['SF_OCSP_RESPONDER_URL'];
snowflake.configure({ocspFailOpen: true});
callback();
}
],
done
);
});

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.
Expand All @@ -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
);
Expand Down

0 comments on commit 436f81e

Please sign in to comment.