test: improve tests for test-http-url.parse
PR-URL: https://github.com/nodejs/node/pull/18523 Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
ca473be461
commit
4a881e04dc
@ -32,7 +32,7 @@ function check(request) {
|
||||
|
||||
const server = http.createServer(function(request, response) {
|
||||
// run the check function
|
||||
check.call(this, request, response);
|
||||
check(request);
|
||||
response.writeHead(200, {});
|
||||
response.end('ok');
|
||||
server.close();
|
||||
|
@ -32,7 +32,7 @@ function check(request) {
|
||||
|
||||
const server = http.createServer(function(request, response) {
|
||||
// run the check function
|
||||
check.call(this, request, response);
|
||||
check(request);
|
||||
response.writeHead(200, {});
|
||||
response.end('ok');
|
||||
server.close();
|
||||
|
@ -40,7 +40,7 @@ function check(request) {
|
||||
|
||||
const server = http.createServer(function(request, response) {
|
||||
// run the check function
|
||||
check.call(this, request, response);
|
||||
check(request);
|
||||
response.writeHead(200, {});
|
||||
response.end('ok');
|
||||
server.close();
|
||||
|
@ -42,7 +42,7 @@ function check(request) {
|
||||
|
||||
const server = https.createServer(httpsOptions, function(request, response) {
|
||||
// run the check function
|
||||
check.call(this, request, response);
|
||||
check(request);
|
||||
response.writeHead(200, {});
|
||||
response.end('ok');
|
||||
server.close();
|
||||
|
@ -20,68 +20,25 @@
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
'use strict';
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
const common = require('../common');
|
||||
const http = require('http');
|
||||
const url = require('url');
|
||||
|
||||
const invalidUrls = [
|
||||
'file:///whatever',
|
||||
'mailto:asdf@asdf.com',
|
||||
'ftp://www.example.com',
|
||||
'javascript:alert(\'hello\');',
|
||||
'xmpp:foo@bar.com',
|
||||
'f://some.host/path'
|
||||
];
|
||||
|
||||
assert.throws(function() {
|
||||
http.request(url.parse('file:///whatever'));
|
||||
}, function(err) {
|
||||
if (err instanceof Error) {
|
||||
assert.strictEqual(
|
||||
err.message, 'Protocol "file:" not supported. Expected "http:"');
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(function() {
|
||||
http.request(url.parse('mailto:asdf@asdf.com'));
|
||||
}, function(err) {
|
||||
if (err instanceof Error) {
|
||||
assert.strictEqual(
|
||||
err.message, 'Protocol "mailto:" not supported. Expected "http:"');
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(function() {
|
||||
http.request(url.parse('ftp://www.example.com'));
|
||||
}, function(err) {
|
||||
if (err instanceof Error) {
|
||||
assert.strictEqual(
|
||||
err.message, 'Protocol "ftp:" not supported. Expected "http:"');
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(function() {
|
||||
http.request(url.parse('javascript:alert(\'hello\');'));
|
||||
}, function(err) {
|
||||
if (err instanceof Error) {
|
||||
assert.strictEqual(
|
||||
err.message, 'Protocol "javascript:" not supported. Expected "http:"');
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(function() {
|
||||
http.request(url.parse('xmpp:isaacschlueter@jabber.org'));
|
||||
}, function(err) {
|
||||
if (err instanceof Error) {
|
||||
assert.strictEqual(
|
||||
err.message, 'Protocol "xmpp:" not supported. Expected "http:"');
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(function() {
|
||||
http.request(url.parse('f://some.host/path'));
|
||||
}, function(err) {
|
||||
if (err instanceof Error) {
|
||||
assert.strictEqual(
|
||||
err.message, 'Protocol "f:" not supported. Expected "http:"');
|
||||
return true;
|
||||
}
|
||||
invalidUrls.forEach((invalid) => {
|
||||
common.expectsError(
|
||||
() => { http.request(url.parse(invalid)); },
|
||||
{
|
||||
code: 'ERR_INVALID_PROTOCOL',
|
||||
type: Error
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -32,7 +32,7 @@ function check(request) {
|
||||
|
||||
const server = http.createServer(function(request, response) {
|
||||
// run the check function
|
||||
check.call(this, request, response);
|
||||
check(request);
|
||||
response.writeHead(200, {});
|
||||
response.end('ok');
|
||||
server.close();
|
||||
|
@ -39,7 +39,7 @@ function check(request) {
|
||||
|
||||
const server = http.createServer(function(request, response) {
|
||||
// run the check function
|
||||
check.call(this, request, response);
|
||||
check(request);
|
||||
response.writeHead(200, {});
|
||||
response.end('ok');
|
||||
server.close();
|
||||
|
@ -32,7 +32,7 @@ function check(request) {
|
||||
|
||||
const server = http.createServer(function(request, response) {
|
||||
// run the check function
|
||||
check.call(this, request, response);
|
||||
check(request);
|
||||
response.writeHead(200, {});
|
||||
response.end('ok');
|
||||
server.close();
|
||||
|
Loading…
x
Reference in New Issue
Block a user