Merge pull request #8667 from mutdmour/feature/8336

[FIX] Able to react with invalid emoji
pull/9045/head^2
Rodrigo Nascimento 8 years ago committed by GitHub
commit c20f3fd5e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      packages/rocketchat-emoji-custom/client/models/EmojiCustom.js
  2. 2
      packages/rocketchat-reactions/client/methods/setReaction.js
  3. 4
      packages/rocketchat-reactions/setReaction.js
  4. 32
      tests/end-to-end/api/05-chat.js

@ -3,6 +3,18 @@ class EmojiCustom extends RocketChat.models._Base {
super();
this._initModel('custom_emoji');
}
//find
findByNameOrAlias(name, options) {
const query = {
$or: [
{name},
{aliases: name}
]
};
return this.find(query, options);
}
}
RocketChat.models.EmojiCustom = new EmojiCustom();

@ -17,6 +17,8 @@ Meteor.methods({
return false;
} else if (message.private) {
return false;
} else if (!RocketChat.emoji.list[reaction] && RocketChat.models.EmojiCustom.findByNameOrAlias(reaction).count() === 0) {
return false;
}
if (message.reactions && message.reactions[reaction] && message.reactions[reaction].usernames.indexOf(user.username) !== -1) {

@ -19,6 +19,10 @@ Meteor.methods({
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'setReaction' });
}
if (!RocketChat.emoji.list[reaction] && RocketChat.models.EmojiCustom.findByNameOrAlias(reaction).count() === 0) {
throw new Meteor.Error('error-not-allowed', 'Invalid emoji provided.', { method: 'setReaction' });
}
const user = Meteor.user();
if (Array.isArray(room.muted) && room.muted.indexOf(user.username) !== -1 && !room.reactWhenReadOnly) {

@ -2,8 +2,8 @@
/* globals expect */
/* eslint no-unused-vars: 0 */
import {getCredentials, api, login, request, credentials, message, log, apiPrivateChannelName } from '../../data/api-data.js';
import {adminEmail, password} from '../../data/user.js';
import { getCredentials, api, login, request, credentials, message, log, apiPrivateChannelName } from '../../data/api-data.js';
import { adminEmail, password } from '../../data/user.js';
import supertest from 'supertest';
describe('[Chat]', function() {
@ -169,18 +169,20 @@ describe('[Chat]', function() {
.end(done);
});
it('/chat.react', (done) => {
request.post(api('chat.react'))
.set(credentials)
.send({
emoji: 'smile',
messageId: message._id
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
})
.end(done);
describe('/chat.react', () => {
it('should return statusCode: 200 when the emoji is valid', (done) => {
request.post(api('chat.react'))
.set(credentials)
.send({
emoji: ':squid:',
messageId: message._id
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
})
.end(done);
});
});
});

Loading…
Cancel
Save