fix(validation): fix url port validation

This commit is contained in:
vladikoff 2018-09-07 13:43:59 -04:00
Родитель f73a063ffc
Коммит 3aa84cfe35
2 изменённых файлов: 47 добавлений и 2 удалений

Просмотреть файл

@ -170,6 +170,13 @@ function isValidUrl(url, hostnameRegex) {
// The only trick here is that `new URL()` will add a trailing
// slash if there's no path component, which is why we also
// compare to `origin` below.
// if the original url has a :443 in the url we need to strip it for the check below
// to follow the `new URL` behaviour.
if (/^https:\/\//.test(url) && /:443($|\/[^\d])/.test(url)) {
url = url.replace(':443', '')
}
if (parsed.href !== url && parsed.origin !== url) {
return false
}

Просмотреть файл

@ -376,9 +376,47 @@ describe('remote device', function () {
)
it(
'update device works with callback urls that have ports',
'update device works with callback urls that :443 as a port',
() => {
var goodPushCallback = 'https://updates.push.services.mozilla.com:433'
var goodPushCallback = 'https://updates.push.services.mozilla.com:443'
var email = server.uniqueEmail()
var password = 'test password'
return Client.create(config.publicUrl, email, password)
.then(
function (client) {
var deviceInfo = {
name: 'test device',
type: 'mobile',
pushCallback: goodPushCallback,
pushPublicKey: '',
pushAuthKey: ''
}
return client.devices()
.then(
function (devices) {
assert.equal(devices.length, 0, 'devices returned no items')
return client.updateDevice(deviceInfo)
}
)
.then(
function (device) {
assert.ok(device.id, 'device.id was set')
assert.equal(device.pushCallback, deviceInfo.pushCallback, 'device.pushCallback is correct')
}
)
.catch(
function (err) {
assert.fail(err, 'request should have worked')
}
)
})
}
)
it(
'update device works with callback urls that a custom port',
() => {
var goodPushCallback = 'https://updates.push.services.mozilla.com:10332'
var email = server.uniqueEmail()
var password = 'test password'
return Client.create(config.publicUrl, email, password)