Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
Merge pull request #1116 from mozilla/phil/device-validation
Browse files Browse the repository at this point in the history
fix(server): eliminate device validation discrepancies
  • Loading branch information
rfk committed Nov 18, 2015
2 parents 4703b83 + 6722204 commit addc9d6
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 12 deletions.
18 changes: 9 additions & 9 deletions lib/routes/account.js
Expand Up @@ -59,7 +59,7 @@ module.exports = function (
resume: isA.string().max(2048).optional(),
preVerifyToken: isA.string().max(2048).regex(BASE64_JWT).optional(),
device: isA.object({
name: isA.string().max(255).optional(),
name: isA.string().max(255).optional().allow(''),
type: isA.string().max(16).required(),
pushCallback: isA.string().uri({ scheme: 'https' }).max(255).optional().allow(''),
pushPublicKey: isA.string().length(64).regex(HEX_STRING).optional().allow('')
Expand All @@ -76,7 +76,7 @@ module.exports = function (
device: isA.object({
id: isA.string().length(32).regex(HEX_STRING).required(),
createdAt: isA.number().positive().required(),
name: isA.string().max(255).optional(),
name: isA.string().max(255).optional().allow(''),
type: isA.string().max(16).required(),
pushCallback: isA.string().uri({ scheme: 'https' }).max(255).optional().allow(''),
pushPublicKey: isA.string().length(64).regex(HEX_STRING).optional().allow('')
Expand Down Expand Up @@ -287,7 +287,7 @@ module.exports = function (
reason: isA.string().max(16).optional(),
device: isA.object({
id: isA.string().length(32).regex(HEX_STRING).optional(),
name: isA.string().max(255).optional(),
name: isA.string().max(255).optional().allow(''),
type: isA.string().max(16).optional(),
pushCallback: isA.string().uri({ scheme: 'https' }).max(255).optional().allow(''),
pushPublicKey: isA.string().length(64).regex(HEX_STRING).optional().allow('')
Expand All @@ -305,7 +305,7 @@ module.exports = function (
device: isA.object({
id: isA.string().length(32).regex(HEX_STRING).required(),
createdAt: isA.number().positive().optional(),
name: isA.string().max(255).optional(),
name: isA.string().max(255).optional().allow(''),
type: isA.string().max(16).optional(),
pushCallback: isA.string().uri({ scheme: 'https' }).max(255).optional().allow(''),
pushPublicKey: isA.string().length(64).regex(HEX_STRING).optional().allow('')
Expand Down Expand Up @@ -723,7 +723,7 @@ module.exports = function (
validate: {
payload: isA.object({
id: isA.string().length(32).regex(HEX_STRING).optional(),
name: isA.string().max(255).optional(),
name: isA.string().max(255).optional().allow(''),
type: isA.string().max(16).optional(),
pushCallback: isA.string().uri({ scheme: 'https' }).max(255).optional().allow(''),
pushPublicKey: isA.string().length(64).regex(HEX_STRING).optional().allow('')
Expand All @@ -733,7 +733,7 @@ module.exports = function (
schema: {
id: isA.string().length(32).regex(HEX_STRING).required(),
createdAt: isA.number().positive().optional(),
name: isA.string().max(255).optional(),
name: isA.string().max(255).optional().allow(''),
type: isA.string().max(16).optional(),
pushCallback: isA.string().uri({ scheme: 'https' }).max(255).optional().allow(''),
pushPublicKey: isA.string().length(64).regex(HEX_STRING).optional().allow('')
Expand Down Expand Up @@ -764,10 +764,10 @@ module.exports = function (
schema: isA.array().items(isA.object({
id: isA.string().length(32).regex(HEX_STRING).required(),
sessionToken: isA.string().length(64).regex(HEX_STRING).required(),
name: isA.string().max(255).required().allow(''),
name: isA.string().max(255).optional().allow(''),
type: isA.string().max(16).required(),
pushCallback: isA.string().uri({ scheme: 'https' }).max(255).required().allow(''),
pushPublicKey: isA.string().length(64).regex(HEX_STRING).required()
pushCallback: isA.string().uri({ scheme: 'https' }).max(255).optional().allow(''),
pushPublicKey: isA.string().length(64).regex(HEX_STRING).optional()
}))
}
},
Expand Down
54 changes: 51 additions & 3 deletions test/remote/device_tests.js
Expand Up @@ -125,7 +125,7 @@ TestServer.start(config)
.then(
function (client) {
var deviceInfo = {
name: 'test device',
name: '',
type: 'mobile',
pushCallback: '',
pushPublicKey: ''
Expand Down Expand Up @@ -155,9 +155,9 @@ TestServer.start(config)
.then(
function (devices) {
t.equal(devices.length, 1, 'devices returned one item')
t.equal(devices[0].name, deviceInfo.name, 'devices returned correct name')
t.equal(devices[0].name, '', 'devices returned empty name')
t.equal(devices[0].type, deviceInfo.type, 'devices returned correct type')
t.equal(devices[0].pushCallback, deviceInfo.pushCallback, 'devices returned correct pushCallback')
t.equal(devices[0].pushCallback, '', 'devices returned empty pushCallback')
t.deepEqual(devices[0].pushPublicKey, '0000000000000000000000000000000000000000000000000000000000000000', 'devices returned correct pushPublicKey')
return client.destroyDevice(devices[0].id)
}
Expand All @@ -167,6 +167,54 @@ TestServer.start(config)
}
)

test(
'device registration without optional parameters',
function (t) {
var email = server.uniqueEmail()
var password = 'test password'
return Client.create(config.publicUrl, email, password)
.then(
function (client) {
var deviceInfo = {
type: 'mobile'
}
return client.devices()
.then(
function (devices) {
t.equal(devices.length, 0, 'devices returned no items')
return client.updateDevice(deviceInfo)
}
)
.then(
function (device) {
t.ok(device.id, 'device.id was set')
t.ok(device.createdAt > 0, 'device.createdAt was set')
t.equal(device.name, undefined, 'device.name is undefined')
t.equal(device.type, deviceInfo.type, 'device.type is correct')
t.equal(device.pushCallback, undefined, 'device.pushCallback is undefined')
t.deepEqual(device.pushPublicKey, undefined, 'device.pushPublicKey is undefined')
}
)
.then(
function () {
return client.devices()
}
)
.then(
function (devices) {
t.equal(devices.length, 1, 'devices returned one item')
t.equal(devices[0].name, undefined, 'devices returned undefined name')
t.equal(devices[0].type, deviceInfo.type, 'devices returned correct type')
t.equal(devices[0].pushCallback, undefined, 'devices returned undefined pushCallback')
t.deepEqual(devices[0].pushPublicKey, undefined, 'devices returned undefined pushPublicKey')
return client.destroyDevice(devices[0].id)
}
)
}
)
}
)

test(
'teardown',
function (t) {
Expand Down

0 comments on commit addc9d6

Please sign in to comment.