mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-09-08 14:15:40 +08:00
migrated API tests from icedfrisby to supertest
This commit is contained in:
parent
afacc1df07
commit
dcef8e22cd
20 changed files with 304 additions and 311 deletions
|
@ -1 +1 @@
|
|||
define({
"name": "wildduck",
"version": "1.0.0",
"description": "WildDuck API docs",
"title": "WildDuck API",
"url": "https://api.wildduck.email",
"sampleUrl": false,
"defaultVersion": "0.0.0",
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2019-07-11T07:54:04.591Z",
"url": "http://apidocjs.com",
"version": "0.17.7"
}
});
|
||||
define({
"name": "wildduck",
"version": "1.0.0",
"description": "WildDuck API docs",
"title": "WildDuck API",
"url": "https://api.wildduck.email",
"sampleUrl": false,
"defaultVersion": "0.0.0",
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2019-07-31T12:58:20.000Z",
"url": "http://apidocjs.com",
"version": "0.17.7"
}
});
|
||||
|
|
|
@ -1 +1 @@
|
|||
{
"name": "wildduck",
"version": "1.0.0",
"description": "WildDuck API docs",
"title": "WildDuck API",
"url": "https://api.wildduck.email",
"sampleUrl": false,
"defaultVersion": "0.0.0",
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2019-07-11T07:54:04.591Z",
"url": "http://apidocjs.com",
"version": "0.17.7"
}
}
|
||||
{
"name": "wildduck",
"version": "1.0.0",
"description": "WildDuck API docs",
"title": "WildDuck API",
"url": "https://api.wildduck.email",
"sampleUrl": false,
"defaultVersion": "0.0.0",
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2019-07-31T12:58:20.000Z",
"url": "http://apidocjs.com",
"version": "0.17.7"
}
}
|
||||
|
|
|
@ -72,6 +72,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -162,6 +163,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
|
|
@ -86,6 +86,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -181,6 +182,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -275,6 +277,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -368,6 +371,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -462,6 +466,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
|
|
@ -50,6 +50,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -112,6 +113,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -190,6 +192,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -250,6 +253,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -315,6 +319,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
|
|
@ -119,6 +119,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -352,6 +353,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -652,6 +654,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -808,6 +811,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -973,6 +977,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -1232,6 +1237,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -1465,6 +1471,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -1803,6 +1810,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -2081,6 +2089,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -2221,6 +2230,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -2400,6 +2410,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -2549,6 +2560,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
|
|
@ -101,6 +101,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -277,6 +278,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -434,6 +436,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -686,6 +689,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
|
|
@ -115,6 +115,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -152,6 +153,7 @@ module.exports = (db, server, userHandler) => {
|
|||
if (user) {
|
||||
response.id = user.toString();
|
||||
}
|
||||
res.status(403);
|
||||
res.json(response);
|
||||
return next();
|
||||
}
|
||||
|
@ -164,6 +166,7 @@ module.exports = (db, server, userHandler) => {
|
|||
if (user) {
|
||||
response.id = user.toString();
|
||||
}
|
||||
res.status(403);
|
||||
res.json(response);
|
||||
return next();
|
||||
}
|
||||
|
@ -186,6 +189,7 @@ module.exports = (db, server, userHandler) => {
|
|||
code: err.code || 'AuthFailed',
|
||||
id: user.toString()
|
||||
};
|
||||
res.status(500);
|
||||
res.json(response);
|
||||
return next();
|
||||
}
|
||||
|
@ -195,6 +199,7 @@ module.exports = (db, server, userHandler) => {
|
|||
authResponse.u2fAuthRequest = authData.u2fAuthRequest;
|
||||
}
|
||||
|
||||
res.status(200);
|
||||
res.json(permission.filter(authResponse));
|
||||
return next();
|
||||
})
|
||||
|
@ -364,6 +369,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -549,6 +555,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
|
|
@ -101,6 +101,7 @@ module.exports = (db, server) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -231,6 +232,7 @@ module.exports = (db, server) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -320,6 +322,7 @@ module.exports = (db, server) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
|
|
@ -119,6 +119,7 @@ module.exports = (db, server) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -252,6 +253,7 @@ module.exports = (db, server) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -397,6 +399,7 @@ module.exports = (db, server) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -504,6 +507,7 @@ module.exports = (db, server) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -591,6 +595,7 @@ module.exports = (db, server) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
|
|
@ -98,6 +98,7 @@ module.exports = (db, server) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -260,6 +261,7 @@ module.exports = (db, server) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -383,6 +385,7 @@ module.exports = (db, server) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -492,6 +495,7 @@ module.exports = (db, server) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -593,6 +597,7 @@ module.exports = (db, server) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
|
|
@ -87,6 +87,7 @@ module.exports = (db, server) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -284,6 +285,7 @@ module.exports = (db, server) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -439,6 +441,7 @@ module.exports = (db, server) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -645,6 +648,7 @@ module.exports = (db, server) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -972,6 +976,7 @@ module.exports = (db, server) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
|
|
@ -127,6 +127,7 @@ module.exports = (db, server, mailboxHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -386,6 +387,7 @@ module.exports = (db, server, mailboxHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -519,6 +521,7 @@ module.exports = (db, server, mailboxHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -701,6 +704,7 @@ module.exports = (db, server, mailboxHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -820,6 +824,7 @@ module.exports = (db, server, mailboxHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
|
|
@ -114,6 +114,7 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -401,6 +402,7 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -755,6 +757,7 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -1305,6 +1308,7 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -1600,7 +1604,7 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(500);
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -1736,6 +1740,7 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -1969,6 +1974,7 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -2092,6 +2098,7 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -2447,6 +2454,7 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -2799,6 +2807,7 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -3031,6 +3040,7 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -3358,6 +3368,7 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -3529,6 +3540,7 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -3678,6 +3690,7 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
|
|
@ -103,6 +103,7 @@ module.exports = (db, server, storageHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -260,6 +261,7 @@ module.exports = (db, server, storageHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -432,6 +434,7 @@ module.exports = (db, server, storageHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -511,6 +514,7 @@ module.exports = (db, server, storageHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
|
|
@ -861,6 +861,7 @@ module.exports = (db, server, messageHandler, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
|
|
@ -81,6 +81,7 @@ module.exports = (db, server, notifier) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
|
|
@ -139,6 +139,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -559,6 +560,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -800,6 +802,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -991,6 +994,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -1371,6 +1375,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -1576,6 +1581,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -1669,6 +1675,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -1854,6 +1861,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -1950,6 +1958,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
@ -2047,6 +2056,7 @@ module.exports = (db, server, userHandler) => {
|
|||
});
|
||||
|
||||
if (result.error) {
|
||||
res.status(400);
|
||||
res.json({
|
||||
error: result.error.message,
|
||||
code: 'InputValidationError'
|
||||
|
|
|
@ -28,10 +28,10 @@
|
|||
"grunt-mocha-test": "0.13.3",
|
||||
"grunt-shell-spawn": "0.4.0",
|
||||
"grunt-wait": "0.3.0",
|
||||
"icedfrisby": "2.2.1",
|
||||
"mailparser": "2.7.1",
|
||||
"mocha": "6.2.0",
|
||||
"request": "2.88.0"
|
||||
"request": "2.88.0",
|
||||
"supertest": "4.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@phc/pbkdf2": "1.1.14",
|
||||
|
@ -54,7 +54,7 @@
|
|||
"libmime": "4.1.3",
|
||||
"libqp": "1.1.0",
|
||||
"mailsplit": "4.4.1",
|
||||
"mobileconfig": "2.2.0",
|
||||
"mobileconfig": "2.3.0",
|
||||
"mongo-cursor-pagination": "7.1.0",
|
||||
"mongodb": "3.2.7",
|
||||
"mongodb-extended-json": "1.10.1",
|
||||
|
|
516
test/api-test.js
516
test/api-test.js
|
@ -1,346 +1,252 @@
|
|||
/*eslint no-unused-expressions: 0, prefer-arrow-callback: 0, no-console:0 */
|
||||
/* globals before: false, after: false */
|
||||
|
||||
'use strict';
|
||||
|
||||
const supertest = require('supertest');
|
||||
const chai = require('chai');
|
||||
const frisby = require('icedfrisby');
|
||||
|
||||
const expect = chai.expect;
|
||||
chai.config.includeStack = true;
|
||||
|
||||
const URL = 'http://localhost:8080';
|
||||
|
||||
let userId = false;
|
||||
const server = supertest.agent('http://localhost:8080');
|
||||
|
||||
describe('API tests', function() {
|
||||
let userId, asp, address, inbox;
|
||||
|
||||
this.timeout(10000); // eslint-disable-line no-invalid-this
|
||||
|
||||
frisby
|
||||
.create('POST domainaliases')
|
||||
.post(
|
||||
URL + '/domainaliases',
|
||||
{
|
||||
alias: 'jõgeva.öö',
|
||||
domain: 'example.com'
|
||||
},
|
||||
{ json: true }
|
||||
)
|
||||
.expectStatus(200)
|
||||
.afterJSON(response => {
|
||||
expect(response).to.exist;
|
||||
expect(response.success).to.be.true;
|
||||
})
|
||||
.toss();
|
||||
|
||||
frisby
|
||||
.create('POST users')
|
||||
.post(
|
||||
URL + '/users',
|
||||
{
|
||||
before(async () => {
|
||||
// ensure that we have an existing user account
|
||||
const response = await server
|
||||
.post('/users')
|
||||
.send({
|
||||
username: 'testuser',
|
||||
password: 'secretpass',
|
||||
address: 'testuser@example.com',
|
||||
name: 'test user'
|
||||
},
|
||||
{ json: true }
|
||||
)
|
||||
.expectStatus(200)
|
||||
.afterJSON(response => {
|
||||
expect(response).to.exist;
|
||||
expect(response.success).to.be.true;
|
||||
userId = response.id;
|
||||
})
|
||||
.expect(200);
|
||||
expect(response.body.success).to.be.true;
|
||||
expect(response.body.id).to.exist;
|
||||
|
||||
frisby
|
||||
.create('GET users/{id}')
|
||||
.get(URL + '/users/' + userId)
|
||||
.expectStatus(200)
|
||||
.afterJSON(response => {
|
||||
expect(response).to.exist;
|
||||
expect(response.success).to.be.true;
|
||||
expect(response.id).to.equal(userId);
|
||||
expect(response.name).to.equal('test user');
|
||||
})
|
||||
.toss();
|
||||
userId = response.body.id;
|
||||
});
|
||||
|
||||
frisby
|
||||
.create('PUT users/{id}')
|
||||
.put(
|
||||
URL + '/users/' + userId,
|
||||
{
|
||||
name: 'user test'
|
||||
},
|
||||
{ json: true }
|
||||
)
|
||||
.expectStatus(200)
|
||||
.afterJSON(response => {
|
||||
expect(response).to.exist;
|
||||
expect(response.success).to.be.true;
|
||||
})
|
||||
.toss();
|
||||
after(async () => {
|
||||
if (!userId) {
|
||||
return;
|
||||
}
|
||||
|
||||
frisby
|
||||
.create('POST authenticate')
|
||||
.post(
|
||||
URL + '/authenticate',
|
||||
{
|
||||
username: 'testuser@example.com',
|
||||
password: 'secretpass',
|
||||
scope: 'master'
|
||||
},
|
||||
{ json: true }
|
||||
)
|
||||
.expectStatus(200)
|
||||
.afterJSON(response => {
|
||||
expect(response).to.exist;
|
||||
expect(response.success).to.be.true;
|
||||
})
|
||||
.toss();
|
||||
const response = await server.delete(`/users/${userId}`).expect(200);
|
||||
expect(response.body.success).to.be.true;
|
||||
|
||||
frisby
|
||||
.create('POST authenticate - failure')
|
||||
.post(
|
||||
URL + '/authenticate',
|
||||
{
|
||||
username: 'testuser@example.com',
|
||||
password: 'invalid',
|
||||
scope: 'master'
|
||||
},
|
||||
{ json: true }
|
||||
)
|
||||
.afterJSON(response => {
|
||||
expect(response).to.exist;
|
||||
expect(response.error).to.exist;
|
||||
expect(response.success).to.not.be.true;
|
||||
})
|
||||
.toss();
|
||||
userId = false;
|
||||
});
|
||||
|
||||
frisby
|
||||
.create('POST authenticate - using aliasdomain')
|
||||
.post(
|
||||
URL + '/authenticate',
|
||||
{
|
||||
username: 'testuser@jõgeva.öö',
|
||||
password: 'secretpass',
|
||||
scope: 'master'
|
||||
},
|
||||
{ json: true }
|
||||
)
|
||||
.expectStatus(200)
|
||||
.afterJSON(response => {
|
||||
expect(response).to.exist;
|
||||
expect(response.success).to.be.true;
|
||||
})
|
||||
.toss();
|
||||
it('should POST /domainaliases', async () => {
|
||||
const response = await server
|
||||
.post('/domainaliases')
|
||||
.send({
|
||||
alias: 'jõgeva.öö',
|
||||
domain: 'example.com'
|
||||
})
|
||||
.expect(200);
|
||||
expect(response.body.success).to.be.true;
|
||||
});
|
||||
|
||||
frisby
|
||||
.create('POST authenticate - failure using aliasdomain')
|
||||
.post(
|
||||
URL + '/authenticate',
|
||||
{
|
||||
username: 'testuser@jõgeva.öö',
|
||||
password: 'invalid',
|
||||
scope: 'master'
|
||||
},
|
||||
{ json: true }
|
||||
)
|
||||
.afterJSON(response => {
|
||||
expect(response).to.exist;
|
||||
expect(response.error).to.exist;
|
||||
expect(response.success).to.not.be.true;
|
||||
})
|
||||
.toss();
|
||||
it('should GET /users/:user', async () => {
|
||||
const response = await server.get(`/users/${userId}`).expect(200);
|
||||
expect(response.body.success).to.be.true;
|
||||
expect(response.body.id).to.equal(userId);
|
||||
expect(response.body.name).to.equal('test user');
|
||||
});
|
||||
|
||||
frisby
|
||||
.create('POST users/{id}/asps - generate ASP')
|
||||
.post(
|
||||
URL + '/users/' + userId + '/asps',
|
||||
{
|
||||
description: 'test',
|
||||
scopes: ['imap', 'smtp'],
|
||||
generateMobileconfig: true
|
||||
},
|
||||
{ json: true }
|
||||
)
|
||||
.afterJSON(response => {
|
||||
expect(response).to.exist;
|
||||
expect(response.error).to.not.exist;
|
||||
expect(response.success).to.be.true;
|
||||
expect(response.password).to.exist;
|
||||
expect(response.mobileconfig).to.exist;
|
||||
it('should PUT /users/:user', async () => {
|
||||
const response = await server
|
||||
.put(`/users/${userId}`)
|
||||
.send({
|
||||
name: 'user test'
|
||||
})
|
||||
.expect(200);
|
||||
expect(response.body.success).to.be.true;
|
||||
});
|
||||
|
||||
let asp = response.password;
|
||||
it('should GET /users/:user (updated name)', async () => {
|
||||
const response = await server.get(`/users/${userId}`).expect(200);
|
||||
expect(response.body.success).to.be.true;
|
||||
expect(response.body.id).to.equal(userId);
|
||||
expect(response.body.name).to.equal('user test');
|
||||
});
|
||||
|
||||
frisby
|
||||
.create('POST authenticate - success on correct scope')
|
||||
.post(
|
||||
URL + '/authenticate',
|
||||
{
|
||||
username: 'testuser@example.com',
|
||||
password: asp,
|
||||
scope: 'imap'
|
||||
},
|
||||
{ json: true }
|
||||
)
|
||||
.expectStatus(200)
|
||||
.afterJSON(response => {
|
||||
expect(response).to.exist;
|
||||
expect(response.success).to.be.true;
|
||||
})
|
||||
.toss();
|
||||
it('should POST /authenticate with success', async () => {
|
||||
const response = await server
|
||||
.post(`/authenticate`)
|
||||
.send({
|
||||
username: 'testuser@example.com',
|
||||
password: 'secretpass',
|
||||
scope: 'master'
|
||||
})
|
||||
.expect(200);
|
||||
expect(response.body.success).to.be.true;
|
||||
});
|
||||
|
||||
frisby
|
||||
.create('POST authenticate - failure on incorrect scope')
|
||||
.post(
|
||||
URL + '/authenticate',
|
||||
{
|
||||
username: 'testuser@example.com',
|
||||
password: asp,
|
||||
scope: 'master'
|
||||
},
|
||||
{ json: true }
|
||||
)
|
||||
.afterJSON(response => {
|
||||
expect(response).to.exist;
|
||||
expect(response.error).to.exist;
|
||||
expect(response.success).to.not.be.true;
|
||||
})
|
||||
.toss();
|
||||
})
|
||||
.toss();
|
||||
it('should POST /authenticate with failure', async () => {
|
||||
const response = await server
|
||||
.post(`/authenticate`)
|
||||
.send({
|
||||
username: 'testuser@example.com',
|
||||
password: 'invalid',
|
||||
scope: 'master'
|
||||
})
|
||||
.expect(403);
|
||||
expect(response.body.error).to.exist;
|
||||
expect(response.body.success).to.not.be.true;
|
||||
});
|
||||
|
||||
frisby
|
||||
.create('GET users/{id} – updated name')
|
||||
.get(URL + '/users/' + userId)
|
||||
.expectStatus(200)
|
||||
.afterJSON(response => {
|
||||
expect(response).to.exist;
|
||||
expect(response.success).to.be.true;
|
||||
expect(response.id).to.equal(userId);
|
||||
expect(response.name).to.equal('user test');
|
||||
})
|
||||
.toss();
|
||||
it('should POST /authenticate using alias domain', async () => {
|
||||
const response = await server
|
||||
.post(`/authenticate`)
|
||||
.send({
|
||||
username: 'testuser@jõgeva.öö',
|
||||
password: 'secretpass',
|
||||
scope: 'master'
|
||||
})
|
||||
.expect(200);
|
||||
expect(response.body.success).to.be.true;
|
||||
});
|
||||
|
||||
frisby
|
||||
.create('GET users/{id}/addresses')
|
||||
.get(URL + '/users/' + userId + '/addresses')
|
||||
.expectStatus(200)
|
||||
.afterJSON(response => {
|
||||
expect(response).to.exist;
|
||||
expect(response.success).to.be.true;
|
||||
expect(response.results.length).to.equal(1);
|
||||
expect(response.results[0].address).to.equal('testuser@example.com');
|
||||
expect(response.results[0].main).to.be.true;
|
||||
})
|
||||
.toss();
|
||||
it('should POST /authenticate with failure using alias domain', async () => {
|
||||
const response = await server
|
||||
.post(`/authenticate`)
|
||||
.send({
|
||||
username: 'testuser@jõgeva.öö',
|
||||
password: 'invalid',
|
||||
scope: 'master'
|
||||
})
|
||||
.expect(403);
|
||||
expect(response.body.error).to.exist;
|
||||
expect(response.body.success).to.not.be.true;
|
||||
});
|
||||
|
||||
frisby
|
||||
.create('POST users/{id}/addresses')
|
||||
.post(
|
||||
URL + '/users/' + userId + '/addresses',
|
||||
{
|
||||
address: 'alias1@example.com',
|
||||
main: true
|
||||
},
|
||||
{ json: true }
|
||||
)
|
||||
.expectStatus(200)
|
||||
.afterJSON(response => {
|
||||
expect(response).to.exist;
|
||||
expect(response.success).to.be.true;
|
||||
})
|
||||
.toss();
|
||||
it('should POST /users/:user/asps to generate ASP', async () => {
|
||||
const response = await server
|
||||
.post(`/users/${userId}/asps`)
|
||||
.send({
|
||||
description: 'test',
|
||||
scopes: ['imap', 'smtp'],
|
||||
generateMobileconfig: true
|
||||
})
|
||||
.expect(200);
|
||||
expect(response.body.error).to.not.exist;
|
||||
expect(response.body.success).to.be.true;
|
||||
expect(response.body.password).to.exist;
|
||||
expect(response.body.mobileconfig).to.exist;
|
||||
|
||||
frisby
|
||||
.create('POST users/{id}/addresses')
|
||||
.post(
|
||||
URL + '/users/' + userId + '/addresses',
|
||||
{
|
||||
address: 'alias2@example.com'
|
||||
},
|
||||
{ json: true }
|
||||
)
|
||||
.expectStatus(200)
|
||||
.afterJSON(response => {
|
||||
expect(response).to.exist;
|
||||
expect(response.success).to.be.true;
|
||||
})
|
||||
.toss();
|
||||
asp = response.body.password;
|
||||
});
|
||||
|
||||
frisby
|
||||
.create('GET users/{id}/addresses – updated listing')
|
||||
.get(URL + '/users/' + userId + '/addresses')
|
||||
.expectStatus(200)
|
||||
.afterJSON(response => {
|
||||
expect(response).to.exist;
|
||||
expect(response.success).to.be.true;
|
||||
expect(response.results.length).to.equal(3);
|
||||
response.results.sort((a, b) => a.id.localeCompare(b.id));
|
||||
it('should POST /authenticate using ASP and allowed scope', async () => {
|
||||
const response = await server
|
||||
.post(`/authenticate`)
|
||||
.send({
|
||||
username: 'testuser@jõgeva.öö',
|
||||
password: asp,
|
||||
scope: 'imap'
|
||||
})
|
||||
.expect(200);
|
||||
expect(response.body.success).to.be.true;
|
||||
});
|
||||
|
||||
expect(response.results[0].address).to.equal('testuser@example.com');
|
||||
expect(response.results[0].main).to.be.false;
|
||||
it('should POST /authenticate with failure using ASP and master scope', async () => {
|
||||
const response = await server
|
||||
.post(`/authenticate`)
|
||||
.send({
|
||||
username: 'testuser@jõgeva.öö',
|
||||
password: asp,
|
||||
scope: 'master'
|
||||
})
|
||||
.expect(403);
|
||||
expect(response.body.error).to.exist;
|
||||
expect(response.body.success).to.not.be.true;
|
||||
});
|
||||
|
||||
expect(response.results[1].address).to.equal('alias1@example.com');
|
||||
expect(response.results[1].main).to.be.true;
|
||||
it('should GET /users/:user/addresses', async () => {
|
||||
const response = await server.get(`/users/${userId}/addresses`).expect(200);
|
||||
expect(response.body.success).to.be.true;
|
||||
expect(response.body.results.length).to.equal(1);
|
||||
expect(response.body.results[0].address).to.equal('testuser@example.com');
|
||||
expect(response.body.results[0].main).to.be.true;
|
||||
});
|
||||
|
||||
expect(response.results[2].address).to.equal('alias2@example.com');
|
||||
expect(response.results[2].main).to.be.false;
|
||||
it('should POST users/:user/addresses', async () => {
|
||||
const response1 = await server
|
||||
.post(`/users/${userId}/addresses`)
|
||||
.send({
|
||||
address: 'alias1@example.com',
|
||||
main: true
|
||||
})
|
||||
.expect(200);
|
||||
expect(response1.body.success).to.be.true;
|
||||
|
||||
frisby
|
||||
.create('DELETE users/{id}/addresses/{address}')
|
||||
.delete(URL + '/users/' + userId + '/addresses/' + response.results[2].id)
|
||||
.expectStatus(200)
|
||||
.afterJSON(response => {
|
||||
expect(response).to.exist;
|
||||
expect(response.success).to.be.true;
|
||||
const response2 = await server
|
||||
.post(`/users/${userId}/addresses`)
|
||||
.send({
|
||||
address: 'alias2@example.com'
|
||||
})
|
||||
.expect(200);
|
||||
expect(response2.body.success).to.be.true;
|
||||
});
|
||||
|
||||
frisby
|
||||
.create('GET users/{id}/addresses – after DELETE')
|
||||
.get(URL + '/users/' + userId + '/addresses')
|
||||
.expectStatus(200)
|
||||
.afterJSON(response => {
|
||||
expect(response).to.exist;
|
||||
expect(response.success).to.be.true;
|
||||
expect(response.results.length).to.equal(2);
|
||||
it('should GET /users/:user (after email update', async () => {
|
||||
const response = await server.get(`/users/${userId}`).expect(200);
|
||||
expect(response.body.success).to.be.true;
|
||||
expect(response.body.id).to.equal(userId);
|
||||
expect(response.body.address).to.equal('alias1@example.com');
|
||||
});
|
||||
|
||||
frisby
|
||||
.create('DELETE users/{id}')
|
||||
.delete(URL + '/users/' + userId)
|
||||
.expectStatus(200)
|
||||
.afterJSON(response => {
|
||||
expect(response).to.exist;
|
||||
expect(response.success).to.be.true;
|
||||
})
|
||||
.toss();
|
||||
})
|
||||
.toss();
|
||||
})
|
||||
.toss();
|
||||
})
|
||||
.toss();
|
||||
it('should GET /users/:user/addresses (updated listing)', async () => {
|
||||
const response = await server.get(`/users/${userId}/addresses`).expect(200);
|
||||
expect(response.body.success).to.be.true;
|
||||
expect(response.body.results.length).to.equal(3);
|
||||
response.body.results.sort((a, b) => a.id.localeCompare(b.id));
|
||||
|
||||
frisby
|
||||
.create('GET users/{id} – updated address')
|
||||
.get(URL + '/users/' + userId)
|
||||
.expectStatus(200)
|
||||
.afterJSON(response => {
|
||||
expect(response).to.exist;
|
||||
expect(response.success).to.be.true;
|
||||
expect(response.id).to.equal(userId);
|
||||
expect(response.address).to.equal('alias1@example.com');
|
||||
})
|
||||
.toss();
|
||||
expect(response.body.results[0].address).to.equal('testuser@example.com');
|
||||
expect(response.body.results[0].main).to.be.false;
|
||||
|
||||
frisby
|
||||
.create('GET users/{id}/mailboxes')
|
||||
.get(URL + '/users/' + userId + '/mailboxes')
|
||||
.expectStatus(200)
|
||||
.afterJSON(response => {
|
||||
expect(response).to.exist;
|
||||
expect(response.success).to.be.true;
|
||||
expect(response.results.length).to.be.gte(4);
|
||||
expect(response.results[0].path).to.equal('INBOX');
|
||||
})
|
||||
.toss();
|
||||
})
|
||||
.toss();
|
||||
expect(response.body.results[1].address).to.equal('alias1@example.com');
|
||||
expect(response.body.results[1].main).to.be.true;
|
||||
|
||||
expect(response.body.results[2].address).to.equal('alias2@example.com');
|
||||
expect(response.body.results[2].main).to.be.false;
|
||||
|
||||
address = response.body.results[2];
|
||||
});
|
||||
|
||||
it('should DELETE users/:user/addresses/:address', async () => {
|
||||
const response = await server.delete(`/users/${userId}/addresses/${address.id}`).expect(200);
|
||||
expect(response.body.success).to.be.true;
|
||||
});
|
||||
|
||||
it('should GET /users/:user/addresses (after DELETE)', async () => {
|
||||
const response = await server.get(`/users/${userId}/addresses`).expect(200);
|
||||
expect(response.body.success).to.be.true;
|
||||
expect(response.body.results.length).to.equal(2);
|
||||
response.body.results.sort((a, b) => a.id.localeCompare(b.id));
|
||||
|
||||
expect(response.body.results[0].address).to.equal('testuser@example.com');
|
||||
expect(response.body.results[0].main).to.be.false;
|
||||
|
||||
expect(response.body.results[1].address).to.equal('alias1@example.com');
|
||||
expect(response.body.results[1].main).to.be.true;
|
||||
});
|
||||
|
||||
it('should GET /users/:user/mailboxes', async () => {
|
||||
const response = await server.get(`/users/${userId}/mailboxes`).expect(200);
|
||||
expect(response.body.success).to.be.true;
|
||||
expect(response.body.results.length).to.gte(4);
|
||||
|
||||
inbox = response.body.results.find(result => result.path === 'INBOX');
|
||||
expect(inbox).to.exist;
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue