From 768dd02da275fa0fe3cb1ed31f6e0bade6466b1f Mon Sep 17 00:00:00 2001 From: Andris Reinman Date: Thu, 11 Jan 2018 09:43:31 +0200 Subject: [PATCH] updated boolean check in api --- lib/api/2fa/totp.js | 3 ++- lib/api/addresses.js | 22 ++++++++++++++------ lib/api/asps.js | 3 ++- lib/api/autoreply.js | 3 ++- lib/api/filters.js | 30 ++++++++++++++++++--------- lib/api/mailboxes.js | 7 +++++-- lib/api/messages.js | 49 +++++++++++++++++++++++++++++--------------- lib/api/submit.js | 3 ++- lib/api/users.js | 48 ++++++++++++++++++++++++------------------- 9 files changed, 109 insertions(+), 59 deletions(-) diff --git a/lib/api/2fa/totp.js b/lib/api/2fa/totp.js index 05d414aa..49444ed7 100644 --- a/lib/api/2fa/totp.js +++ b/lib/api/2fa/totp.js @@ -18,7 +18,8 @@ module.exports = (db, server, userHandler) => { .max(255) .required(), fresh: Joi.boolean() - .truthy(['Y', 'true', 'yes', 1]) + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .default(false), sess: Joi.string().max(255), ip: Joi.string().ip({ diff --git a/lib/api/addresses.js b/lib/api/addresses.js index ec87842f..6cc4fa50 100644 --- a/lib/api/addresses.js +++ b/lib/api/addresses.js @@ -241,8 +241,12 @@ module.exports = (db, server) => { .required(), Joi.string().regex(/^\w+@\*$/, 'special address') ], - main: Joi.boolean().truthy(['Y', 'true', 'yes', 1]), - allowWildcard: Joi.boolean().truthy(['Y', 'true', 'yes', 1]) + main: Joi.boolean() + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']), + allowWildcard: Joi.boolean() + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) }); const result = Joi.validate(req.params, schema, { @@ -716,7 +720,8 @@ module.exports = (db, server) => { .length(24) .required(), main: Joi.boolean() - .truthy(['Y', 'true', 'yes', 1]) + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .required() }); @@ -1058,10 +1063,13 @@ module.exports = (db, server) => { forwards: Joi.number() .min(0) .default(0), - allowWildcard: Joi.boolean().truthy(['Y', 'true', 'yes', 1]), + allowWildcard: Joi.boolean() + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']), autoreply: Joi.object().keys({ status: Joi.boolean() - .truthy(['Y', 'true', 'yes', 1]) + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .default(true), start: Joi.date() .empty('') @@ -1349,7 +1357,9 @@ module.exports = (db, server) => { .min(1), forwards: Joi.number().min(0), autoreply: Joi.object().keys({ - status: Joi.boolean().truthy(['Y', 'true', 'yes', 1]), + status: Joi.boolean() + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']), start: Joi.date() .empty('') .allow(false), diff --git a/lib/api/asps.js b/lib/api/asps.js index 2be3b2cb..6fc2bc2e 100644 --- a/lib/api/asps.js +++ b/lib/api/asps.js @@ -224,7 +224,8 @@ module.exports = (db, server, userHandler) => { ) .unique(), generateMobileconfig: Joi.boolean() - .truthy(['Y', 'true', 'yes', 1]) + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .default(false), expires: Joi.date(), sess: Joi.string().max(255), diff --git a/lib/api/autoreply.js b/lib/api/autoreply.js index 6acc4c46..c83a031c 100644 --- a/lib/api/autoreply.js +++ b/lib/api/autoreply.js @@ -58,7 +58,8 @@ module.exports = (db, server) => { .length(24) .required(), status: Joi.boolean() - .truthy(['Y', 'true', 'yes', 1]) + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .default(false), subject: Joi.string() .empty('') diff --git a/lib/api/filters.js b/lib/api/filters.js index 5266ead2..f3689cc8 100644 --- a/lib/api/filters.js +++ b/lib/api/filters.js @@ -503,21 +503,26 @@ module.exports = (db, server) => { .max(255) .empty(''), query_ha: Joi.boolean() - .truthy(['Y', 'true', 'yes', 1]) + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .empty(''), query_size: Joi.number().empty(''), action_seen: Joi.boolean() - .truthy(['Y', 'true', 'yes', 1]) + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .empty(''), action_flag: Joi.boolean() - .truthy(['Y', 'true', 'yes', 1]) + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .empty(''), action_delete: Joi.boolean() - .truthy(['Y', 'true', 'yes', 1]) + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .empty(''), action_spam: Joi.boolean() - .truthy(['Y', 'true', 'yes', 1]) + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .empty(''), action_mailbox: Joi.string() @@ -784,21 +789,26 @@ module.exports = (db, server) => { .max(255) .empty(''), query_ha: Joi.boolean() - .truthy(['Y', 'true', 'yes', 1]) + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .empty(''), query_size: Joi.number().empty(''), action_seen: Joi.boolean() - .truthy(['Y', 'true', 'yes', 1]) + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .empty(''), action_flag: Joi.boolean() - .truthy(['Y', 'true', 'yes', 1]) + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .empty(''), action_delete: Joi.boolean() - .truthy(['Y', 'true', 'yes', 1]) + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .empty(''), action_spam: Joi.boolean() - .truthy(['Y', 'true', 'yes', 1]) + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .empty(''), action_mailbox: Joi.string() diff --git a/lib/api/mailboxes.js b/lib/api/mailboxes.js index ff0bc4a3..4516a788 100644 --- a/lib/api/mailboxes.js +++ b/lib/api/mailboxes.js @@ -79,7 +79,8 @@ module.exports = (db, server, mailboxHandler) => { .length(24) .required(), counters: Joi.boolean() - .truthy(['Y', 'true', 'yes', 1]) + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .default(false) }); @@ -531,7 +532,9 @@ module.exports = (db, server, mailboxHandler) => { .required(), path: Joi.string().regex(/\/{2,}|\/$/g, { invert: true }), retention: Joi.number().min(0), - subscribed: Joi.boolean().truthy(['Y', 'true', 'yes', 1]) + subscribed: Joi.boolean() + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) }); const result = Joi.validate(req.params, schema, { diff --git a/lib/api/messages.js b/lib/api/messages.js index eab9a579..ce90f265 100644 --- a/lib/api/messages.js +++ b/lib/api/messages.js @@ -408,10 +408,12 @@ module.exports = (db, server, messageHandler) => { .empty(''), attachments: Joi.boolean() .empty('') - .truthy('true'), + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']), flagged: Joi.boolean() .empty('') - .truthy('true'), + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']), limit: Joi.number() .default(20) .min(1) @@ -834,10 +836,12 @@ module.exports = (db, server, messageHandler) => { .min(1) .required(), replaceCidLinks: Joi.boolean() - .truthy(['Y', 'true', 'yes', 1]) + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .default(false), markAsSeen: Joi.boolean() - .truthy(['Y', 'true', 'yes', 1]) + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .default(false) }); @@ -1566,14 +1570,23 @@ module.exports = (db, server, messageHandler) => { message: Joi.string() .regex(/^\d+(,\d+)*$|^\d+:\d+$|/i) .required(), - seen: Joi.boolean().truthy(['Y', 'true', 'yes', 1]), - deleted: Joi.boolean().truthy(['Y', 'true', 'yes', 1]), - flagged: Joi.boolean().truthy(['Y', 'true', 'yes', 1]), - draft: Joi.boolean().truthy(['Y', 'true', 'yes', 1]), + seen: Joi.boolean() + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']), + deleted: Joi.boolean() + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']), + flagged: Joi.boolean() + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']), + draft: Joi.boolean() + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']), expires: Joi.alternatives().try( Joi.date(), Joi.boolean() - .truthy(['Y', 'true', 'yes', 1]) + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .allow(false) ) }); @@ -1870,13 +1883,16 @@ module.exports = (db, server, messageHandler) => { .required(), date: Joi.date(), unseen: Joi.boolean() - .truthy(['Y', 'true', 'yes', 1]) + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .default(false), flagged: Joi.boolean() - .truthy(['Y', 'true', 'yes', 1]) + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .default(false), draft: Joi.boolean() - .truthy(['Y', 'true', 'yes', 1]) + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .default(false), raw: Joi.binary() .max(consts.MAX_ALLOWE_MESSAGE_SIZE) @@ -2003,9 +2019,9 @@ module.exports = (db, server, messageHandler) => { success: status, message: data ? { - id: data.uid, - mailbox: data.mailbox - } + id: data.uid, + mailbox: data.mailbox + } : false }); return next(); @@ -2593,7 +2609,8 @@ module.exports = (db, server, messageHandler) => { .length(24) .required(), replaceCidLinks: Joi.boolean() - .truthy(['Y', 'true', 'yes', 1]) + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .default(false) }); diff --git a/lib/api/submit.js b/lib/api/submit.js index 6720fc23..f31b224a 100644 --- a/lib/api/submit.js +++ b/lib/api/submit.js @@ -597,7 +597,8 @@ module.exports = (db, server, messageHandler, userHandler) => { uploadOnly: Joi.boolean() .empty('') - .truthy('true') + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .default(false), sendTime: Joi.date(), diff --git a/lib/api/users.js b/lib/api/users.js index 56a887dd..6eeb40ab 100644 --- a/lib/api/users.js +++ b/lib/api/users.js @@ -144,21 +144,21 @@ module.exports = (db, server, userHandler) => { let filter = query ? { - $or: [ - { - address: { - $regex: query.replace(/\./g, ''), - $options: '' - } - }, - { - unameview: { - $regex: query.replace(/\./g, ''), - $options: '' - } - } - ] - } + $or: [ + { + address: { + $regex: query.replace(/\./g, ''), + $options: '' + } + }, + { + unameview: { + $regex: query.replace(/\./g, ''), + $options: '' + } + } + ] + } : {}; let tagSeen = new Set(); @@ -355,7 +355,8 @@ module.exports = (db, server, userHandler) => { address: Joi.string().email(), emptyAddress: Joi.boolean() - .truthy(['Y', 'true', 'yes', 1]) + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .default(false), language: Joi.string() @@ -395,10 +396,12 @@ module.exports = (db, server, userHandler) => { .trim() .regex(/^-----BEGIN PGP PUBLIC KEY BLOCK-----/, 'PGP key format'), encryptMessages: Joi.boolean() - .truthy(['Y', 'true', 'yes', 1]) + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .default(false), encryptForwarded: Joi.boolean() - .truthy(['Y', 'true', 'yes', 1]) + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']) .default(false), sess: Joi.string().max(255), ip: Joi.string().ip({ @@ -880,10 +883,12 @@ module.exports = (db, server, userHandler) => { .regex(/^-----BEGIN PGP PUBLIC KEY BLOCK-----/, 'PGP key format'), encryptMessages: Joi.boolean() .empty('') - .truthy(['Y', 'true', 'yes', 1]), + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']), encryptForwarded: Joi.boolean() .empty('') - .truthy(['Y', 'true', 'yes', 1]), + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']), retention: Joi.number().min(0), quota: Joi.number().min(0), recipients: Joi.number().min(0), @@ -901,7 +906,8 @@ module.exports = (db, server, userHandler) => { disabled: Joi.boolean() .empty('') - .truthy(['Y', 'true', 'yes', 1]), + .truthy(['Y', 'true', 'yes', 'on', 1]) + .falsy(['N', 'false', 'no', 'off', 0, '']), sess: Joi.string().max(255), ip: Joi.string().ip({ version: ['ipv4', 'ipv6'],