forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net: emit an error when custom lookup resolves to a non-string address
PR-URL: nodejs#57192 Fixes: nodejs#57112 Reviewed-By: Tim Perry <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Daeyeon Jeong <[email protected]> Reviewed-By: Jason Zhang <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
- Loading branch information
1 parent
60dff42
commit 71196c4
Showing
2 changed files
with
45 additions
and
1 deletion.
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
44 changes: 44 additions & 0 deletions
44
test/parallel/test-net-connect-custom-lookup-non-string-address.mjs
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,44 @@ | ||
import * as common from '../common/index.mjs'; | ||
import net from 'node:net'; | ||
import { describe, it } from 'node:test'; | ||
|
||
const brokenCustomLookup = (_hostname, options, callback) => { | ||
// Incorrectly return an array of IPs instead of a string. | ||
callback(null, ['127.0.0.1'], options.family); | ||
}; | ||
|
||
describe('when family is ipv4', () => { | ||
it('socket emits an error when lookup does not return a string', (t, done) => { | ||
const options = { | ||
host: 'example.com', | ||
port: 80, | ||
lookup: brokenCustomLookup, | ||
family: 4 | ||
}; | ||
|
||
const socket = net.connect(options, common.mustNotCall()); | ||
socket.on('error', (err) => { | ||
t.assert.strictEqual(err.code, 'ERR_INVALID_IP_ADDRESS'); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when family is ipv6', () => { | ||
it('socket emits an error when lookup does not return a string', (t, done) => { | ||
const options = { | ||
host: 'example.com', | ||
port: 80, | ||
lookup: brokenCustomLookup, | ||
family: 6 | ||
}; | ||
|
||
const socket = net.connect(options, common.mustNotCall()); | ||
socket.on('error', (err) => { | ||
t.assert.strictEqual(err.code, 'ERR_INVALID_IP_ADDRESS'); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); |