Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalizes request body and URL by parsing params to a list and sorting #211

Merged
merged 2 commits into from Aug 27, 2023

Conversation

patrickberkeley
Copy link
Contributor

@patrickberkeley patrickberkeley commented Aug 23, 2023

Before these changes, if the request body or URL contained a list of params that were in a different order than the params in the cassette, the request would fail to match the cassette.

As of OTP 26, map key order is not guaranteed, so request bodies and URL params that are created using maps can fail to match since the order of their keys is not idempotent.

These changes convert the request body and URL params to a sorted list before comparing it to the request body and URL in the cassette. This ensures cassettes will be matched as long as their request bodies and URL params contain the same set of key-value pairs as the incoming request.

Before this change, if the request body was a list of params that were
in a different order than the params in the cassette, the request body
match would fail.

As of OTP 26, map key order is not guaranteed, so request bodies that
are created using maps can fail to match since the order of their keys
is not idempotent.

These changes convert the request body to a list of params and sort it
before comparing it to the request body in the cassette. This ensures
cassettes will be matched as long as their request bodies contain the
same set of key-value pairs as the incoming request body.
@patrickberkeley patrickberkeley changed the title Normalizes request body by parsing as params, then converting to a list Normalizes request body and URL by parsing params to a list and sorting Aug 24, 2023
Before this change, if the url query params were in a different order
than the url params in the cassette, the request body match would fail.

As of OTP 26, map key order is not guaranteed, so url params that are
created using maps can fail to match since the order of their keys is
not idempotent.

These changes convert the url params to a list and sort it before
comparing it to the url in the cassette. This ensures cassettes will be
matched as long as their url params contain the same set of key-value
pairs as the incoming url params (and the rest of the url matches too).
@coveralls
Copy link

Coverage Status

coverage: 92.419% (+0.2%) from 92.248% when pulling a1d9dbc on seated:pjb/normalize-response-body into 406af2d on parroty:master.

@coveralls
Copy link

Coverage Status

coverage: 92.581% (+0.3%) from 92.248% when pulling a1d9dbc on seated:pjb/normalize-response-body into 406af2d on parroty:master.

@parroty parroty merged commit d1c1765 into parroty:master Aug 27, 2023
8 checks passed
@parroty
Copy link
Owner

parroty commented Aug 27, 2023

Thank you!

@patrickberkeley patrickberkeley deleted the pjb/normalize-response-body branch August 27, 2023 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants