From e25ab0ff66485a58a3e94a76141a8ac027c672cc Mon Sep 17 00:00:00 2001 From: Gustav Nikolaj Olsen Date: Fri, 2 Sep 2016 12:07:14 +0200 Subject: [PATCH] wip: footgun protective boots. --- lib/unexpectedMitm.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/unexpectedMitm.js b/lib/unexpectedMitm.js index a078f60..5aa0d48 100644 --- a/lib/unexpectedMitm.js +++ b/lib/unexpectedMitm.js @@ -829,9 +829,20 @@ module.exports = { .addAssertion(' with http mocked out [and verified] [with extra info] ', function (expect, subject, requestDescriptions) { // ... expect.errorMode = 'nested'; var mitm = createMitm(); + var cleanedUpMitm = false; var shouldBeVerified = checkEnvFlag('UNEXPECTED_MITM_VERIFY') || expect.flags['and verified']; var shouldReturnExtraInfo = expect.flags['with extra info']; + // XXX: Register footgun detection in case an uncaught exception + // breaks the test in such a way that our finally block will not + // be called, and mitm thus will not be cleaned up. + afterEach(function () { + if (!cleanedUpMitm) { + cleanedUpMitm = true; + mitm.disable(); + } + }); + if (!Array.isArray(requestDescriptions)) { if (typeof requestDescriptions === 'undefined') { requestDescriptions = []; @@ -1120,6 +1131,7 @@ module.exports = { } }); }).finally(function () { + cleanedUpMitm = true; mitm.disable(); });