version=1.0.0.RELEASE
The stubs generated using the REST Docs integration do not validate request parameters
example test:
@Test
public void clientCredentials() throws Exception {
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post("/oauth/token")
.with(httpBasic("id", "secret"))
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.param("grant_type", "client_credentials");
mockMvc.perform(request)
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(document("oauth/client_credentials",
preprocessResponse(prettyPrint()),
requestHeaders(headerWithName("Authorization").description("Basic auth credentials, where the client id is the user name and the client secret is the password")),
requestParameters(parameterWithName("grant_type").description("client_credentials grant type")),
responseFields(
fieldWithPath("access_token").description("The access token which has been issued by IDM"),
fieldWithPath("token_type").description("This is a bearer token which should be passed in the request header"),
fieldWithPath("expires_in").description("Seconds until expiration"),
fieldWithPath("scope").description("The scope that the token is authorized for")
)
));
}
generated stub:
{
"request" : {
"url" : "/oauth/token",
"method" : "POST",
"headers" : {
"Content-Type" : {
"equalTo" : "application/x-www-form-urlencoded"
},
"Authorization" : {
"equalTo" : "Basic NTEzOTk1MGEtZWNjOC00MGUzLWFhMzEtY2Y3OWZlMWJiNzJhOnNlY3JldA=="
}
},
"bodyPatterns" : [ {
"equalTo" : ""
} ]
},
"response" : {
"status" : 200,
"body" : "{\n \"access_token\" : \"06a0399e-3ebe-49c4-ba93-314dd6f827e9\",\n \"token_type\" : \"bearer\",\n \"expires_in\" : 599999,\n \"scope\" : \"Authentication\"\n}",
"headers" : {
"Cache-Control" : "no-store",
"Pragma" : "no-cache",
"Content-Type" : "application/json;charset=UTF-8",
"X-Content-Type-Options" : "nosniff",
"X-XSS-Protection" : "1; mode=block",
"X-Frame-Options" : "DENY"
}
}
}
the grant_type parameter is never mentioned in the stub.
@cah-andrewfitzgerald care for a PR? ;)
@marcingrzejszczak Did a little bit of investigation, it doesn't look like this is supported by WireMock at the moment. There is an open issue (tomakehurst/wiremock#383) to support request parameters (instead of just query parameters).
Ah, so we have to wait then... Fair enough!
Tried also using WireMock API, same result, the query parameters are being ignored and this leads to contract tests failing.
The issue is still open in WireMock. I'll move this to icebox.
Is there any workaround for this issue?
Not that I know of
Most helpful comment
The issue is still open in WireMock. I'll move this to icebox.