mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: body-parser-2.x test (#13278)
* feat: body-parser-2.x test * fix req.body
This commit is contained in:
committed by
GitHub
parent
57819810ce
commit
389bc062e3
@@ -45,7 +45,7 @@
|
|||||||
"autoprefixer": "10.4.21",
|
"autoprefixer": "10.4.21",
|
||||||
"bcryptjs": "3.0.2",
|
"bcryptjs": "3.0.2",
|
||||||
"benchpressjs": "2.5.3",
|
"benchpressjs": "2.5.3",
|
||||||
"body-parser": "1.20.3",
|
"body-parser": "2.2.0",
|
||||||
"bootbox": "6.0.0",
|
"bootbox": "6.0.0",
|
||||||
"bootstrap": "5.3.3",
|
"bootstrap": "5.3.3",
|
||||||
"bootswatch": "5.3.3",
|
"bootswatch": "5.3.3",
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ Posts.get = async (req, res) => {
|
|||||||
|
|
||||||
Posts.getIndex = async (req, res) => {
|
Posts.getIndex = async (req, res) => {
|
||||||
const { pid } = req.params;
|
const { pid } = req.params;
|
||||||
const { sort } = req.body;
|
const { sort } = req.body || {};
|
||||||
|
|
||||||
const index = await api.posts.getIndex(req, { pid, sort });
|
const index = await api.posts.getIndex(req, { pid, sort });
|
||||||
if (index === null) {
|
if (index === null) {
|
||||||
|
|||||||
@@ -287,7 +287,9 @@ middleware.validateAuth = helpers.try(async (req, res, next) => {
|
|||||||
|
|
||||||
middleware.checkRequired = function (fields, req, res, next) {
|
middleware.checkRequired = function (fields, req, res, next) {
|
||||||
// Used in API calls to ensure that necessary parameters/data values are present
|
// Used in API calls to ensure that necessary parameters/data values are present
|
||||||
const missing = fields.filter(field => !req.body.hasOwnProperty(field) && !req.query.hasOwnProperty(field));
|
const missing = fields.filter(
|
||||||
|
field => req.body && !req.body.hasOwnProperty(field) && !req.query.hasOwnProperty(field)
|
||||||
|
);
|
||||||
|
|
||||||
if (!missing.length) {
|
if (!missing.length) {
|
||||||
return next();
|
return next();
|
||||||
|
|||||||
@@ -62,8 +62,9 @@ module.exports = function (middleware) {
|
|||||||
return await finishLogin(req, user);
|
return await finishLogin(req, user);
|
||||||
} else if (user.hasOwnProperty('master') && user.master === true) {
|
} else if (user.hasOwnProperty('master') && user.master === true) {
|
||||||
// If the token received was a master token, a _uid must also be present for all calls
|
// If the token received was a master token, a _uid must also be present for all calls
|
||||||
if (req.body.hasOwnProperty('_uid') || req.query.hasOwnProperty('_uid')) {
|
const body = req.body || {};
|
||||||
user.uid = req.body._uid || req.query._uid;
|
if (body.hasOwnProperty('_uid') || req.query.hasOwnProperty('_uid')) {
|
||||||
|
user.uid = body._uid || req.query._uid;
|
||||||
delete user.master;
|
delete user.master;
|
||||||
return await finishLogin(req, user);
|
return await finishLogin(req, user);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user