Skip to content

Commit

Permalink
Ensure we have fully decoded the request in the no mock early exit case.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjeffburke committed Jul 14, 2016
1 parent d4bc1f1 commit ce80ad1
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions lib/unexpectedMitm.js
Expand Up @@ -800,6 +800,33 @@ module.exports = {
unchunkedBody: Buffer.concat(result.body)
}, metadata);

if (!hasRequestDescription) {
// there was no mock so arrange "<no response>"
assertMockResponse(null);

/*
* We wish to cause the generation of a diff
* so we arrange to enter our 'success' path
* but ensure the delegated assertion fully
* completes by signalling an error condition.
* Given we later fail on "to satisfy" we pass
* a null fulfilment value.
*
* Note the use of the single reject/resolve
* behaviour of promises: while the delegated
* assertion is reject()ed, we have already
* resolve()d thus the rejection of the former
* is effectively ignored and we proceed with
* our output.
*/

// cancel the delegated assertion
lastHijackedSocket.emit('error', new Error('unexpected-mitm: Saw unexpected requests.'));
// continue with current assertion
resolve([null, httpConversation, httpConversationSatisfySpec]);
return [null, null];
}

if (typeof responseProperties === 'function') {
// reset the readable req stream state
stream.Readable.call(req);
Expand Down Expand Up @@ -916,32 +943,6 @@ module.exports = {
});
}

if (!hasRequestDescription) {
// there was no mock so arrange "<no response>"
assertMockResponse(null);

/*
* We wish to cause the generation of a diff
* so we arrange to enter our 'success' path
* but ensure the delegated assertion fully
* completes by signalling an error condition.
* Given we later fail on "to satisfy" we pass
* a null fulfilment value.
*
* Note the use of the single reject/resolve
* behaviour of promises: while the delegated
* assertion is reject()ed, we have already
* resolve()d thus the rejection of the former
* is effectively ignored and we proceed with
* our output.
*/

// cancel the delegated assertion
lastHijackedSocket.emit('error', new Error('unexpected-mitm: Saw unexpected requests.'));
// continue with current assertion
resolve([null, httpConversation, httpConversationSatisfySpec]);
}

/*
* hook final write callback to record raw data and immediately
* assert request so it occurs prior to request completion
Expand Down

0 comments on commit ce80ad1

Please sign in to comment.