node/test/parallel/test-http-invalid-urls.js
Hackzzila 564048dc29
http,https,tls: switch to WHATWG URL parser
This switches the url parser from `url.parse()` to the WHATWG URL
parser while keeping `url.parse()` as fallback.

Also add tests for invalid url deprecations and correct hostname
checks.

PR-URL: https://github.com/nodejs/node/pull/20270
Fixes: https://github.com/nodejs/node/issues/19468
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2018-04-29 17:03:16 +02:00

31 lines
731 B
JavaScript

/* eslint-disable node-core/crypto-check */
'use strict';
const common = require('../common');
const http = require('http');
const modules = { 'http': http };
if (common.hasCrypto) {
const https = require('https');
modules.https = https;
}
function test(host) {
['get', 'request'].forEach((fn) => {
Object.keys(modules).forEach((module) => {
const doNotCall = common.mustNotCall(
`${module}.${fn} should not connect to ${host}`
);
const throws = () => { modules[module][fn](host, doNotCall); };
common.expectsError(throws, {
type: TypeError,
code: 'ERR_INVALID_URL'
});
});
});
}
['www.nodejs.org', 'localhost', '127.0.0.1', 'http://:80/'].forEach(test);