mock-server / mockserver

MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby. MockServer also includes a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding).
http://mock-server.com
Apache License 2.0
4.59k stars 1.07k forks source link

HttpRequestMatcher ignores the body content #358

Closed lindycoder closed 7 years ago

lindycoder commented 7 years ago

Hello, i'm sorry if this is a problem of my comprehension but i can't seem to find how to make this work.

Using the JS client i create this expectation:

mockServerClient("localhost", 31589).mockAnyResponse({
    httpRequest: {
      method: 'POST',
      path: '/api/2.0/',
      body : {
        type: "STRING",
        value: "var1=1&var2=1&var3=something"
      }
    },
    httpResponse: {
      statusCode: 200,
      body: JSON.stringify({
        "status": true
      }),
      headers: [
        {"name": "Content-Type", "values": ["application/json"]},
      ]
    },
    times: {
      unlimited: true
    }
  })

which shows in the container's log as

2017-07-17 13:40:03,961 INFO o.m.m.MockServerHandler creating expectation:

    {
      "httpRequest" : {
        "method" : "POST",
        "path" : "/api/2.0/",
        "body" : "var1=1&var2=1&var3=something"
      },
      "times" : {
        "remainingTimes" : 0,
        "unlimited" : true
      },
      "timeToLive" : {
        "unlimited" : true
      },
      "httpResponse" : {
        "statusCode" : 200,
        "headers" : [ {
          "name" : "Content-Type",
          "values" : [ "application/json" ]
        } ],
        "body" : "{\"status\":true}"
      },
      "action" : {
        "statusCode" : 200,
        "headers" : [ {
          "name" : "Content-Type",
          "values" : [ "application/json" ]
        } ],
        "body" : "{\"status\":true}"
      }
    }

And when i perform a request:

2017-07-17 13:40:04,777 INFO o.m.m.HttpRequestMatcher request:

    {
      "method" : "POST",
      "path" : "/api/2.0/",
      "headers" : [ {
        "name" : "Host",
        "values" : [ "hostname" ]
      }, {
        "name" : "Content-Type",
        "values" : [ "application/x-www-form-urlencoded" ]
      }, {
        "name" : "Connection",
        "values" : [ "keep-alive" ]
      } ],
      "keepAlive" : true,
      "secure" : false,
      "body" : {
        "contentType" : "text/plain; charset=utf-8",
        "type" : "STRING",
        "string" : "var1=5000&var2=5000&var3=SOMETHING-ELSE"
      }
    }

 matched expectation:

    {
      "path" : "/api/2.0/"
    }

2017-07-17 13:40:04,778 INFO o.m.m.MockServerHandler returning response:

    {
      "statusCode" : 200,
      "headers" : [ {
        "name" : "Content-Type",
        "values" : [ "application/json" ]
      } ],
      "body" : "{\"status\":true}"
    }

 for request:

    {
      "method" : "POST",
      "path" : "/api/2.0/",
      "headers" : [ {
        "name" : "Host",
        "values" : [ "somehost" ]
      }, {
        "name" : "Content-Type",
        "values" : [ "application/x-www-form-urlencoded" ]
      } ],
      "keepAlive" : true,
      "secure" : false,
      "body" : {
        "contentType" : "text/plain; charset=utf-8",
        "type" : "STRING",
        "string" : "var1=5000&var2=5000&var3=SOMETHING-ELSE"
      }
    }

What you see here is that the PATH is right but the BODY is wrong and the BODY doesn't show up in the "matched expectation" section.

So is this a problem of my expectation creation?

I'm using

Thank you very much

lindycoder commented 7 years ago

It would seem like my teardown hadn't reset properly and there were old expectations in the instance. Sorry!