Skip to content

Commit 10dc25d

Browse files
starkwangMylesBorins
authored andcommitted
test: improve tests for test-http-url.parse
PR-URL: #18523 Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 9c818cf commit 10dc25d

8 files changed

+25
-68
lines changed

test/parallel/test-http-url.parse-auth-with-header-in-request.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function check(request) {
3232

3333
const server = http.createServer(function(request, response) {
3434
// run the check function
35-
check.call(this, request, response);
35+
check(request);
3636
response.writeHead(200, {});
3737
response.end('ok');
3838
server.close();

test/parallel/test-http-url.parse-auth.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function check(request) {
3232

3333
const server = http.createServer(function(request, response) {
3434
// run the check function
35-
check.call(this, request, response);
35+
check(request);
3636
response.writeHead(200, {});
3737
response.end('ok');
3838
server.close();

test/parallel/test-http-url.parse-basic.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function check(request) {
4040

4141
const server = http.createServer(function(request, response) {
4242
// run the check function
43-
check.call(this, request, response);
43+
check(request);
4444
response.writeHead(200, {});
4545
response.end('ok');
4646
server.close();

test/parallel/test-http-url.parse-https.request.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function check(request) {
4242

4343
const server = https.createServer(httpsOptions, function(request, response) {
4444
// run the check function
45-
check.call(this, request, response);
45+
check(request);
4646
response.writeHead(200, {});
4747
response.end('ok');
4848
server.close();

test/parallel/test-http-url.parse-only-support-http-https-protocol.js

+18-61
Original file line numberDiff line numberDiff line change
@@ -20,68 +20,25 @@
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
'use strict';
23-
require('../common');
24-
const assert = require('assert');
23+
const common = require('../common');
2524
const http = require('http');
2625
const url = require('url');
2726

28-
29-
assert.throws(function() {
30-
http.request(url.parse('file:///whatever'));
31-
}, function(err) {
32-
if (err instanceof Error) {
33-
assert.strictEqual(
34-
err.message, 'Protocol "file:" not supported. Expected "http:"');
35-
return true;
36-
}
37-
});
38-
39-
assert.throws(function() {
40-
http.request(url.parse('mailto:[email protected]'));
41-
}, function(err) {
42-
if (err instanceof Error) {
43-
assert.strictEqual(
44-
err.message, 'Protocol "mailto:" not supported. Expected "http:"');
45-
return true;
46-
}
47-
});
48-
49-
assert.throws(function() {
50-
http.request(url.parse('ftp://www.example.com'));
51-
}, function(err) {
52-
if (err instanceof Error) {
53-
assert.strictEqual(
54-
err.message, 'Protocol "ftp:" not supported. Expected "http:"');
55-
return true;
56-
}
57-
});
58-
59-
assert.throws(function() {
60-
http.request(url.parse('javascript:alert(\'hello\');'));
61-
}, function(err) {
62-
if (err instanceof Error) {
63-
assert.strictEqual(
64-
err.message, 'Protocol "javascript:" not supported. Expected "http:"');
65-
return true;
66-
}
67-
});
68-
69-
assert.throws(function() {
70-
http.request(url.parse('xmpp:[email protected]'));
71-
}, function(err) {
72-
if (err instanceof Error) {
73-
assert.strictEqual(
74-
err.message, 'Protocol "xmpp:" not supported. Expected "http:"');
75-
return true;
76-
}
77-
});
78-
79-
assert.throws(function() {
80-
http.request(url.parse('f://some.host/path'));
81-
}, function(err) {
82-
if (err instanceof Error) {
83-
assert.strictEqual(
84-
err.message, 'Protocol "f:" not supported. Expected "http:"');
85-
return true;
86-
}
27+
const invalidUrls = [
28+
'file:///whatever',
29+
30+
'ftp://www.example.com',
31+
'javascript:alert(\'hello\');',
32+
33+
'f://some.host/path'
34+
];
35+
36+
invalidUrls.forEach((invalid) => {
37+
common.expectsError(
38+
() => { http.request(url.parse(invalid)); },
39+
{
40+
code: 'ERR_INVALID_PROTOCOL',
41+
type: Error
42+
}
43+
);
8744
});

test/parallel/test-http-url.parse-path.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function check(request) {
3232

3333
const server = http.createServer(function(request, response) {
3434
// run the check function
35-
check.call(this, request, response);
35+
check(request);
3636
response.writeHead(200, {});
3737
response.end('ok');
3838
server.close();

test/parallel/test-http-url.parse-post.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function check(request) {
3939

4040
const server = http.createServer(function(request, response) {
4141
// run the check function
42-
check.call(this, request, response);
42+
check(request);
4343
response.writeHead(200, {});
4444
response.end('ok');
4545
server.close();

test/parallel/test-http-url.parse-search.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function check(request) {
3232

3333
const server = http.createServer(function(request, response) {
3434
// run the check function
35-
check.call(this, request, response);
35+
check(request);
3636
response.writeHead(200, {});
3737
response.end('ok');
3838
server.close();

0 commit comments

Comments
 (0)