summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-url.parse-only-support-http-https-protocol.js
blob: 5e49193181032c00e0e33b9b9c4462bbb632136c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'use strict';
var common = require('../common');
var assert = require('assert');
var http = require('http');
var 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;
  }
});

//TODO do I need to test url.parse(notPrococol.example.com)?