mitm-papandreou
Advanced tools
Comparing version 1.7.0-patch1 to 1.7.1-patch1
@@ -0,1 +1,5 @@ | ||
## 1.7.1 (Jun 13, 2020) | ||
- Fixes one test for Node v12.4. | ||
- Fixes the socket "close" event on Node v12.16.3. | ||
## 1.7.0 (Jan 30, 2019) | ||
@@ -2,0 +6,0 @@ - Adds compatibility with Node v10.15.1. |
@@ -37,6 +37,10 @@ var DuplexStream = require("stream").Duplex | ||
// End is for ReadableStream.prototype.push(null). | ||
// Finish is for WritableStream.prototype.end. | ||
// The "end" event follows ReadableStream.prototype.push(null). | ||
this.on("data", readData.bind(this)) | ||
this.on("end", readEof.bind(this)) | ||
// The "finish" event follows WritableStream.prototype.end. | ||
// | ||
// There's WritableStream.prototype._final for processing before "finish" is | ||
// emitted, but that's only available in Node v8 and later. | ||
this.on("finish", this._write.bind(this, null, null, noop)) | ||
@@ -59,3 +63,2 @@ | ||
InternalSocket.prototype.readStop = function() { this.pause() } | ||
InternalSocket.prototype.close = InternalSocket.prototype.end | ||
@@ -127,3 +130,5 @@ InternalSocket.prototype._read = noop | ||
// While it seems to have existed since Node v0.10, Node v11.2 requires | ||
// "showdown". | ||
// "shutdown". AFAICT, "shutdown" is for shutting the writable side down and | ||
// hence the use of WritableStream.prototype.end and waiting for the "finish" | ||
// event. | ||
if ( | ||
@@ -133,3 +138,3 @@ NODE_11_2_AND_LATER || | ||
) InternalSocket.prototype.shutdown = function(req) { | ||
this.once("end", req.oncomplete.bind(req, NO_ERROR, req.handle)) | ||
this.once("finish", req.oncomplete.bind(req, NO_ERROR, req.handle)) | ||
this.end() | ||
@@ -143,2 +148,9 @@ | ||
// I'm unsure of the relationship between InternalSocket.prototype.shutdown and | ||
// InternalSocket.prototype.close. | ||
InternalSocket.prototype.close = function(done) { | ||
if (!this._writableState.finished) this.end(done) | ||
else if (done) done() | ||
} | ||
// Node v0.10 will use writeQueueSize to see if it should set write request's | ||
@@ -145,0 +157,0 @@ // "cb" property or write more immediately. |
{ | ||
"name": "mitm-papandreou", | ||
"version": "1.7.0-patch1", | ||
"version": "1.7.1-patch1", | ||
"description": "Intercept and mock outgoing network TCP connections and HTTP requests for testing. Intercepts and gives you a Net.Socket, Http.IncomingMessage and Http.ServerResponse to test and respond with. Useful when testing code that hits remote servers.", | ||
@@ -19,3 +19,2 @@ "keywords": [ | ||
"bugs": "https://github.com/moll/node-mitm/issues", | ||
"author": { | ||
@@ -26,3 +25,2 @@ "name": "Andri Möll", | ||
}, | ||
"repository": { | ||
@@ -32,11 +30,12 @@ "type": "git", | ||
}, | ||
"licenses": [{ | ||
"type": "LAGPL", | ||
"url": "https://github.com/moll/node-mitm/blob/master/LICENSE" | ||
}], | ||
"licenses": [ | ||
{ | ||
"type": "LAGPL", | ||
"url": "https://github.com/moll/node-mitm/blob/master/LICENSE" | ||
} | ||
], | ||
"main": "index.js", | ||
"scripts": {"test": "make test"}, | ||
"scripts": { | ||
"test": "make test" | ||
}, | ||
"dependencies": { | ||
@@ -46,3 +45,2 @@ "underscore": ">= 1.1.6 < 1.6", | ||
}, | ||
"devDependencies": { | ||
@@ -53,4 +51,5 @@ "mocha": ">= 1.12.0 < 3", | ||
}, | ||
"engines": {"node": ">= 0.10.24"} | ||
"engines": { | ||
"node": ">= 0.10.24" | ||
} | ||
} |
@@ -19,3 +19,3 @@ Mitm.js | ||
Mitm.js works on all Node versions: ancient **v0.10**, **v0.11** and **v0.12** versions, previous and current LTS versions like **v4**, **v6** and **v8** and fresh **v10** and beyond. For all it has **automated tests** to ensure it will stay that way. | ||
Mitm.js works on all Node versions: ancient **v0.10**, **v0.11** and **v0.12** versions, previous and current LTS versions like **v4** to **v12** and the newest **v13** and beyond. For all it has **automated tests** to ensure it will stay that way. | ||
@@ -190,2 +190,5 @@ I've developed Mitm.js on a need-to basis for testing [Monday | ||
#### Custom HTTP Methods | ||
Unfortunately because [Node.js's web server doesn't seem to support custom HTTP methods](https://github.com/nodejs/node-v0.x-archive/issues/3192) (that is, ones beyond `require("http").METHODS`), Mitm.js doesn't support them out of the box either. The Node.js HTTP parser throws an error given a request with an unsupported method. However, as Mitm.js also supports intercepting at the TCP level, you could hook in your own HTTP parser. I've briefly alluded to it in [issue #63](https://github.com/moll/node-mitm/issues/63). | ||
### Bypassing interception | ||
@@ -192,0 +195,0 @@ You can bypass connections listening to the `connect` event on the Mitm instance |
@@ -15,2 +15,3 @@ var _ = require("underscore") | ||
var NODE_0_10 = Semver.satisfies(process.version, ">= 0.10 < 0.11") | ||
var newBuffer = Buffer.from || function(d, enc) { return new Buffer(d, enc) } | ||
@@ -97,2 +98,20 @@ describe("Mitm", function() { | ||
// The "close" event broke on Node v12.16.3 as the | ||
// InternalSocket.prototype.close method didn't call back if | ||
// the WritableStream had already been closed. | ||
it("must emit close on socket if ended immediately", function(done) { | ||
this.mitm.on("connection", function(socket) { socket.end() }) | ||
var socket = module.connect({host: "foo"}) | ||
socket.on("close", done.bind(null, null)) | ||
}) | ||
it("must emit close on socket if ended in next tick", function(done) { | ||
this.mitm.on("connection", function(socket) { | ||
process.nextTick(socket.end.bind(socket)) | ||
}) | ||
var socket = module.connect({host: "foo"}) | ||
socket.on("close", done.bind(null, null)) | ||
}) | ||
it("must intercept 127.0.0.1", function(done) { | ||
@@ -203,6 +222,6 @@ var server; this.mitm.on("connection", function(s) { server = s }) | ||
var client = Net.connect({host: "foo"}) | ||
server.write("Hello") | ||
server.write("Hello ☺️") | ||
client.setEncoding("utf8") | ||
client.on("data", function(data) { data.must.equal("Hello") }) | ||
client.on("data", function(data) { data.must.equal("Hello ☺️") }) | ||
client.on("data", done.bind(null, null)) | ||
@@ -224,6 +243,6 @@ }) | ||
var client = Net.connect({host: "foo"}) | ||
client.write("Hello") | ||
client.write("Hello ☺️") | ||
server.setEncoding("utf8") | ||
process.nextTick(function() { server.read().must.equal("Hello") }) | ||
process.nextTick(function() { server.read().must.equal("Hello ☺️") }) | ||
process.nextTick(done) | ||
@@ -270,7 +289,8 @@ }) | ||
var client = Net.connect({host: "foo"}) | ||
client.write(new Buffer("Hello")) | ||
client.write(newBuffer("Hello", "binary")) | ||
server.setEncoding("utf8") | ||
process.nextTick(function() { server.read().must.equal("Hello") }) | ||
process.nextTick(done) | ||
process.nextTick(function() { | ||
assertBuffers(server.read(), newBuffer("Hello", "binary")) | ||
done() | ||
}) | ||
}) | ||
@@ -284,5 +304,6 @@ | ||
server.setEncoding("utf8") | ||
process.nextTick(function() { server.read().must.equal("Hello") }) | ||
process.nextTick(done) | ||
process.nextTick(function() { | ||
assertBuffers(server.read(), newBuffer("Hello", "binary")) | ||
done() | ||
}) | ||
}) | ||
@@ -296,5 +317,6 @@ | ||
server.setEncoding("utf8") | ||
process.nextTick(function() { server.read().must.equal("Hello") }) | ||
process.nextTick(done) | ||
process.nextTick(function() { | ||
assertBuffers(server.read(), newBuffer("Hello", "binary")) | ||
done() | ||
}) | ||
}) | ||
@@ -309,4 +331,7 @@ | ||
process.nextTick(function() { | ||
server.setEncoding("ucs2") | ||
server.read().must.equal("H\u0000e\u0000l\u0000l\u0000o\u0000") | ||
assertBuffers( | ||
server.read(), | ||
newBuffer("H\u0000e\u0000l\u0000l\u0000o\u0000", "binary") | ||
) | ||
done() | ||
@@ -756,2 +781,7 @@ }) | ||
function assertBuffers(a, b) { | ||
if (a.equals) a.equals(b).must.be.true() | ||
else a.toString("utf8").must.equal(b.toString("utf8")) | ||
} | ||
function noop() {} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
58424
967
262