-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
1 parent
232ea3e
commit 730a1ce
Showing
8 changed files
with
25 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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:[email protected]')); | ||
}, 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:[email protected]')); | ||
}, 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:[email protected]', | ||
'ftp://www.example.com', | ||
'javascript:alert(\'hello\');', | ||
'xmpp:[email protected]', | ||
'f://some.host/path' | ||
]; | ||
|
||
invalidUrls.forEach((invalid) => { | ||
common.expectsError( | ||
() => { http.request(url.parse(invalid)); }, | ||
{ | ||
code: 'ERR_INVALID_PROTOCOL', | ||
type: Error | ||
} | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters