lionheart
lionheart

Reputation: 437

Redirect url from x-www-form-urlencoded request doesn't work out of the box

row body is printed in Postman as TradeSha=https%3A%2F%2Fenv.example.com%2Fpayments%2FRedirectHandler%2F1002%3FtId%3D100201195%26token%3D9c8dce5b-ddbb-4190-9cbe-3da45fad50d2

Location header is printed as https://env.example.com/payments/PSPRedirectHandler/1002?tId=unknown-token&token=unknown-token

For this request: POST /mpggateway HTTP/1.1 Host: core-mocks-qa.bglobale.com Content-Type: application/x-www-form-urlencoded Content-Length: 154

TradeSha=https%3A%2F%2Fenv.example.com%2Fpayments%2FRedirectHandler%2F1002%3FtId%3D100201195%26token%3D9c8dce5b-ddbb-4190-9cbe-3da45fad50d2

And this mapping in WireMock:

        {
        "request": {
          "urlPattern": "/mpggateway",
          "method": "POST",
          "headers": {
            "Content-Type": {
              "matches": "application/x-www-form-urlencoded.*"
            }
          }
        },
        "response": {
          "status": 302,
          "headers": {
            "Location": "https://env.example.com/payments/RedirectHandler/1002?tId={{regexExtract request.body 'tId%3D([a-f0-9\\-]+)' 1 default='unknown-token'}}&token={{regexExtract request.body 'token%3D([a-f0-9\\-]+)' 1 default='unknown-token'}}"
          },
          "body": "Raw Body: {{request.body}}",
          "delayDistribution": {
            "type": "uniform",
            "lower": 500,
            "upper": 750
          }
        },
        "metadata": {
          "description": "cool"
        }
      }

I've tried using different regex and also formData helper.

Upvotes: 0

Views: 37

Answers (1)

lionheart
lionheart

Reputation: 437

The "1" in the handlebars should refer to a variable that should be used afterwards. For example - {{regexExtract request.body 'token%3D([a-f0-9\\-]+)' 1 default='unknown-token'}} should be {{regexExtract request.body 'token%3D([a-f0-9\\-]+)' 'parts' default='unknown-token'}}{{parts.1}}

Now it works

Upvotes: 0

Related Questions