diff --git a/.changeset/odd-beds-dream.md b/.changeset/odd-beds-dream.md new file mode 100644 index 0000000000000..547d7daf52435 --- /dev/null +++ b/.changeset/odd-beds-dream.md @@ -0,0 +1,5 @@ +--- +"@rocket.chat/meteor": patch +--- + +Fixes an issue that caused Hono to not process payloads with content type `x-www-form-urlencoded` correctly diff --git a/apps/meteor/app/api/server/router.ts b/apps/meteor/app/api/server/router.ts index c37100c18b223..3cb0735ba99f3 100644 --- a/apps/meteor/app/api/server/router.ts +++ b/apps/meteor/app/api/server/router.ts @@ -144,6 +144,9 @@ export class Router< parsedBody = await request.raw.clone().json(); } else if (contentType?.includes('multipart/form-data')) { parsedBody = await request.raw.clone().formData(); + } else if (contentType?.includes('application/x-www-form-urlencoded')) { + const req = await request.raw.clone().formData(); + parsedBody = Object.fromEntries(req.entries()); } else { parsedBody = await request.raw.clone().text(); } diff --git a/apps/meteor/tests/end-to-end/api/livechat/06-integrations.ts b/apps/meteor/tests/end-to-end/api/livechat/06-integrations.ts index de4ca08b045a7..bcdee0666dcfa 100644 --- a/apps/meteor/tests/end-to-end/api/livechat/06-integrations.ts +++ b/apps/meteor/tests/end-to-end/api/livechat/06-integrations.ts @@ -63,16 +63,14 @@ describe('LIVECHAT - Integrations', () => { return Promise.all(visitorTokens.map((token) => deleteVisitor(token))); }); + // Twilio sends the body as a x-www-form-urlencoded, the tests should do the same describe('POST livechat/sms-incoming/:service', () => { it('should throw an error if SMS is disabled', async () => { await updateSetting('SMS_Enabled', false); await request .post(api('livechat/sms-incoming/twilio')) .set(credentials) - .send({ - from: '+123456789', - body: 'Hello', - }) + .send('from=%2B123456789&body=Hello') .expect('Content-Type', 'application/json') .expect(400); }); @@ -82,11 +80,7 @@ describe('LIVECHAT - Integrations', () => { await request .post(api('livechat/sms-incoming/twilio')) .set(credentials) - .send({ - From: '+123456789', - To: '+123456789', - Body: 'Hello', - }) + .send('From=%2B123456789&To=%2B123456789&Body=Hello') .expect('Content-Type', 'application/json') .expect(400); }); @@ -97,11 +91,7 @@ describe('LIVECHAT - Integrations', () => { await request .post(api('livechat/sms-incoming/twilio')) .set(credentials) - .send({ - From: '+123456789', - To: '+123456789', - Body: 'Hello', - }) + .send('From=%2B123456789&To=%2B123456789&Body=Hello') .expect('Content-Type', 'application/json') .expect(400); }); @@ -113,11 +103,7 @@ describe('LIVECHAT - Integrations', () => { await request .post(api('livechat/sms-incoming/twilio')) .set(credentials) - .send({ - From: '+123456789', - To: '+123456789', - Body: 'Hello', - }) + .send('From=%2B123456789&To=%2B123456789&Body=Hello') .expect('Content-Type', 'text/xml') .expect(200) .expect((res: Response) => {