diff --git a/.changeset/funny-wolves-tie.md b/.changeset/funny-wolves-tie.md new file mode 100644 index 000000000000..e2364ccb05e5 --- /dev/null +++ b/.changeset/funny-wolves-tie.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': patch +--- + +Fixed issue where bad word filtering was not working in the UI for messages diff --git a/apps/meteor/server/services/messages/service.ts b/apps/meteor/server/services/messages/service.ts index e18a9c276c50..03906bfd0208 100644 --- a/apps/meteor/server/services/messages/service.ts +++ b/apps/meteor/server/services/messages/service.ts @@ -142,8 +142,8 @@ export class MessageService extends ServiceClassInternal implements IMessageServ message = await mentionServer.execute(message); message = await this.cannedResponse.replacePlaceholders({ message, room, user }); - message = await this.markdownParser.parseMarkdown({ message, config: this.getMarkdownConfig() }); message = await this.badWords.filterBadWords({ message }); + message = await this.markdownParser.parseMarkdown({ message, config: this.getMarkdownConfig() }); message = await this.spotify.convertSpotifyLinks({ message }); message = await this.jumpToMessage.createAttachmentForMessageURLs({ message, diff --git a/apps/meteor/tests/e2e/permissions.spec.ts b/apps/meteor/tests/e2e/permissions.spec.ts index 54aaeb3c0ee5..75bf44a159e2 100644 --- a/apps/meteor/tests/e2e/permissions.spec.ts +++ b/apps/meteor/tests/e2e/permissions.spec.ts @@ -186,7 +186,7 @@ test.describe.serial('permissions', () => { }); }); - test.describe.skip('Filter words', () => { + test.describe.serial('Filter words', () => { test.beforeAll(async ({ api }) => { const statusCode1 = (await api.post('/settings/Message_AllowBadWordsFilter', { value: true })).status(); const statusCode2 = (await api.post('/settings/Message_BadWordsFilterList', { value: 'badword' })).status(); diff --git a/apps/meteor/tests/end-to-end/api/chat.ts b/apps/meteor/tests/end-to-end/api/chat.ts index e41a4232d908..82a1a68955ed 100644 --- a/apps/meteor/tests/end-to-end/api/chat.ts +++ b/apps/meteor/tests/end-to-end/api/chat.ts @@ -1,5 +1,6 @@ import type { Credentials } from '@rocket.chat/api-client'; import type { IMessage, IRoom, IThreadMessage, IUser } from '@rocket.chat/core-typings'; +import { Random } from '@rocket.chat/random'; import { expect } from 'chai'; import { after, before, beforeEach, describe, it } from 'mocha'; import type { Response } from 'supertest'; @@ -768,6 +769,40 @@ describe('[Chat]', () => { .end(done); }); + describe('Bad words filter', () => { + before(() => + Promise.all([updateSetting('Message_AllowBadWordsFilter', true), updateSetting('Message_BadWordsFilterList', 'badword,badword2')]), + ); + + after(() => Promise.all([updateSetting('Message_AllowBadWordsFilter', false), updateSetting('Message_BadWordsFilterList', '')])); + + it('should censor bad words on send', async () => { + const badMessage = { + _id: Random.id(), + rid: testChannel._id, + msg: 'This message has badword badword2', + }; + + await request + .post(api('chat.sendMessage')) + .set(credentials) + .send({ message: badMessage }) + .expect(200) + .expect('Content-Type', 'application/json') + .expect((res) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.property('message'); + const { message } = res.body; + expect(message).to.have.property('msg', 'This message has ******* ********'); + expect(message).to.have.property('md').to.be.an('array').that.has.lengthOf(1); + const para = message.md[0]; + expect(para).to.have.property('value').to.be.an('array').that.has.lengthOf(1); + const text = para.value[0]; + expect(text).to.have.property('value', 'This message has ******* ********'); + }); + }); + }); + describe('oembed', () => { let ytEmbedMsgId: IMessage['_id']; let imgUrlMsgId: IMessage['_id']; @@ -1460,6 +1495,38 @@ describe('[Chat]', () => { expect(res.body.message).to.have.property('attachments').that.is.an('array').that.has.lengthOf(0); }); }); + + describe('Bad words filter', () => { + before(() => + Promise.all([updateSetting('Message_AllowBadWordsFilter', true), updateSetting('Message_BadWordsFilterList', 'badword,badword2')]), + ); + + after(() => Promise.all([updateSetting('Message_AllowBadWordsFilter', false), updateSetting('Message_BadWordsFilterList', '')])); + + it('should censor bad words on update', async () => { + await request + .post(api('chat.update')) + .set(credentials) + .send({ + roomId: testChannel._id, + msgId: message._id, + text: 'This message has badword badword2', + }) + .expect(200) + .expect('Content-Type', 'application/json') + .expect((res) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.property('message'); + const { message } = res.body; + expect(message).to.have.property('msg', 'This message has ******* ********'); + expect(message).to.have.property('md').to.be.an('array').that.has.lengthOf(1); + const para = message.md[0]; + expect(para).to.have.property('value').to.be.an('array').that.has.lengthOf(1); + const text = para.value[0]; + expect(text).to.have.property('value', 'This message has ******* ********'); + }); + }); + }); }); describe('[/chat.delete]', () => {