Hi, We are using Wiremock in a docker container to...
# help
t
Hi, We are using Wiremock in a docker container to mock an Auth-System, we have the following stub as a fallback:
Copy code
{
  "priority": 1000000,
  "request": {
    "method": "POST",
    "url": "/authServiceMock",
    "bodyPatterns": [
      {
        "equalToJson": {
          "Benutzer": "${json-unit.any-string}"
        }
      }
    ]
  },
  "response": {
    "status": 200,
    "headers": {
      "Content-Type": "application/json"
    },
    "jsonBody": {
      "permissions": [
        "Start",
      ],
      "Benutzer": "{{{ jsonPath request.body '$.Benutzer' }}}"
    }
  }
}
This works fine, but when i send a username with a backslash (like
domain\\user1
) to the endpoint i get this error from wiremock:
Copy code
HTTP ERROR 500 wiremock.com.fasterxml.jackson.databind.JsonMappingException: { "errors" : [ { "code" : 10, "source" : { }, "title" : "Error parsing JSON", "detail" : "Unexpected character ('s' (code 115)): expected a hex-digit for character escape sequence\n at [Source: (String)\"{\"permissions\":[\"Start\"],\"Benutzer\":\"domain\\user1\",\"Anwendung\":17}\"; line: 1, column: 46]" } ] } (through reference chain: com.github.tomakehurst.wiremock.http.ResponseDefinition["jsonBody"])
I tried escaping the
Benutzer
part but had no luck. Is there any way to solve this problem? The wierd thing is that if I request with the Benutzer
domain\\\\user1
I dont get an error and in the response the String is set to
domain\\user1
r
i think that's because the result of the jsonPath expression contains an unescaped unicode character because it's just plaintext, rather than a json escaped string so it's creating invalid json than the jsonBody field is complaining about
you could try
{{ toJson (jsonPath request.body '$.Benutzer') }}
but i think that will create double quotes on the string value
if that doesnt work, try
{{ cut (toJson (jsonPath request.body '$.Benutzer')) '"' }}
to cut the inner quotes out
t
{{ regexExtract request.body '\"Benutzer\":\"([^\"]+)\"' 'parts' }}{{ parts.0 }}
solved the issue for now
👍 1
do I need to install some dependencies or why am i getting
could not find helper: 'toJson'
r
ah apologies, that helper is not in the core oss