Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

unexpected-mitm

Package Overview
Dependencies
Maintainers
1
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unexpected-mitm - npm Package Compare versions

Comparing version 2.1.1 to 2.2.0

23

lib/unexpectedMitm.js

@@ -250,3 +250,4 @@ /* global setImmediate, after */

var bypassNextConnect = false,
lastHijackedSocket;
lastHijackedSocket,
lastHijackedSocketOptions;

@@ -259,9 +260,10 @@ mitm.on('connect', function (socket, opts) {

lastHijackedSocket = socket;
lastHijackedSocketOptions = opts;
}
}).on('request', createSerializedRequestHandler(function (req, res) {
var recordedExchange = {
request: {
request: _.extend({
url: req.method + ' ' + req.url,
headers: formatHeaderObj(req.headers)
},
}, _.pick(lastHijackedSocketOptions.agent && lastHijackedSocketOptions.agent.options, messy.HttpRequest.metadataPropertyNames)),
response: {}

@@ -374,6 +376,8 @@ };

httpConversationSatisfySpec = {exchanges: []},
lastHijackedSocket;
lastHijackedSocket,
lastHijackedSocketOptions;
mitm.on('connect', function (socket, opts) {
lastHijackedSocket = socket;
lastHijackedSocketOptions = opts;
}).on('request', createSerializedRequestHandler(function (req, res) {

@@ -383,3 +387,2 @@ if (callbackCalled) {

}
var noMoreMockedOutRequests = nextRequestDescriptionIndex >= requestDescriptions.length,

@@ -391,3 +394,3 @@ requestDescription = requestDescriptions[nextRequestDescriptionIndex],

mockResponseBodyIsReady = true,
actualRequest = new messy.HttpRequest({
actualRequest = new messy.HttpRequest(_.extend({
method: req.method,

@@ -399,3 +402,3 @@ path: req.url,

encrypted: req.connection.encrypted // Waiting for https://github.com/moll/node-mitm/issues/10
});
}, _.pick(lastHijackedSocketOptions.agent && lastHijackedSocketOptions.agent.options, messy.HttpRequest.metadataPropertyNames)));
if (!noMoreMockedOutRequests) {

@@ -473,9 +476,5 @@ if (Object.prototype.toString.call(responseProperties) === '[object Error]') {

httpConversation.exchanges.push(httpExchange);
var httpConversationSnapshot = new messy.HttpConversation({
exchanges: [].concat(httpConversation.exchanges)
});
if (expectedRequestProperties) {
httpConversationSatisfySpec.exchanges.push({request: expectedRequestProperties || {}});
}
var httpConversationSatisfySpecSnapshot = { exchanges: [].concat(httpConversationSatisfySpec.exchanges) };
bufferStream(req, passError(handleError, function (body) {

@@ -498,3 +497,3 @@ if (callbackCalled) {

that.errorMode = 'default';
expect(httpConversationSnapshot, 'to satisfy', httpConversationSatisfySpecSnapshot);
expect(httpConversation, 'to satisfy', httpConversationSatisfySpec);
} catch (e) {

@@ -501,0 +500,0 @@ that.errorMode = 'nested';

{
"name": "unexpected-mitm",
"version": "2.1.1",
"version": "2.2.0",
"description": "Unexpected plugin for the mitm library",

@@ -18,4 +18,4 @@ "main": "lib/unexpectedMitm.js",

"unexpected": "5.8.1",
"unexpected-http": "1.7.1",
"unexpected-messy": "2.10.0"
"unexpected-http": "1.8.0",
"unexpected-messy": "2.11.0"
},

@@ -26,3 +26,3 @@ "dependencies": {

"memoizesync": "0.5.0",
"messy": "4.1.1",
"messy": "4.3.0",
"mitm-papandreou": "1.0.3-patch1",

@@ -29,0 +29,0 @@ "mocha": "2.1.0",

@@ -340,2 +340,71 @@ /*global describe, it, __dirname*/

describe('wíth a client certificate', function () {
describe('when asserting on ca/cert/key', function () {
it('should succeed', function (done) {
expect({
url: 'https://www.google.com/foo',
cert: new Buffer([1]),
key: new Buffer([2]),
ca: new Buffer([3])
}, 'with http mocked out', {
request: {
url: 'GET /foo',
cert: new Buffer([1]),
key: new Buffer([2]),
ca: new Buffer([3])
},
response: 200
}, 'to yield response', 200, done);
});
it('should fail with a meaningful error message', function (done) {
expect({
url: 'https://www.google.com/foo',
cert: new Buffer([1]),
key: new Buffer([2]),
ca: new Buffer([3])
}, 'with http mocked out', {
request: {
url: 'GET /foo',
cert: new Buffer([1]),
key: new Buffer([5]),
ca: new Buffer([3])
},
response: 200
}, 'to yield response', 200, function (err) {
expect(err, 'to be an', Error);
expect(err.output.toString('text').replace(/^Date:.*\n/m, ''), 'to equal',
'expected\n' +
'{\n' +
" url: 'https://www.google.com/foo',\n" +
' cert: Buffer([0x01]),\n' +
' key: Buffer([0x02]),\n' +
' ca: Buffer([0x03])\n' +
'}\n' +
'with http mocked out\n' +
'{\n' +
' request: {\n' +
" url: '/foo',\n" +
' cert: Buffer([0x01]),\n' +
' key: Buffer([0x05]),\n' +
' ca: Buffer([0x03]),\n' +
" method: 'GET'\n" +
' },\n' +
' response: 200\n' +
'} to yield response 200\n' +
'\n' +
'GET /foo HTTP/1.1\n' +
'Host: www.google.com\n' +
'Connection: keep-alive\n' +
'// key: expected Buffer([0x02]) to satisfy Buffer([0x05])\n' +
'// -02 │.│\n' +
'// +05 │.│\n' +
'\n' +
'HTTP/1.1 200 OK');
done();
});
});
});
});
it('should record', function (done) {

@@ -351,2 +420,11 @@ expect({

it('should record a client certificate', function (done) {
expect({
url: 'POST https://www.google.com/',
cert: new Buffer([1]),
key: new Buffer([2]),
ca: new Buffer([3])
}, 'with http recorded', 'to yield response', 200, done);
});
it('should record some more', function (done) {

@@ -353,0 +431,0 @@ expect({

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc