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

Getting possible mock file paths can result in a collision #1

Closed
marijnz0r opened this issue Aug 29, 2018 · 7 comments · Fixed by #2
Closed

Getting possible mock file paths can result in a collision #1

marijnz0r opened this issue Aug 29, 2018 · 7 comments · Fixed by #2
Labels
bug Something isn't working

Comments

@marijnz0r
Copy link

Endpoint 1:
api/endpoint?foo_bar_fizz=buzz

Endpoint 2:
api/endpoint?foo=bar&fizz=buzz

Getting possible mock file paths for both the endpoints will result in the same mock file:
api/endpoint.foo-bar-fizz-buzz.mock

I think changes need to be made in the getQueryFromRequst method in the ResponseBuilder.

@bbrala
Copy link
Member

bbrala commented Aug 30, 2018

Do you have an proposal on how we should build the paths so we can fix these collisions?

@JaZo
Copy link
Member

JaZo commented Sep 5, 2018

The problem is that an URI is allowed to contain more characters (see http://tools.ietf.org/html/rfc3986#section-2) than a (cross platform) filename. This makes collisions inevitable. However, we can make the collisions less frequent by separating the GET-params using a different character and by separating the key and value using an obscure character that isn't widely used in URIs.

@marijnz0r, @bbrala, do you think something like this would help?

Endpoint 1:
api/endpoint.foo_bar_fizz~buzz.mock

Endpoint 2:
api/endpoint.foo~bar.fizz~buzz.mock

@bbrala
Copy link
Member

bbrala commented Sep 5, 2018

I think that should work, though perhaps making the endpoint a directory for parameters would make things even better.

api/endpoint/foo_bar_fizz~buzz.mock

api/endpoint/foo~bar.fizz~buzz.mock

Without parameters

api/endpoint.mock

This way parameters and endpoints will not interfere with eachother.

@marijnz0r
Copy link
Author

That's a nice solution! I think it's important to explain it in the readme thoroughly, because it will be more difficult for users to create the correct mock files this way.

@JaZo
Copy link
Member

JaZo commented Sep 5, 2018

@bbrala using a directory for URIs with GET-params might help, but can also introduce more collisions.

api/endpoint?foo
api/endpoint/foo.mock

api/endpoint/foo
api/endpoint/foo.mock

@marijnz0r I'm thinking of creating a small JS-helper which converts a given URI to a filepath using the same rules as this client.

@bbrala
Copy link
Member

bbrala commented Sep 5, 2018

Hmm good point...

Technically & is allowed in the filename, perhaps we are overcomplicating it by tring to replace the seperator for the query parameters.

@JaZo
Copy link
Member

JaZo commented Sep 5, 2018

= is also allowed, so it's best if we just leave it at = and & and only replace characters in the key/value! 😄

api/endpoint?foo=bar&fizz=buzz
api/endpoint.foo=bar&fizz=buzz.mock

I'll create a PR for this!

@JaZo JaZo closed this as completed in #2 Sep 5, 2018
@JaZo JaZo added the bug Something isn't working label Aug 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants