Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: improve tests for test-http-url.parse #18523

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-url.parse-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-url.parse-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-url.parse-https.request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');


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:[email protected]'));
}, 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:[email protected]'));
}, 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;
}
const invalidUrls = [
'file:///whatever',
'mailto:[email protected]',
'ftp://www.example.com',
'javascript:alert(\'hello\');',
'xmpp:[email protected]',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would prefer to remove the real persons address here and use a generic one.

'f://some.host/path'
];

invalidUrls.forEach((invalid) => {
common.expectsError(
() => { http.request(url.parse(invalid)); },
{
code: 'ERR_INVALID_PROTOCOL',
type: Error
}
);
});
2 changes: 1 addition & 1 deletion test/parallel/test-http-url.parse-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-url.parse-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-url.parse-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down