-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request from GHSA-v2v2-hph8-q5xp
* Fix for content-type confusion Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * fix: suggestion * fix: lint --------- Signed-off-by: Matteo Collina <hello@matteocollina.com> Co-authored-by: Manuel Spigolon <manuel.spigolon@nearform.com>
- Loading branch information
Showing
3 changed files
with
56 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict' | ||
|
||
const t = require('tap') | ||
const fastify = require('fastify') | ||
const get = require('simple-get').concat | ||
const From = require('..') | ||
|
||
const upstream = fastify() | ||
t.teardown(upstream.close.bind(upstream)) | ||
t.plan(4) | ||
|
||
upstream.post('/test', async (request, reply) => { | ||
if (typeof request.body === 'object') { | ||
return 'not ok' | ||
} | ||
return 'ok' | ||
}) | ||
|
||
upstream.listen({ port: 0 }, function (err) { | ||
t.error(err) | ||
|
||
const app = fastify() | ||
app.register(From) | ||
t.teardown(app.close.bind(app)) | ||
|
||
app.post('/test', (request, reply) => { | ||
if (request.body.method === 'invalid_method') { | ||
return reply.code(400).send({ message: 'payload contains invalid method' }) | ||
} | ||
reply.from(`http://127.0.0.1:${upstream.server.address().port}/test`) | ||
}) | ||
|
||
app.listen({ port: 0 }, function (err) { | ||
t.error(err) | ||
|
||
get({ | ||
url: `http://127.0.0.1:${app.server.address().port}/test`, | ||
headers: { 'content-type': 'application/json ; charset=utf-8' }, | ||
// eslint-disable-next-line no-useless-escape | ||
body: '"{\\\"method\\\":\\\"invalid_method\\\"}"', | ||
method: 'POST' | ||
}, (err, res, data) => { | ||
t.error(err) | ||
t.equal(data.toString(), 'ok') | ||
}) | ||
}) | ||
}) |