|
| 1 | +// Copyright Joyent, Inc. and other Node contributors. |
| 2 | +// |
| 3 | +// Permission is hereby granted, free of charge, to any person obtaining a |
| 4 | +// copy of this software and associated documentation files (the |
| 5 | +// "Software"), to deal in the Software without restriction, including |
| 6 | +// without limitation the rights to use, copy, modify, merge, publish, |
| 7 | +// distribute, sublicense, and/or sell copies of the Software, and to permit |
| 8 | +// persons to whom the Software is furnished to do so, subject to the |
| 9 | +// following conditions: |
| 10 | +// |
| 11 | +// The above copyright notice and this permission notice shall be included |
| 12 | +// in all copies or substantial portions of the Software. |
| 13 | +// |
| 14 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 | +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 16 | +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN |
| 17 | +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 18 | +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 19 | +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 20 | +// USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 21 | + |
| 22 | +var common = require('../common'); |
| 23 | +var assert = require('assert'); |
| 24 | +var http = require('http'); |
| 25 | +var url = require('url'); |
| 26 | + |
| 27 | + |
| 28 | +assert.throws(function() { |
| 29 | + http.request(url.parse('file:///whatever')); |
| 30 | +}, function(err) { |
| 31 | + if (err instanceof Error) { |
| 32 | + assert.strictEqual(err.message, 'Protocol:file: not supported.'); |
| 33 | + return true; |
| 34 | + } |
| 35 | +}); |
| 36 | + |
| 37 | +assert.throws(function() { |
| 38 | + http.request(url.parse('mailto:asdf@asdf.com')); |
| 39 | +}, function(err) { |
| 40 | + if (err instanceof Error) { |
| 41 | + assert.strictEqual(err.message, 'Protocol:mailto: not supported.'); |
| 42 | + return true; |
| 43 | + } |
| 44 | +}); |
| 45 | + |
| 46 | +assert.throws(function() { |
| 47 | + http.request(url.parse('ftp://www.example.com')); |
| 48 | +}, function(err) { |
| 49 | + if (err instanceof Error) { |
| 50 | + assert.strictEqual(err.message, 'Protocol:ftp: not supported.'); |
| 51 | + return true; |
| 52 | + } |
| 53 | +}); |
| 54 | + |
| 55 | +assert.throws(function() { |
| 56 | + http.request(url.parse('javascript:alert(\'hello\');')); |
| 57 | +}, function(err) { |
| 58 | + if (err instanceof Error) { |
| 59 | + assert.strictEqual(err.message, 'Protocol:javascript: not supported.'); |
| 60 | + return true; |
| 61 | + } |
| 62 | +}); |
| 63 | + |
| 64 | +assert.throws(function() { |
| 65 | + http.request(url.parse('xmpp:isaacschlueter@jabber.org')); |
| 66 | +}, function(err) { |
| 67 | + if (err instanceof Error) { |
| 68 | + assert.strictEqual(err.message, 'Protocol:xmpp: not supported.'); |
| 69 | + return true; |
| 70 | + } |
| 71 | +}); |
| 72 | + |
| 73 | +assert.throws(function() { |
| 74 | + http.request(url.parse('f://some.host/path')); |
| 75 | +}, function(err) { |
| 76 | + if (err instanceof Error) { |
| 77 | + assert.strictEqual(err.message, 'Protocol:f: not supported.'); |
| 78 | + return true; |
| 79 | + } |
| 80 | +}); |
| 81 | + |
| 82 | +//TODO do I need to test url.parse(notPrococol.example.com)? |
0 commit comments