Pass through proxy for recording network traffic

937 views
Skip to first unread message

ite...@googlemail.com

unread,
Oct 4, 2015, 5:12:55 AM10/4/15
to mountebank-discuss
Hi,

I'm using mountebank to stub out some services for testing. I'm pretty new to mountebank so these are pretty simple http stubbing examples. I'm loving the restful API, and GUI access to see clearly what's going on at all stages during development & debugging of the tests.

But I also have a requirement to examine & test the network traffic being generated by the application I'm testing via a selenium testing framework.

The only way I've found so far is to use browsermob-proxy and attach it selenium as a proxy server :

"proxy": {
"proxyType": "manual",
"httpProxy": "localhost:8082"
}

This seems to me to be acting as a simple pass through proxy that records all network traffic in a .HAR http archive format which I can examine in my tests.

This is necessary because I'm testing the integration of third party javascript libraries, and I can't simply override them to point at a stub - so need to record all the ajax calls.

I don't necessarily want to use mountebank AND browsermob-proxy.

I'd prefer to use mountebank but couldn't figure out a way of acheiving the network traffic recording I need.

Is there a simple way of setting up mountebank as a simple pass through proxy that can record all interactions coming from a selenium testing framework?

Thanks for making mountebank.

Brandon Byars

unread,
Oct 4, 2015, 12:44:23 PM10/4/15
to ite...@googlemail.com, mountebank-discuss
Hi there,
mountebank does support record-and-replay proxying (see http://www.mbtest.org/docs/api/proxies), and depending on your needs for recording the network traffic, can also expose the network traffic for inspection in your tests.  For that last bit, you need to run mb with the --mock parameter.

A simple example to get you started:

{
  "port": 3000,
  "protocol": "http",
  "stubs": [
    "responses": [
      {
        "proxy": {
          "to": "http://localhost:8082",
          "mode": "proxyAlways"
        }
      }
    ]
  ]
}

This will record all network traffic but continue to proxy it all to the downstream host (use "proxyOnce" instead of "proxyAlways" to only pass the first call to localhost:8082, and respond to subsequent requests with the recorded response).  Using something called predicateGenerators, you can treat (for example) requests to different URL paths to localhost:8082 as different proxied responses to record.

To see the requests that were made, send a GET to (in this example) http://localhost:2525/imposters/3000.  It will include a "requests" array that shows all the requests that were made.  If you want the requests and responses, pass the --debug flag to mb and take a look at the "matches" array.

Hope that's enough to get you started.  Feel free to reach out if you need help setting it up in your context.
-Brandon




--
You received this message because you are subscribed to the Google Groups "mountebank-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mountebank-disc...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ite...@googlemail.com

unread,
Oct 6, 2015, 3:39:53 PM10/6/15
to mountebank-discuss, ite...@googlemail.com
Hi,

thanks for the reply. I really appreciate it.

I'm not sure, but I don't think the example you gave does quite what I'm looking for.

For example, my app is running on port 3000, and Selenium is running on port 4444 - but I can tell selenium to run through a proxy on port 8082. Effectively this tells the browser that runs during tests to use a proxy on port 8082. (It's like going in to Firefox's settings and manually setting the browser to use a proxy on that port) Third party javascript libraries might generate ajax calls from my app to "abc.com" and "xyz.co.uk" that I want to 'examine'. I have no way of overriding these endpoints to point at a typical mountebank imposter.
With browsermob started on port 8080, I can curl a restful request to it, to start a proxy on 8082 which will then record all request/response that the browser makes through that port...

To put it another way, let's forget about selenium and tests - If I manually set my Chrome browser to use a proxy server at localhost:8082, is there any way I can use mountebank to start a 'pass-through' proxy on that port that will record all requests/responses that occur when I then browse using Chrome?

I know mountebank can do a lot of great stuff, and I was really excited about the injection ability - perhaps my use case is actually too simplistic.

Thanks

Brandon Byars

unread,
Oct 7, 2015, 10:23:39 AM10/7/15
to I Telic, mountebank-discuss
Ah - I understand now, thanks for the explanation.  There is no way currently to do that.  I'll add that to the backlog.
-Brandin

ite...@googlemail.com

unread,
Oct 10, 2015, 6:05:49 AM10/10/15
to mountebank-discuss, ite...@googlemail.com
On Wednesday, October 7, 2015 at 3:23:39 PM UTC+1, Brandon Byars wrote:
> Ah - I understand now, thanks for the explanation.  There is no way currently to do that.  I'll add that to the backlog.
> -Brandin
>
>
> On Tue, Oct 6, 2015 at 2:39 PM, <ite...@googlemail.com> wrote:
> Hi,
>
>
>
> thanks for the reply. I really appreciate it.
>
>
>
> I'm not sure, but I don't think the example you gave does quite what I'm looking for.
>
>
>
> For example, my app is running on port 3000, and Selenium is running on port 4444 - but I can tell selenium to run through a proxy on port 8082. Effectively this tells the browser that runs during tests to use a proxy on port 8082. (It's like going in to Firefox's settings and manually setting the browser to use a proxy on that port) Third party javascript libraries might generate ajax calls from my app to "abc.com" and "xyz.co.uk" that I want to 'examine'. I have no way of overriding these endpoints to point at a typical mountebank imposter.
>
> With browsermob started on port 8080, I can curl a restful request to it, to start a proxy on 8082 which will then record all request/response that the browser makes through that port...
>
>
>
> To put it another way, let's forget about selenium and tests - If I manually set my Chrome browser to use a proxy server at localhost:8082, is there any way I can use mountebank to start a 'pass-through' proxy on that port that will record all requests/responses that occur when I then browse using Chrome?
>
>
>
> I know mountebank can do a lot of great stuff, and I was really excited about the injection ability - perhaps my use case is actually too simplistic.
>
>
>
> Thanks
>
>
Thanks for the reply.

I really hope this project is supported and continues. Keep up the good work :)
Reply all
Reply to author
Forward
0 new messages