diff --git a/test/MockFtpServer.js b/test/MockFtpServer.js index 541501e..dc1aaab 100644 --- a/test/MockFtpServer.js +++ b/test/MockFtpServer.js @@ -39,6 +39,15 @@ module.exports = class MockFtpServer { }) this.dataConn = undefined this.dataServer = net.createServer(conn => { + if(!conn.resetAndDestroy) { + conn.resetAndDestroy = () => { + conn._handle.reset(() => { + this.conn.emit("close") + }) + conn._handle.onread = () =>{}; + conn._handle = null; + } + } this.dataConn = conn this.connections.push(conn) this.didOpenDataConn() diff --git a/test/downloadSpec.js b/test/downloadSpec.js index 5845560..fc6c67a 100644 --- a/test/downloadSpec.js +++ b/test/downloadSpec.js @@ -148,11 +148,17 @@ describe("Download to stream", function() { dataSocket.destroy(new Error("Error that should be ignored because task has completed successfully")) }) it("handles early data socket closure", async () => { + /** + * type of this.client + * @type {Client} + */ + this.client; + this.server.addHandlers({ "pasv": () => `227 Entering Passive Mode (${this.server.dataAddressForPasvResponse})`, "retr": ({arg}) => { //close data connection such that client receives ECONNRESET - this.server.dataConn.resetAndDestroy?.() + this.server.dataConn.resetAndDestroy() return `550 ${arg}: No such file or directory.` }