Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config file does not allow nested stringify functions #183

Closed
bbyars opened this issue Jan 1, 2017 · 10 comments
Closed

Config file does not allow nested stringify functions #183

bbyars opened this issue Jan 1, 2017 · 10 comments
Projects
Milestone

Comments

@bbyars
Copy link
Owner

bbyars commented Jan 1, 2017

See https://groups.google.com/forum/#!topic/mountebank-discuss/6ShnSHx-GAc

and

https://gist.github.com/zot24/3cf6df65c8ae3e63c2deabc4ed7174b9

@bbyars bbyars added this to the v1.8.0 milestone Jan 1, 2017
bbyars added a commit that referenced this issue Jan 1, 2017
@bbyars
Copy link
Owner Author

bbyars commented Jan 1, 2017

Fixed in 0e02d68

@bbyars bbyars closed this as completed Jan 1, 2017
@rohgoyal
Copy link

rohgoyal commented Sep 21, 2017

hey Brandon, I am still facing this issue. Nested stringily failing for me with error something like this

{
	"errors": [{
		"code": "invalid injection",
		"message": "invalid response injection",
		"source": "(function (request, state, logger) {\n    logger.info('apiStub.ejs Called');\n    var apiKey = request.method + '-' + request.path;\n    logger.info(apiKey);\n    return {\n      headers: {\n        'Content-Type': 'application/json'\n      },\n      body: JSON.stringify({ count: 10 }\\n)\n    };\n}\n)(scope, injectState, logger, deferred.resolve, imposterState);",
		"data": "Invalid or unexpected token",
		"name": "Error",
		"stack": "Error\n    at Object.from (/usr/local/lib/node_modules/mountebank/src/util/inherit.js:15:17)\n    at createError (/usr/local/lib/node_modules/mountebank/src/util/errors.js:10:26)\n    at Object.InjectionError (/usr/local/lib/node_modules/mountebank/src/util/errors.js:25:16)\n    at inject (/usr/local/lib/node_modules/mountebank/src/models/responseResolver.js:43:44)\n    at processResponse (/usr/local/lib/node_modules/mountebank/src/models/responseResolver.js:237:20)\n    at Object.resolve (/usr/local/lib/node_modules/mountebank/src/models/responseResolver.js:271:16)\n    at Object.resolve (/usr/local/lib/node_modules/mountebank/src/models/stubRepository.js:124:18)\n    at F.respond (/usr/local/lib/node_modules/mountebank/src/models/http/baseHttpServer.js:78:34)\n    at /usr/local/lib/node_modules/mountebank/src/models/abstractServer.js:96:35\n    at _fulfilled (/usr/local/lib/node_modules/mountebank/node_modules/q/q.js:854:54)"
	}]
}

@rohgoyal
Copy link

rohgoyal commented Sep 21, 2017

Btw, this is how you can recreate the problem
$mb --configfile templates/originServer.ejs --allowInjection

templates/originServer.ejs

{
  "port": 5555,
  "protocol": "http",
  "name": "origin",
  "stubs": [
    {
      "responses": [{ "inject": "<%- stringify(filename, 'apiStub.ejs') %>" }]
    }
  ]
}

templates/apiStub.ejs

function (request, state, logger) {
    logger.info('apiStub.ejs Called');
    var apiKey = request.method + '-' + request.path;
    logger.info(apiKey);
    return {
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(<%- stringify(filename, 'GET-request.ejs') %>)
    };
}

templates/GET-request.ejs
{ count: 10 }

@bbyars
Copy link
Owner Author

bbyars commented Sep 23, 2017 via email

@rohgoyal
Copy link

Hi Brendan, I get this error when I call the port 5555, instead startup.
Here is what I am running on my laptop
~ $mb --version
1.12.0

@bbyars
Copy link
Owner Author

bbyars commented Sep 26, 2017 via email

@leogtzr
Copy link
Contributor

leogtzr commented Jun 3, 2018

Hi Brendan, has this been fixed? I am facing the same issue, I am able to replicate the issue with @rohgoyal imposter and ejs file.

I am using 1.14.1

Thanks!

@bbyars
Copy link
Owner Author

bbyars commented Jun 4, 2018

Hi @leogtzr. Interesting...I can't reproduce it. I thought I fixed it in v1.13.0 (see #293 and the corresponding commit). A local test using @rohgoyal 's files works for me, returning a body of "{"count":10}" when calling the imposter on port 5555, and logging the "apiStub.ejs Called".

What O/S are you using?

@leogtzr
Copy link
Contributor

leogtzr commented Jun 8, 2018 via email

@bbyars
Copy link
Owner Author

bbyars commented Jun 13, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

3 participants