bbyars / mountebank

Over the wire test doubles

Home Page:http://www.mbtest.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

defaultResponse not being returned in imposter json

mmillsAtREPAY opened this issue · comments

Expected behaviour

When I POST this to mountebank:

Expected Request
{
    "port": 4545,
    "protocol": "http",
    "defaultResponse": {
        "statusCode": 400,
        "body": "No way!",
        "headers": {}
    }
}

I expect to receive a response equivalent to this:

Expected Response
{
    "protocol": "http",
    "port": 4545,
    "numberOfRequests": 0,
    "recordRequests": false,
    "defaultResponse": {
        "statusCode": 400,
        "body": "No way!",
        "headers": {}
    },
    "requests": [],
    "stubs": [],
    "_links": {
        "self": {
            "href": "http://localhost:2525/imposters/4545"
        },
        "stubs": {
            "href": "http://localhost:2525/imposters/4545/stubs"
        }
    }
}

Actual behaviour

When I perform any operation that returns an existing (or newly created) imposter that has a defaultResponse object set, the defaultResponse object is not included in the return value. I've verified the behavior from POST /imposters, GET /imposters, GET /imposters/4545, and DELETE /imposters/4545.

Actual Request
{
    "port": 4545,
    "protocol": "http",
    "defaultResponse": {
        "statusCode": 400,
        "body": "No way!",
        "headers": {}
    }
}
Actual Response
{
    "protocol": "http",
    "port": 4545,
    "numberOfRequests": 0,
    "recordRequests": false,
    "requests": [],
    "stubs": [],
    "_links": {
        "self": {
            "href": "http://localhost:2525/imposters/4545"
        },
        "stubs": {
            "href": "http://localhost:2525/imposters/4545/stubs"
        }
    }
}

Steps to reproduce

POST the request above to a running mountebank instance and inspect the response

Software versions used

OS         : Windows 10
mountebank : 2.4.0
node.js    : 15.10.0
Installation method : npm

Log contents in mb.log when running mb --loglevel debug

mb --loglevel debug
info: [mb:2525] mountebank v2.4.0 now taking orders - point your browser to http://localhost:2525/ for help
debug: [mb:2525] config: {"options":{"port":2525,"noParse":false,"formatter":"mountebank-formatters","pidfile":"mb.pid","log":{"level":"debug","transports":{"console":{"colorize":true,"format":"%level: %message"},"file":{"path":"mb.log","format":"json"}}},"allowInjection":false,"localOnly":false,"ipWhitelist":["*"],"mock":false,"debug":false,"heroku":false,"protofile":"protocols.json","origin":false},"process":{"nodeVersion":"v15.10.0","architecture":"x64","platform":"win32"}}
info: [mb:2525] POST /imposters/
debug: [mb:2525] ::1:56222 => {"port":4545,"protocol":"http","defaultResponse":{"statusCode":400,"body":"No way!","headers":{}}}
info: [http:4545] Open for business...
debug: [http:4545] ::1:56224 ESTABLISHED
debug: [http:4545] ::1:56225 ESTABLISHED
debug: [http:4545] ::1:56224 LAST-ACK
debug: [http:4545] ::1:56224 CLOSED
info: [http:4545] ::1:56225 => GET /
debug: [http:4545] ::1:56225 => {"requestFrom":"::1:56225","method":"GET","path":"/","query":{},"headers":{"User-Agent":"PostmanRuntime/7.28.4","Accept":"*/*","Postman-Token":"d81a4925-0b84-44ce-b7ac-2720a08d6b70","Host":"localhost:4545","Accept-Encoding":"gzip, deflate, br","Connection":"keep-alive"},"body":"","ip":"::1"}
info: [http:4545] no predicate match, using default response
debug: [http:4545] generating response from {"is":{}}
debug: [http:4545] ::1:56225 <= {"statusCode":400,"headers":{"Connection":"close"},"body":"No way!","_mode":"text"}
debug: [http:4545] ::1:56225 CLOSED

Thanks!