How can I send a request with malformed query parameters or path in the URL using REST Assured?

Viewed 521

I have to test a rest webservice and am using REST Assured and JUnit5 to do so.
Part of the tests cover how the service should respond to requests with wrong data and wrong or invalid formats.

What I'd like to be able to do:

  1. Send a request http://example.com/some/path?thisiswrong=% (not-encoded percent sign as value)
  2. Assert that the webservice responds with an error as expected.

Simplified sample code:

RestAssured.given()
    .urlEncodingEnabled(false)
    .baseUri("http://example.com")
    .basePath("some/path")
    .queryParams("thisiswrong", "%")
    .get();

The execution fails without sending the request due to an IllegalArgumentException which is actually due to an error: java.net.URISyntaxException: Malformed escape pair.
This happens somewhere inside REST Assured before sending the request.

I've tried providing the url using an instance of java.net.URL but in the end it's the same.
Using .get(new URI("http://example.com/some/path?uff=%")) and .get(new URL("http://example.com/some/path?uff=%")) both end with IllegalArgumentException.

I'm not url-encoding the values since sending % or %25 is not the same as can be verified using curl or Postman.

How can I send this request while still using REST Assured?

0 Answers
Related