formacao
This commit is contained in:
+9
@@ -106,3 +106,12 @@ test('WSS Equal', (t) => {
|
||||
runTest(t, suite)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('URI Equals tolerates malformed fragments', (t) => {
|
||||
t.equal(
|
||||
fastURI.equal('http://example.com/#%E0%A4A', 'http://example.com/#%E0%A4A'),
|
||||
true,
|
||||
'malformed fragment does not throw during equality checks'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
+5
@@ -150,6 +150,11 @@ test('URI parse', (t) => {
|
||||
t.equal(components.query, undefined, 'query')
|
||||
t.equal(components.fragment, '%0D', 'fragment')
|
||||
|
||||
// malformed percent-encoded fragment must not throw
|
||||
components = fastURI.parse('http://example.com/#%E0%A4A')
|
||||
t.equal(components.error, 'URI malformed', 'malformed fragment errors')
|
||||
t.equal(components.fragment, '%E0%A4A', 'malformed fragment is preserved')
|
||||
|
||||
// all
|
||||
components = fastURI.parse('uri://user:pass@example.com:123/one/two.three?q1=a1&q2=a2#body')
|
||||
t.equal(components.error, undefined, 'all errors')
|
||||
|
||||
+9
@@ -76,3 +76,12 @@ test('URN Resolving', (t) => {
|
||||
t.equal(fastURI.resolve('urn:some:other:prop', 'urn:some:ip:prop'), 'urn:some:ip:prop', 'urn:some:ip:prop')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('URI Resolving tolerates malformed fragments', (t) => {
|
||||
t.equal(
|
||||
fastURI.resolve('http://base.com/', 'http://example.com/#%E0%A4A'),
|
||||
'http://example.com/#%E0%A4A',
|
||||
'malformed fragment does not throw during resolve'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
'use strict'
|
||||
|
||||
const test = require('tape')
|
||||
const fastURI = require('..')
|
||||
|
||||
test('parse preserves reserved path escapes as data', (t) => {
|
||||
const components = fastURI.parse('http://example.com/a%2Fb/public/%2e%2e/admin')
|
||||
|
||||
t.equal(components.path, '/a%2Fb/public/%2E%2E/admin')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('normalize preserves percent-encoded path separators and dot segments', (t) => {
|
||||
t.equal(
|
||||
fastURI.normalize('http://example.com/public/%2e%2e/admin'),
|
||||
'http://example.com/public/%2E%2E/admin'
|
||||
)
|
||||
|
||||
t.equal(
|
||||
fastURI.normalize('http://example.com/a%2Fb'),
|
||||
'http://example.com/a%2Fb'
|
||||
)
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('equal does not treat reserved path escapes as live path syntax', (t) => {
|
||||
t.equal(
|
||||
fastURI.equal('http://example.com/public/%2e%2e/admin', 'http://example.com/admin', {}),
|
||||
false
|
||||
)
|
||||
|
||||
t.equal(
|
||||
fastURI.equal('http://example.com/a%2Fb', 'http://example.com/a/b', {}),
|
||||
false
|
||||
)
|
||||
|
||||
t.end()
|
||||
})
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
'use strict'
|
||||
|
||||
const test = require('tape')
|
||||
const fastURI = require('..')
|
||||
|
||||
test('parse marks malformed authority and port inputs as errors', (t) => {
|
||||
const malformedCases = [
|
||||
{
|
||||
input: 'http://[::1]foo',
|
||||
expectedError: 'URI path must start with "/" when authority is present.'
|
||||
},
|
||||
{
|
||||
input: 'http://[::1]:80abc/path',
|
||||
expectedError: 'URI path must start with "/" when authority is present.'
|
||||
},
|
||||
{
|
||||
input: 'http://example.com:80abc/path',
|
||||
expectedError: 'URI path must start with "/" when authority is present.'
|
||||
},
|
||||
{
|
||||
input: 'http://[::1]:65536',
|
||||
expectedError: 'URI port is malformed.'
|
||||
}
|
||||
]
|
||||
|
||||
t.plan(malformedCases.length)
|
||||
|
||||
malformedCases.forEach(({ input, expectedError }) => {
|
||||
t.equal(fastURI.parse(input).error, expectedError, input)
|
||||
})
|
||||
})
|
||||
|
||||
test('normalize does not canonicalize malformed URLs into different valid URLs', (t) => {
|
||||
const malformedCases = [
|
||||
'http://[::1]foo',
|
||||
'http://[::1]:80abc/path',
|
||||
'http://example.com:80abc/path',
|
||||
'http://[::1]:65536'
|
||||
]
|
||||
|
||||
t.plan(malformedCases.length)
|
||||
|
||||
malformedCases.forEach((input) => {
|
||||
t.equal(fastURI.normalize(input), input, input)
|
||||
})
|
||||
})
|
||||
|
||||
test('equal returns false when either side is malformed', (t) => {
|
||||
const malformedPairs = [
|
||||
['http://[::1]foo', 'http://[::1]/foo'],
|
||||
['http://[::1]:80abc/path', 'http://[::1]/abc/path'],
|
||||
['http://example.com:80abc/path', 'http://example.com/abc/path'],
|
||||
['http://[::1]:65536', 'http://[::1]:65536/']
|
||||
]
|
||||
|
||||
t.plan(malformedPairs.length)
|
||||
|
||||
malformedPairs.forEach(([left, right]) => {
|
||||
t.equal(fastURI.equal(left, right), false, `${left} != ${right}`)
|
||||
})
|
||||
})
|
||||
|
||||
test('normalize preserves encoded authority delimiters in host', (t) => {
|
||||
const cases = [
|
||||
['http://trusted.com%40evil.com/', 'http://trusted.com%40evil.com/'],
|
||||
['http://example.com%3A8080/', 'http://example.com%3A8080/'],
|
||||
['http://example.com%2Fevil.com/path', 'http://example.com%2Fevil.com/path'],
|
||||
['http://example.com%23fragment/path', 'http://example.com%23fragment/path'],
|
||||
['http://example.com%3Fq=evil/path', 'http://example.com%3Fq=evil/path'],
|
||||
['http://user%3Apass%40evil.com/', 'http://user%3Apass%40evil.com/'],
|
||||
['http://user@trusted.com%40evil.com/', 'http://user@trusted.com%40evil.com/'],
|
||||
['https://trusted.com%40evil.com/', 'https://trusted.com%40evil.com/'],
|
||||
['ws://trusted.com%40evil.com/chat', 'ws://trusted.com%40evil.com/chat'],
|
||||
['wss://trusted.com%40evil.com/chat', 'wss://trusted.com%40evil.com/chat']
|
||||
]
|
||||
|
||||
t.plan(cases.length)
|
||||
|
||||
cases.forEach(([input, expected]) => {
|
||||
t.equal(fastURI.normalize(input), expected, input)
|
||||
})
|
||||
})
|
||||
|
||||
test('parse preserves encoded authority delimiters in host', (t) => {
|
||||
const cases = [
|
||||
['http://trusted.com%40evil.com/', 'trusted.com%40evil.com'],
|
||||
['http://example.com%3A8080/', 'example.com%3A8080'],
|
||||
['http://user%3Apass%40evil.com/', 'user%3Apass%40evil.com']
|
||||
]
|
||||
|
||||
t.plan(cases.length)
|
||||
|
||||
cases.forEach(([input, expectedHost]) => {
|
||||
t.equal(fastURI.parse(input).host, expectedHost, input)
|
||||
})
|
||||
})
|
||||
|
||||
test('equal returns false when encoded delimiters differ from live delimiters', (t) => {
|
||||
const pairs = [
|
||||
['http://trusted.com%40evil.com/', 'http://trusted.com@evil.com/'],
|
||||
['http://example.com%3A8080/', 'http://example.com:8080/']
|
||||
]
|
||||
|
||||
t.plan(pairs.length)
|
||||
|
||||
pairs.forEach(([left, right]) => {
|
||||
t.equal(fastURI.equal(left, right, {}), false, `${left} != ${right}`)
|
||||
})
|
||||
})
|
||||
|
||||
test('resolve preserves encoded authority delimiters', (t) => {
|
||||
const result = fastURI.resolve('http://base.com/', '//trusted.com%40evil.com/path')
|
||||
const parsed = fastURI.parse(result)
|
||||
|
||||
t.plan(1)
|
||||
t.notEqual(parsed.host, 'evil.com', '//trusted.com%40evil.com/path')
|
||||
})
|
||||
|
||||
test('serialize escapes authority delimiters in host field', (t) => {
|
||||
const result = fastURI.serialize({ scheme: 'http', host: 'trusted.com@evil.com', path: '/' })
|
||||
const parsed = fastURI.parse(result)
|
||||
|
||||
t.plan(1)
|
||||
t.notEqual(parsed.host, 'evil.com', 'host: trusted.com@evil.com')
|
||||
})
|
||||
|
||||
test('normalize does not double-decode %2540 into a live @', (t) => {
|
||||
const result = fastURI.normalize('http://trusted.com%2540evil.com/')
|
||||
const parsed = fastURI.parse(result)
|
||||
|
||||
t.plan(1)
|
||||
t.notEqual(parsed.host, 'trusted.com@evil.com', 'http://trusted.com%2540evil.com/')
|
||||
})
|
||||
Reference in New Issue
Block a user