SpectoLabs / hoverfly-java

Java binding for Hoverfly

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

startHoverflyProcess method cannot start process with desired options

pnip opened this issue · comments

commented

The startHoverflyProcess is flawed.

https://github.com/SpectoLabs/hoverfly-java/blob/master/src/main/java/io/specto/hoverfly/junit/core/Hoverfly.java#L164-L233

I specified a upstream-proxy and disableTlsVerification:

        LocalHoverflyConfig localHoverflyConfig = localConfigs();
        localHoverflyConfig.proxyPort(8500);
        localHoverflyConfig.disableTlsVerification();

        String modeStr = getProperty("hoverfly.mode");
        HoverflyMode mode = CAPTURE;
        if (modeStr != null && modeStr.equals(SIMULATE.getValue())) {
            mode = SIMULATE;
        }
        if (mode == CAPTURE) {
            String upstream = getProperty("upstream.llfs.proxy");
            if(upstream == null) {
                addError("In capture mode, upstream proxy cannot be null");
            }
            localHoverflyConfig.upstreamProxy(upstream);
        }
        Hoverfly hoverfly = new Hoverfly(localHoverflyConfig, mode);
        if (mode == SIMULATE) {
            SimulationSource source = classpath("simulation.json");
            hoverfly.simulate(source);
        }
        hoverfly.start();

Which result hoverfly invocation below from console:

2018-10-28 08:51:15 DEBUG ProcessExecutor:42 - Executing [/var/folders/yj/lfg_xqr54xg6ncbfmb257p8c0000gn/T/hoverfly.7847244821844173747/hoverfly_OSX_amd64, -db, memory, -pp, 8500, -ap, 59824, -tls-verification, false, -logs, json, -upstream-proxy, "http://foo.bar.com:4080"] in /var/folders/yj/lfg_xqr54xg6ncbfmb257p8c0000gn/T/hoverfly.7847244821844173747.

Which neither do disable tls verification nor do upstream proxy, the only way I could manage to make it run with both options on via manual invocation is the following:

Note: the option is set through the form "-option=value"

/var/folders/yj/lfg_xqr54xg6ncbfmb257p8c0000gn/T/hoverfly.7611927711352659532/hoverfly_OSX_amd64 -capture -upstream-proxy=http://foo.bar.com:4080 -tls-verification=false

INFO[2018-10-28T12:21:49-07:00] Upstream proxy has been set url=http://proxy01.stg.llfs.bf1.yahoo.com:4080
INFO[2018-10-28T12:21:49-07:00] TLS certificate verification has been disabled
INFO[2018-10-28T12:21:49-07:00] Using memory backend
INFO[2018-10-28T12:21:49-07:00] Proxy prepared... Destination=. Mode=capture ProxyPort=8500
INFO[2018-10-28T12:21:49-07:00] current proxy configuration destination=. mode=capture port=8500
INFO[2018-10-28T12:21:49-07:00] Admin interface is starting... AdminPort=8888
INFO[2018-10-28T12:21:49-07:00] serving proxy

commented

I patched up hoverfly to output -upstream-proxy="http://foo.bar.com:4080" in startXXX() method. Now it is doing the right thing config wise. (BTW -tls-verification=false is already fix in master branch):

2018-10-29 09:53:43 INFO Hoverfly:172 - Executing binary at /var/folders/yj/lfg_xqr54xg6ncbfmb257p8c0000gn/T/hoverfly.6150012318563413323/hoverfly_OSX_amd64
2018-10-29 09:53:43 DEBUG ProcessExecutor:42 - Executing [/var/folders/yj/lfg_xqr54xg6ncbfmb257p8c0000gn/T/hoverfly.6150012318563413323/hoverfly_OSX_amd64, -db, memory, -pp, 8500, -ap, 62129, -tls-verification=false, -logs, json, -upstream-proxy="http://foo.bar.com:4080"] in /var/folders/yj/lfg_xqr54xg6ncbfmb257p8c0000gn/T/hoverfly.6150012318563413323.

2018-10-29 09:53:43 DEBUG ProcessExecutor:42 - Started java.lang.UNIXProcess@3a45c42a
2018-10-29 09:53:43 DEBUG HoverflyClient:283 - Hoverfly healthcheck failed: Failed to connect to localhost/0:0:0:0:0:0:0:1:62129
2018-10-29 09:53:43 INFO hoverfly:75 - Default proxy port has been overwritten port=8500
2018-10-29 09:53:43 INFO hoverfly:75 - Default admin port has been overwritten port=62129
2018-10-29 09:53:43 INFO hoverfly:75 - Upstream proxy has been set url="http://foo.bar.com:4080"**
2018-10-29 09:53:43 INFO hoverfly:75 - TLS certificate verification has been disabled
2018-10-29 09:53:43 INFO hoverfly:75 - Using memory backend
2018-10-29 09:53:43 INFO hoverfly:75 - Proxy prepared... Destination=. Mode=simulate ProxyPort=8500
2018-10-29 09:53:43 INFO hoverfly:75 - current proxy configuration destination=. mode=simulate port=8500
2018-10-29 09:53:43 INFO hoverfly:75 - serving proxy
2018-10-29 09:53:43 INFO hoverfly:75 - Admin interface is starting... AdminPort=62129
2018-10-29 09:53:43 INFO hoverfly:75 - Mode has been changed mode=capture

@pnip the disableTlsVerification config issue was fixed here: 794d864. You should try using the latest version which is v0.11.1

There is a test for the upstream proxy config here: https://github.com/SpectoLabs/hoverfly-java/blob/master/src/test/java/io/specto/hoverfly/junit/core/HoverflyTest.java#L515

Let me know if it's still not working for some reason.

I can confirm that the upstream proxy should work fine with v0.11.2.

Given the following test:

@Test
    public void shouldSetUpstreamProxy() {
        hoverfly = new Hoverfly(localConfigs().upstreamProxy(new InetSocketAddress("127.0.0.1", 8900)).logToStdOut(), SIMULATE);

        hoverfly.start();
        HoverflyInfoView hoverflyInfo = hoverfly.getHoverflyInfo();

        assertThat(hoverflyInfo.getUpstreamProxy()).isEqualTo("http://127.0.0.1:8900");
    }

The printed log confirms upstream proxy is set:

2019-03-05 23:23:14,663 [INFO ] i.s.h.j.c.Hoverfly Executing binary at /var/folders/5y/zl7s5n3n74j3wkkz77rn_bjr0000gn/T/hoverfly.17249894974173319359/hoverfly_OSX_amd64
INFO[2019-03-05T23:23:14Z] Default proxy port has been overwritten       port=56903
INFO[2019-03-05T23:23:14Z] Default admin port has been overwritten       port=56904
INFO[2019-03-05T23:23:14Z] Upstream proxy has been set                   url="127.0.0.1:8900"
INFO[2019-03-05T23:23:14Z] Using memory backend                         
INFO[2019-03-05T23:23:14Z] Proxy prepared...                             Destination=. Mode=simulate ProxyPort=56903
INFO[2019-03-05T23:23:14Z] current proxy configuration                   destination=. mode=simulate port=56903
INFO[2019-03-05T23:23:14Z] serving proxy                                
INFO[2019-03-05T23:23:14Z] Admin interface is starting...                AdminPort=56904
INFO[2019-03-05T23:23:14Z] Mode has been changed                         mode=simulate