2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-12-01 10:15:40 -06:00
|
|
|
const common = require('../common');
|
|
|
|
const net = require('net');
|
|
|
|
const assert = require('assert');
|
2014-12-02 21:16:32 -06:00
|
|
|
|
2017-04-17 17:20:17 +05:30
|
|
|
// Using port 0 as hostname used is already invalid.
|
2017-08-11 23:04:41 -04:00
|
|
|
const c = net.createConnection(0, 'this.hostname.is.invalid');
|
2014-12-02 21:16:32 -06:00
|
|
|
|
2017-02-03 14:54:19 -05:00
|
|
|
c.on('connect', common.mustNotCall());
|
2014-12-02 21:16:32 -06:00
|
|
|
|
|
|
|
c.on('error', common.mustCall(function(e) {
|
2017-10-20 08:35:54 +02:00
|
|
|
// If Name Service Switch is available on the operating system then it
|
|
|
|
// might be configured differently (/etc/nsswitch.conf).
|
|
|
|
// If the system is configured with no dns the error code will be EAI_AGAIN,
|
|
|
|
// but if there are more services after the dns entry, for example some
|
|
|
|
// linux distributions ship a myhostname service by default which would
|
|
|
|
// still produce the ENOTFOUND error.
|
|
|
|
assert.ok(e.code === 'ENOTFOUND' || e.code === 'EAI_AGAIN');
|
2017-04-17 17:20:17 +05:30
|
|
|
assert.strictEqual(e.port, 0);
|
2017-08-11 23:04:41 -04:00
|
|
|
assert.strictEqual(e.hostname, 'this.hostname.is.invalid');
|
2014-12-02 21:16:32 -06:00
|
|
|
}));
|