Skip to content

Commit

Permalink
inject resetAndDestroy into socket in test for older versions of node
Browse files Browse the repository at this point in the history
  • Loading branch information
RythenGlyth committed Oct 16, 2023
1 parent d077116 commit 17322c2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 9 additions & 0 deletions test/MockFtpServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 7 additions & 1 deletion test/downloadSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`
}
Expand Down

0 comments on commit 17322c2

Please sign in to comment.