mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
c9fe4b67dd
PR-URL: https://github.com/nodejs/node/pull/50782 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const http = require('http');
|
|
|
|
// All of these values should cause http.request() to throw synchronously
|
|
// when passed as the value of either options.hostname or options.host
|
|
const vals = [{}, [], NaN, Infinity, -Infinity, true, false, 1, 0, new Date()];
|
|
|
|
vals.forEach((v) => {
|
|
const received = common.invalidArgTypeHelper(v);
|
|
assert.throws(
|
|
() => http.request({ hostname: v }),
|
|
{
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
name: 'TypeError',
|
|
message: 'The "options.hostname" property must be of ' +
|
|
'type string or one of undefined or null.' +
|
|
received
|
|
}
|
|
);
|
|
|
|
assert.throws(
|
|
() => http.request({ host: v }),
|
|
{
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
name: 'TypeError',
|
|
message: 'The "options.host" property must be of ' +
|
|
'type string or one of undefined or null.' +
|
|
received
|
|
}
|
|
);
|
|
});
|
|
|
|
// These values are OK and should not throw synchronously.
|
|
// Only testing for 'hostname' validation so ignore connection errors.
|
|
const dontCare = () => {};
|
|
const values = ['', undefined, null];
|
|
for (const v of values) {
|
|
http.request({ hostname: v }).on('error', dontCare).end();
|
|
http.request({ host: v }).on('error', dontCare).end();
|
|
}
|