-
Notifications
You must be signed in to change notification settings - Fork 23
fix: issue where application/x-www-form-urlencoded payloads weren't being handled properly #807
Conversation
I added two test cases: one for json and one for formData. The json one passes fine! This code in oas-to-har is working as expected: https://github.com/readmeio/api-explorer/blob/59a5d060997321936ae356f2ba3f36e34c81c520/packages/oas-to-har/src/index.js#L198 I narrowed down the issue to here: https://github.com/Kong/httpsnippet/blob/633b825364ab050f02556cfa837148a1e136fd69/src/index.js#L126-L128 httpsnippet is setting it from the value we set back to "" I'm not sure if this is something that's changed recently in the way we're generating hars? This part of httpsnippet hasn't been updated in 5 years. Gunna defer to Jon for this.
What's the issue? I made some changes to HAR generation in the SDK work to pass Content-Type headers through so JSON objects are dumped in a snippets as objects, not stringified. |
Tests will pass when readmeio/fetch-har#67 is pulled into a new |
@@ -1,4 +1,4 @@ | |||
const querystring = require('querystring'); | |||
const validate = require('har-validator'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, most of the changes to this file were to rewrite some tests into using it.each
to make them easier to maintain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code lgtm! Any idea what caused the regression?
test('should output a har format', () => { | ||
expect(oasToHar(oas)).toStrictEqual({ | ||
expect.extend({ | ||
toBeAValidHAR(har) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm tempted to rip this out into its own package.
it('should use example if no value', () => { | ||
expect( | ||
oasToHar(oas, { | ||
it.each([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
@@ -1157,7 +1048,7 @@ describe('requestBody', () => { | |||
}, | |||
}, | |||
}).log.entries[0].request.postData.text | |||
).toBe(querystring.stringify({ a: 'value' })); | |||
).toBe(JSON.stringify({ a: 'value' })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct? How come it's change from querystring to JSON?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We were only ever using the querystring
module for compiling postData.text
for formData, but since aren't using that for that anymore we no longer need to pull that module in. Since the other cases within the library that are compiling postData.text
use JSON.stringify()
I moved this instance over as well.
That said, this test is still not quite right because it's looking for postData.text
for a formData case, but since the test is skipped right now I'm not going to worry about it right now.
@domharrington Yeah it seems like it was a result of me adding setting |
…eing handled properly (#807) * test: added failing test case for formData issue I added two test cases: one for json and one for formData. The json one passes fine! This code in oas-to-har is working as expected: https://github.com/readmeio/api-explorer/blob/59a5d060997321936ae356f2ba3f36e34c81c520/packages/oas-to-har/src/index.js#L198 I narrowed down the issue to here: https://github.com/Kong/httpsnippet/blob/633b825364ab050f02556cfa837148a1e136fd69/src/index.js#L126-L128 httpsnippet is setting it from the value we set back to "" I'm not sure if this is something that's changed recently in the way we're generating hars? This part of httpsnippet hasn't been updated in 5 years. Gunna defer to Jon for this. * fix: correctly preparing `x-www-form-urlencoded` forms as params * fix: oas-to-har will now output valid HAR definitions * chore(deps): upgrading fetch-har to 3.0.0 * docs: adding an example for our handling of formData Co-authored-by: Jon Ursenbach <jon@ursenba.ch>
* fix: issue where application/x-www-form-urlencoded payloads weren't being handled properly (#807) * test: added failing test case for formData issue I added two test cases: one for json and one for formData. The json one passes fine! This code in oas-to-har is working as expected: https://github.com/readmeio/api-explorer/blob/59a5d060997321936ae356f2ba3f36e34c81c520/packages/oas-to-har/src/index.js#L198 I narrowed down the issue to here: https://github.com/Kong/httpsnippet/blob/633b825364ab050f02556cfa837148a1e136fd69/src/index.js#L126-L128 httpsnippet is setting it from the value we set back to "" I'm not sure if this is something that's changed recently in the way we're generating hars? This part of httpsnippet hasn't been updated in 5 years. Gunna defer to Jon for this. * fix: correctly preparing `x-www-form-urlencoded` forms as params * fix: oas-to-har will now output valid HAR definitions * chore(deps): upgrading fetch-har to 3.0.0 * docs: adding an example for our handling of formData Co-authored-by: Jon Ursenbach <jon@ursenba.ch> * build: updating dist files * v6.12.1 Co-authored-by: domharrington <domharrington@users.noreply.github.com>
🧰 What's being changed?
This resolves a couple bugs with how we're generating HAR definitions:
application/x-www-form-urlencoded
operations, we were storing their payloads inside ofpostData.text
instead ofpostData.params
.postData.params
. See fix: improper handling of application/x-www-form-urlencoded fetch-har#67 for details.postData
regardless if there was actually any data for it. For simple GET requests that just havequeryString
populated, thepostData
object is no longer part of the created HAR.postData
no longer being an expectation. See fix: improper handling of application/x-www-form-urlencoded fetch-har#67 for details.oas-to-har
was creating didn't actually validate outside of httpsnippet. This was because that library adds some defaults (likehttpVersion
) if they're missing. Sinceoas-to-har
should support the HAR spec and not HTTP Snippets handling of it, I've made the decision to:🧪 Testing
You can see this broken in action here: http://bin.readme.com/s/5efbb6ac35bcd40024d60488
Load up the local server and the
formData
example to see how it's handled how: http://localhost:9966/?selected=swagger-files%2Fformdata.json🗳 Checklist
I added two test cases: one for json and one for formData. The json
one passes fine! This code in oas-to-har is working as expected:
api-explorer/packages/oas-to-har/src/index.js
Line 198 in 59a5d06
I narrowed down the issue to here:
https://github.com/Kong/httpsnippet/blob/633b825364ab050f02556cfa837148a1e136fd69/src/index.js#L126-L128
httpsnippet is setting it from the value we set back to ""
I'm not sure if this is something that's changed recently in the way
we're generating hars? This part of httpsnippet hasn't been updated
in 5 years. Gunna defer to Jon for this.