0

I'm using Wiremock server to mock responses and using JSON format to mock responses.

{
  "request":
  {
    "url": "/token",
    "method": "POST",
    "bodyPatterns" : [{
      "contains": "username=test_user@gmail.com&password=passwordtest_security_token"
    }]
  },
  "response":
  {
    "status": 200,
    "headers":
    {
      "Content-Type" : "application/json"
    },
    "jsonBody": {"message": "ok"}
}

This is not working as the '@' in the email is not encoded. I need to pass "test_user%40gmail" for the request to work.

Here the change is only at one place. But for other mocks, request bodies have many special characters**(@,%*\n\s)**. Is there any way to handle the encoding part in the Wiremock.

Also, is there way to encode the string in url?

user10179187
  • 99
  • 1
  • 1
  • 6

1 Answers1

0

In the above example there is an accolade missing which prevents is from loading in WireMock. The below example is complete:

{
    "request": {
        "url": "/token",
        "method": "POST",
        "bodyPatterns": [{
                "contains": "username=test_user@gmail.com&password=passwordtest_security_token"
            }
        ]
    },
    "response": {
        "status": 200,
        "headers": {
            "Content-Type": "application/json"
        },
        "jsonBody": {
            "message": "ok"
        }
    }
}

In your question you highlighted that you need to use %40 instead of @. I have been unable to replicate this scenario. As I'm unsure if you're posting through a form, or raw string.

In the case that you use a regular Form Data option this results in failure to match.

enter image description here

But sending it as a raw body the result is quite the opposite. The example behaves exactly as you would described it should. Below is a screenshot of my Postman result:

enter image description here

A. Kootstra
  • 6,827
  • 3
  • 20
  • 43