diff options
author | Weijia Wang <381152119@qq.com> | 2018-02-02 17:37:25 +0800 |
---|---|---|
committer | Weijia Wang <381152119@qq.com> | 2018-02-06 15:02:38 +0800 |
commit | 4a881e04dc1659669d2e84d2307abc1b9d9cbbd1 (patch) | |
tree | 82b174837065089469c77c41b0701f1d92c249ab /test/parallel/test-http-url.parse-only-support-http-https-protocol.js | |
parent | ca473be461b87a9a6a020d9b78225139251c54c4 (diff) | |
download | android-node-v8-4a881e04dc1659669d2e84d2307abc1b9d9cbbd1.tar.gz android-node-v8-4a881e04dc1659669d2e84d2307abc1b9d9cbbd1.tar.bz2 android-node-v8-4a881e04dc1659669d2e84d2307abc1b9d9cbbd1.zip |
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>
Diffstat (limited to 'test/parallel/test-http-url.parse-only-support-http-https-protocol.js')
-rw-r--r-- | test/parallel/test-http-url.parse-only-support-http-https-protocol.js | 79 |
1 files changed, 18 insertions, 61 deletions
diff --git a/test/parallel/test-http-url.parse-only-support-http-https-protocol.js b/test/parallel/test-http-url.parse-only-support-http-https-protocol.js index 903b4ba598..986f75d307 100644 --- a/test/parallel/test-http-url.parse-only-support-http-https-protocol.js +++ b/test/parallel/test-http-url.parse-only-support-http-https-protocol.js @@ -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: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; - } +const invalidUrls = [ + 'file:///whatever', + 'mailto:asdf@asdf.com', + 'ftp://www.example.com', + 'javascript:alert(\'hello\');', + 'xmpp:foo@bar.com', + 'f://some.host/path' +]; + +invalidUrls.forEach((invalid) => { + common.expectsError( + () => { http.request(url.parse(invalid)); }, + { + code: 'ERR_INVALID_PROTOCOL', + type: Error + } + ); }); |