Regression: Webhooks breaking duo to a too restrict test (#10555)

pull/10561/head^2
Rodrigo Nascimento 8 years ago committed by GitHub
parent 44be02f730
commit 01d2aead1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .eslintrc
  2. 13
      packages/rocketchat-api/server/api.js
  3. 4
      packages/rocketchat-integrations/server/api/api.js
  4. 72
      packages/rocketchat-lib/server/functions/sendMessage.js

@ -76,7 +76,7 @@
"curly": [2, "all"],
"eqeqeq": [2, "allow-null"],
"new-cap": [2, {
"capIsNewExceptions": ["Match.Optional", "Match.Maybe", "Match.OneOf", "Match.ObjectIncluding", "Push.Configure", "SHA256"]
"capIsNewExceptions": ["Match.Optional", "Match.Maybe", "Match.OneOf", "Match.Where", "Match.ObjectIncluding", "Push.Configure", "SHA256"]
}],
"use-isnan": 2,
"valid-typeof": 2,

@ -1,5 +1,6 @@
/* global Restivus, DDP, DDPCommon */
import _ from 'underscore';
const logger = new Logger('API', {});
class API extends Restivus {
constructor(properties) {
@ -68,10 +69,14 @@ class API extends Restivus {
result.success = true;
}
return {
result = {
statusCode: 200,
body: result
};
logger.debug('Success', result);
return result;
}
failure(result, errorType) {
@ -88,10 +93,14 @@ class API extends Restivus {
}
}
return {
result = {
statusCode: 400,
body: result
};
logger.debug('Failure', result);
return result;
}
notFound(msg) {

@ -284,8 +284,8 @@ function executeIntegrationRest() {
}
return RocketChat.API.v1.success(this.scriptResponse);
} catch ({ error }) {
return RocketChat.API.v1.failure(error);
} catch ({ error, message }) {
return RocketChat.API.v1.failure(error || message);
}
}

@ -1,29 +1,49 @@
const objectMaybeIncluding = (types) => {
return Match.Where((value) => {
Object.keys(types).forEach(field => {
if (value[field] != null) {
try {
check(value[field], types[field]);
} catch (error) {
error.path = field;
throw error;
}
}
});
return true;
});
};
const validateAttachmentsFields = attachmentFields => {
check(attachmentFields, objectMaybeIncluding({
short: Boolean
}));
check(attachmentFields, Match.ObjectIncluding({
short: Match.Maybe(Boolean),
title: String,
value: String
}));
};
const validateAttachment = attachment => {
check(attachment, Match.ObjectIncluding({
color: Match.Maybe(String),
text: Match.Maybe(String),
ts: Match.Maybe(String),
thumb_url: Match.Maybe(String),
message_link: Match.Maybe(String),
collapsed: Match.Maybe(Boolean),
author_name: Match.Maybe(String),
author_link: Match.Maybe(String),
author_icon: Match.Maybe(String),
title: Match.Maybe(String),
title_link: Match.Maybe(String),
title_link_download: Match.Maybe(Boolean),
image_url: Match.Maybe(String),
audio_url: Match.Maybe(String),
video_url: Match.Maybe(String),
fields: Match.Maybe(Array)
check(attachment, objectMaybeIncluding({
color: String,
text: String,
ts: String,
thumb_url: String,
message_link: String,
collapsed: Boolean,
author_name: String,
author_link: String,
author_icon: String,
title: String,
title_link: String,
title_link_download: Boolean,
image_url: String,
audio_url: String,
video_url: String,
fields: Array
}));
if (attachment.fields && attachment.fields.length) {
@ -38,14 +58,14 @@ RocketChat.sendMessage = function(user, message, room, upsert = false) {
return false;
}
check(message, Match.ObjectIncluding({
_id: Match.Maybe(String),
msg: Match.Maybe(String),
text: Match.Maybe(String),
alias: Match.Maybe(String),
emoji: Match.Maybe(String),
avatar: Match.Maybe(String),
attachments: Match.Maybe(Array)
check(message, objectMaybeIncluding({
_id: String,
msg: String,
text: String,
alias: String,
emoji: String,
avatar: String,
attachments: Array
}));
if (Array.isArray(message.attachments) && message.attachments.length) {

Loading…
Cancel
Save