Skip to content

Commit

Permalink
fix: validation on bot field used by js.sdk (#34214)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego authored Dec 20, 2024
1 parent de793a8 commit 0fce342
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion apps/meteor/app/lib/server/methods/sendMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Meteor.methods<ServerMethods>({
ts: Match.Maybe(Date),
t: Match.Maybe(String),
otrAck: Match.Maybe(String),
bot: Match.Maybe(Boolean),
bot: Match.Maybe(Object),
content: Match.Maybe(Object),
e2e: Match.Maybe(String),
e2eMentions: Match.Maybe(Object),
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/components/message/MessageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const MessageHeader = ({ message }: MessageHeaderProps): ReactElement => {
</>
)}
</MessageNameContainer>
{shouldShowRolesList && <MessageRoles roles={roles} isBot={message.bot} />}
{shouldShowRolesList && <MessageRoles roles={roles} isBot={!!message.bot} />}
<MessageTimestamp id={`${message._id}-time`} title={formatDateAndTime(message.ts)}>
{formatTime(message.ts)}
</MessageTimestamp>
Expand Down
26 changes: 26 additions & 0 deletions apps/meteor/tests/end-to-end/api/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2082,6 +2082,32 @@ describe('Meteor.methods', () => {
})
.end(done);
});

it('should accept message sent by js.SDK', (done) => {
void request
.post(methodCall('sendMessage'))
.set(credentials)
.send({
message: JSON.stringify({
method: 'sendMessage',
params: [{ rid, msg: 'test message', bot: { i: 'js.SDK' } }],
id: 1000,
msg: 'method',
}),
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);

const data = JSON.parse(res.body.message);

expect(data).to.have.a.property('result').that.is.an('object');
expect(data.result).to.have.a.property('bot').that.is.an('object');
expect(data.result.bot).to.have.a.property('i', 'js.SDK');
})
.end(done);
});
});

describe('[@updateMessage]', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core-typings/src/IMessage/IMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export interface IMessage extends IRocketChatRecord {

private?: boolean;
/* @deprecated */
bot?: boolean;
bot?: Record<string, any>;
sentByEmail?: boolean;
webRtcCallEndTs?: Date;
role?: string;
Expand Down

0 comments on commit 0fce342

Please sign in to comment.