MockServerHandler creates a request with path = uri #60

Closed
cstrecker opened this Issue Aug 8, 2014 · 6 comments

Projects

None yet

2 participants

@cstrecker

Hi James,

there is a bug in org.mockserver.mappers.NettyToMockServerRequestMapper. We use mockserver-netty 3.4

Before handling a request with uri = "http://localhost:8080/some-path" the MockServerHandler creates a NettyHttpRequest with this uri. Then the NettyToMockServerRequestMapper sets the path using NettyHttpRequest.getPath(). But this returns the uri:

"getPath() - Method in class org.jboss.netty.handler.codec.http.QueryStringDecoder
Returns the decoded path string of the URI. "

At the end you have a request with uri = "http://localhost:8080http://localhost:8080/some-path" and path = "http://localhost:8080/some-path". Therefore, the request mapping fails.

Regards, Conny

@cstrecker cstrecker changed the title from MockServerHandler creates NettyHttpRequest with path = uri to MockServerHandler creates a request with path = uri Aug 8, 2014
@jamesdbloom
Owner

Thanks sounds like a bug. Do you have some example code that causes the bug. That would really help me to fix it as I can add that as a test as it sounds like if this is failing there is also a missing test.

If you could send me the example failing scenario I should be able to fix this in this tomorrow.

@cstrecker

Hi,
we use the org.mockserver.integration.ClientAndServer within a web test with selenium-webdriver. I suppose you don't need our complete web test. :-)
Testing the constructor of org.mockserver.model.NettyHttpRequest should be enough.

But I think the actual error is that org.jboss.netty.handler.codec.http.QueryStringDecoder doesn't return the correct path.

Regards, Conny

@cstrecker

Hi James,
that the url of HttpRequest looks like "http://localhost:8080http://localhost:8080/some-path" is caused by NettyToMockServerRequestMapper.setUrl. You set url = host+port+uri. In our case uri = host+port+path and, therefore, we get host+port twice.

Here is an minimized example of a Selenium-Webdriver test to reproduce both bugs.

public class TestExample {
private static ClientAndServer MOCK_SERVER;
private static WebDriver WEB_DRIVER;
private static final String HOST = "localhost";
private static final int PORT = 12345;

@BeforeClass
public static void startProxy() {
    MOCK_SERVER = ClientAndServer.startClientAndServer(PORT);
    initWebDriver();
}

@AfterClass
public static void stopProxy() {
    MOCK_SERVER.stop();
    WEB_DRIVER.close();
}

public static void initWebDriver() {
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    final Proxy proxy = new Proxy();
    proxy.setProxyType(Proxy.ProxyType.MANUAL);
    proxy.setHttpProxy(String.format("%s:%s", new Object[]{HOST, PORT}));
    capabilities.setCapability(CapabilityType.PROXY, proxy);
    WEB_DRIVER = new FirefoxDriver(capabilities);
}

@Test
public void someTest() {
    MOCK_SERVER
            .when(
                    HttpRequest.request()
                            .withPath("/somePath"),
                    org.mockserver.matchers.Times.unlimited()
            ).respond(response()
                 .withBody("<html><body>some content</body></html>"));
    WEB_DRIVER.get("http://localhost:8080/somePath");
    Assert.assertThat(WEB_DRIVER.getPageSource(), 
         Matchers.containsString("some content"));
}
@jamesdbloom
Owner

Sorry for the delay but I've been flat out with two major initial releases of two new products.

The issue was caused by the fact that this netty method can return either a path or a full URL. I have added logic to handle both cases and covered everything with tests. Please retest it and let me know.

@jamesdbloom jamesdbloom added a commit that referenced this issue Aug 17, 2014
@jamesdbloom #60 fixed bug #58 added extension to support more flexible verificati…
…on - and added plugins for coverage and checkstyle however coverage restrictions are not yet set as some classes do not meet the required targets
d370329
@jamesdbloom
Owner

Closing as bug now fixed

@cstrecker

I have retested it ... it works ... thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment