fix: `x-www-form-urlencoded` support on bodyParams (#36068)

pull/36077/head
Kevin Aleman 8 months ago committed by GitHub
parent 9be51ef682
commit 5f0b71e98b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      .changeset/odd-beds-dream.md
  2. 3
      apps/meteor/app/api/server/router.ts
  3. 24
      apps/meteor/tests/end-to-end/api/livechat/06-integrations.ts

@ -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

@ -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();
}

@ -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) => {

Loading…
Cancel
Save