|
20 | 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. |
21 | 21 |
|
22 | 22 | 'use strict'; |
23 | | -require('../common'); |
24 | | -const assert = require('assert'); |
| 23 | +const common = require('../common'); |
25 | 24 | const http = require('http'); |
26 | 25 | const url = require('url'); |
27 | 26 |
|
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:asdf@asdf.com')); |
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:isaacschlueter@jabber.org')); |
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 | + 'mailto:asdf@asdf.com', |
| 30 | + 'ftp://www.example.com', |
| 31 | + 'javascript:alert(\'hello\');', |
| 32 | + 'xmpp:foo@bar.com', |
| 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 | + ); |
87 | 44 | }); |
0 commit comments