-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net: support blocklist in net.connect
PR-URL: #56075 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
- Loading branch information
Showing
5 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const net = require('net'); | ||
const assert = require('assert'); | ||
|
||
const blockList = new net.BlockList(); | ||
blockList.addAddress('127.0.0.1'); | ||
blockList.addAddress('127.0.0.2'); | ||
|
||
function check(err) { | ||
assert.ok(err.code === 'ERR_IP_BLOCKED', err); | ||
} | ||
|
||
// Connect without calling dns.lookup | ||
{ | ||
const socket = net.connect({ | ||
port: 9999, | ||
host: '127.0.0.1', | ||
blockList, | ||
}); | ||
socket.on('error', common.mustCall(check)); | ||
} | ||
|
||
// Connect with single IP returned by dns.lookup | ||
{ | ||
const socket = net.connect({ | ||
port: 9999, | ||
host: 'localhost', | ||
blockList, | ||
lookup: function(_, __, cb) { | ||
cb(null, '127.0.0.1', 4); | ||
}, | ||
autoSelectFamily: false, | ||
}); | ||
|
||
socket.on('error', common.mustCall(check)); | ||
} | ||
|
||
// Connect with autoSelectFamily and single IP | ||
{ | ||
const socket = net.connect({ | ||
port: 9999, | ||
host: 'localhost', | ||
blockList, | ||
lookup: function(_, __, cb) { | ||
cb(null, [{ address: '127.0.0.1', family: 4 }]); | ||
}, | ||
autoSelectFamily: true, | ||
}); | ||
|
||
socket.on('error', common.mustCall(check)); | ||
} | ||
|
||
// Connect with autoSelectFamily and multiple IPs | ||
{ | ||
const socket = net.connect({ | ||
port: 9999, | ||
host: 'localhost', | ||
blockList, | ||
lookup: function(_, __, cb) { | ||
cb(null, [{ address: '127.0.0.1', family: 4 }, { address: '127.0.0.2', family: 4 }]); | ||
}, | ||
autoSelectFamily: true, | ||
}); | ||
|
||
socket.on('error', common.mustCall(check)); | ||
} |