wiremock: Verify request with duplicate query params
I’m really enjoying using wiremock (2.0.10-beta) and have hit a problem trying to verify a call with duplicate query parameters:
/authz/access/12345?operations=op1&operations=op2
My naive attempt didn’t work:
wiremock.verify(getRequestedFor(urlPathEqualTo("/authz/access/12345"))
.withQueryParam("operations", equalTo("op1"))
.withQueryParam("operations", equalTo("op2"))
.withHeader("Authorization", equalTo("Bearer goodtoken")));
The wiremock logs show that the second withQueryParam
is overwriting the first one.
com.github.tomakehurst.wiremock.client.VerificationException: Expected at least one request matching: {
"urlPath" : "/authz/access/12345",
"method" : "GET",
"headers" : {
"Authorization" : {
"equalTo" : "Bearer goodtoken"
}
},
"queryParameters" : {
"operations" : {
"equalTo" : "op2"
}
}
}
Is this a type of verification that Wiremock would consider supporting?
In the meantime, I’m just using the following workaround (and hoping for consistent ordering):
wiremock.verify(getRequestedFor(urlEqualTo("/authz/access/12345?operations=op1&operations=op2"))
.withHeader("Authorization", equalTo("Bearer goodtoken")));
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 23
- Comments: 32 (9 by maintainers)
We’ve just come up against this again and ended up back on this issue! Any progress yet? 😄
+1 having the same issue
Here’s one way you can do this with hamcrest matchers to verify (
contains
) or ignore (containsInAnyOrder
) the order of the duplicated parameters.RID_STRINGS
is just a list of strings representing the expected parameter values.Any update? 😦
Here’s my suggested design for this:
JSON will look something like:
No update?😦
Sorry, still not managed to get this over the line 😞
BTW, you can now combine custom and standard matchers so you could work around this by writing a custom matcher just for the query part.
@tomakehurst cool, got it then probably we can go via way you suggested. You can assign this issue to me.
The intention is that the parameters are varargs in all cases, I just chose 3 as an example.
contains
,equalTo
etc. are the existing matchers and these new ones will make use of them.Ordering should not matter so the first example would match a query like
?id=1&id=2&id=3
and?id=2&id=3&id=1
.In kotlin, an extension function like this got me the desired behaviour (variation of @forrestrice answer):
usage is similar to existing functions:
matchingAll
can be confusing, my initial expectation for:was that one
X-My-Header
has to match all the patterns.How about adding a new method:
matchingInAnyOrder
will match any valid permutation of the matchers whilematchingExactly
will need the matchers to match in the exact order they appear.I’m working on it. Keeping the API backwards compatible is proving a bit tricky.
Here’s a test case showing what I’m aiming at: https://github.com/tomakehurst/wiremock/blob/multi-value-aggregate-matching/src/test/java/com/github/tomakehurst/wiremock/MultiValuedParameterAcceptanceTest.java
I am also having this problem. It is a really a useful feature. Was it implemented in a branch or something? If not, I’d love to work on this.
Thanks! Just to confirm, I wanted to verify that both operations=op1 AND operations=op2 query params appear in one http call.