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

Issue with Injection in Predicate #63

Closed
anu0123 opened this issue Apr 10, 2015 · 4 comments
Closed

Issue with Injection in Predicate #63

anu0123 opened this issue Apr 10, 2015 · 4 comments

Comments

@anu0123
Copy link

anu0123 commented Apr 10, 2015

Hi

I am unable to inject any Javascript function inside the predicates of one of the stub.
In the request i have asked to match the Query under PredicateGenerators.

The function which i have written is very simple
"predicates": [
{
{ "deepEquals":
{
"query":
{"inject": "function(logger)
{logger.info('Inside injection';)}"
}}}
}
I am not able to see any information on logs.
I have allowed Injection on mountebank startup by
mb --allowInjection.

Can anyone suggest anything ? Or if any changes has to be made ?

@bbyars
Copy link
Owner

bbyars commented Apr 10, 2015

Hi there,
The inject predicate looks unlike the other predicates because it needs
access to the entire request and therefore has to be at the top level.
Your example would need to look something like this:

"predicates": [
{
"inject": "function(request, logger) { logger.info('Inside injection');
logger.info(JSON.stringify(request, null, 4)); }"
}
]

The second log statement will show you what the request looks like, and you
can use that to do whatever tests you need. Let me know if that's still
confusing, happy to help you sort it out.
-Brandon

On Fri, Apr 10, 2015 at 12:49 PM, anu0123 notifications@github.com wrote:

Hi

I am unable to inject any Javascript function inside the predicates of one
of the stub.
In the request i have asked to match the Query under PredicateGenerators.

The function which i have written is very simple
"predicates": [
{

{ "deepEquals":
{
"query":
{"inject": "function(logger)
{logger.info('Inside injection';)}"
}}}
}
I am not able to see any information on logs.
I have allowed Injection on mountebank startup by
mb --allowInjection.

Can anyone suggest anything ? Or if any changes has to be made ?


Reply to this email directly or view it on GitHub
#63.

@anu0123
Copy link
Author

anu0123 commented Apr 15, 2015

I am injecting this function in a response which is captured after loading a request onto MounteBank but still it doesn't work.
I had one other question too. Which all predicates can we use besides matches in PredicateGenerators? Any other used with proper syntax throws errors.
Ex I am using : {
"port": 7575,
"protocol": "http",
"stubs": [
{
"responses": [
{
"proxy": {
"to": "http://www.orgin-server",
"mode": "proxyOnce",
"predicateGenerators": [
{
"or": [
{
"matches": {
"query": true
}
},
{
"contains": {
"query": "lp"
}
}
]
}
]
}
}
]
}
]
}

@bbyars
Copy link
Owner

bbyars commented Apr 16, 2015

Hi there,
Responses inline:

I am injecting this function in a response which is captured after loading

a request onto MounteBank but still it doesn't work.

Sorry you're having trouble. Can you send the full imposter JSON you're
sending so I can troubleshoot?

I had one other question too. Which all predicates can we use besides

matches in PredicateGenerators? Any other used with proper syntax throws
errors.

The predicateGenerators objects only accept matches. You can augment them
with caseSensitive and except, but you can't use them to create a contains
predicate, for example.

Ex I am using : {
"port": 7575,
"protocol": "http",
"stubs": [
{
"responses": [
{
"proxy": {
"to": "http://www.orgin-server",
"mode": "proxyOnce",
"predicateGenerators": [
{
"or": [
{
"matches": {
"query": true
}
},
{
"contains": {
"query": "lp"
}
}
]
}
]
}
}
]
}
]
}


Reply to this email directly or view it on GitHub
#63 (comment).

@bbyars bbyars closed this as completed May 2, 2015
@bbyars
Copy link
Owner

bbyars commented Oct 29, 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
None yet
Development

No branches or pull requests

2 participants