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

ParamMatcher failed when using parameter with comma #849

Closed
geovanegodoi opened this issue Nov 23, 2022 · 16 comments
Closed

ParamMatcher failed when using parameter with comma #849

geovanegodoi opened this issue Nov 23, 2022 · 16 comments
Assignees
Labels

Comments

@geovanegodoi
Copy link

geovanegodoi commented Nov 23, 2022

Describe the bug

I'm working on a system that consumes a 3rd party API which accepts as querystring a SQL statement.
For example, to query some data from any table just build the URI like this:

  • http://host/api/queryservice?query=SELECT id FROM table WHERE id = 1
    While trying to mock this API, I realized that whenever I tried to mock a statement using comma, the ParamMatcher fails.
    For example, SELECT id, value FROM table WHERE id = 1.
    And I received a 404 (NotFound) error code.

Expected behavior:

I expected the ParamMatcher has succeded, and returned 200 (OK).

Test to reproduce

1 - Create an API which receives as querystring a SQL statement
2 - Mock that API using "WithParam" function
3 - Test creating a statement which has a 'comma' within, "SELECT id, value FROM table WHERE id = 1"

Other related info

Provide additional information if any.

@StefH StefH added question and removed bug labels Nov 24, 2022
@StefH StefH self-assigned this Nov 24, 2022
@StefH
Copy link
Collaborator

StefH commented Nov 24, 2022

What you can try:

1️⃣
url-escape the comma

2️⃣
Set https://github.com/WireMock-Net/WireMock.Net/blob/master/src/WireMock.Net/Settings/WireMockServerSettings.cs#L267 to QueryParameterMultipleValueSupport.NoComma

@geovanegodoi
Copy link
Author

geovanegodoi commented Nov 24, 2022

Thanks for reply,

I've downloaded the latest nuget version (1.5.10) but there isn't this property.

image

Am I doing something wrong?

@StefH
Copy link
Collaborator

StefH commented Nov 24, 2022

No. Nothing is wrong on your end

I just realized that I need to release a new version which includes this.

I'll do that now.

@geovanegodoi
Copy link
Author

geovanegodoi commented Nov 24, 2022

Thanks, @StefH

I've just downloaded the new release, and now the property is ok.

When you said "url-escape the comma", could you show an example?

I tried somethings, but I still got the error.

@StefH
Copy link
Collaborator

StefH commented Nov 25, 2022

It could be that Url escaping does indeed nor work.

Then you need to use option 2.

Can this issue be closed?

@geovanegodoi
Copy link
Author

geovanegodoi commented Nov 25, 2022

I'm still facing the issue.

The API I'm trying to mock is this one:
https://docs.oracle.com/en/cloud/saas/service/18a/cxsvc/op-services-rest-connect-v1.4-queryresults-get.html

It's a public Oracle REST API, to query entities from database.
When I try to mock this request I get a 404 error.
image

@StefH
Copy link
Collaborator

StefH commented Nov 30, 2022

#854

@StefH
Copy link
Collaborator

StefH commented Nov 30, 2022

@gigiogodoi
Can you please provide a full working c# code example which simulates your issue? Because I cannot reproduce it using unit tests.

@geovanegodoi
Copy link
Author

@StefH
Follow an example repository to reproduce the error, using XUnit and .NET6 .

https://github.com/gigiogodoi/UnitTestWithWiremock

Inside it, there are 2 test cases, one failing because it is using a query with comma.

image

@StefH
Copy link
Collaborator

StefH commented Nov 30, 2022

Thanks a lot for this unit test. I did find the issue and it's fixed in preview version 1.5.11-ci-16748.

@geovanegodoi
Copy link
Author

@StefH
Could you add a testcase to validate a querystring like this ?

query=select id, name, value from table where id in (1, 2, 3, 4, 5)

@StefH
Copy link
Collaborator

StefH commented Nov 30, 2022

@StefH
Copy link
Collaborator

StefH commented Dec 2, 2022

@gigiogodoi Is it ok?

@StefH
Copy link
Collaborator

StefH commented Dec 3, 2022

I'll merge the PR.

@StefH StefH closed this as completed Dec 3, 2022
@geovanegodoi
Copy link
Author

I was not able to download the preview version, because it was not releated in the nuget package manager.

But I will try once you release a new version.

@StefH
Copy link
Collaborator

StefH commented Dec 3, 2022

previews are here: https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions

But I'll release an official version today on nuget.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants