Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-1874

ProxyForwardedTestCase and ProxyXForwardedTestCase should check results with DefaultServer.getDefaultServerAddress() instead of Socket.getLocalAddress()

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Minor
    • Resolution: Unresolved
    • 2.2.7.Final
    • None
    • Servlet
    • None

    Description

      ProxyForwardedTestCase and ProxyXForwardedTestCase has the following check:

       85     @Test
       86     public void testProxyPeerHandler() throws IOException, ServletException {
       87         TestHttpClient client = new TestHttpClient();
       88         try {
       :
       99             Socket socket = new Socket();
      100             socket.connect(new InetSocketAddress(DefaultServer.getHostAddress(), PORT));
      101 
      102             Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
      103             Assert.assertEquals(socket.getLocalAddress().getHostAddress(), map.get(GenericServletConstants.LOCAL_ADDR));
      104             Assert.assertEquals(socket.getLocalAddress().getHostName(), map.get(GenericServletConstants.LOCAL_NAME));
      105             Assert.assertEquals(PORT, Integer.parseInt(map.get(GenericServletConstants.LOCAL_PORT)));
      106             Assert.assertEquals("192.0.2.10", map.get(GenericServletConstants.SERVER_NAME));
      107             Assert.assertEquals("8888", map.get(GenericServletConstants.SERVER_PORT));
      108             Assert.assertEquals("192.0.2.43", map.get(GenericServletConstants.REMOTE_ADDR));
      109             Assert.assertEquals("0", map.get(GenericServletConstants.REMOTE_PORT));
      110 
      

      At line 103 and 104, it checks the results with socket.getLocalAddress(). This socket.getLocalAddress() returns a client-side local address of this socket.

      However, as ServletRequest.getLocalAddr(), ServletRequest.getLocalNamet() and ServletRequest.getLocalPort() are executed on the server-side, the result contains the local address of the server.

      A unit test runs on the same local machine (localhost), so the above check passes luckily. But I think the test code does not check correctly.

      I think Socket.getInetAddress() should be used instead of Socket.getLocalAddress().

      I think DefaultServer.getDefaultServerAddress() should be used instead of Socket.getLocalAddress().

      Attachments

        Issue Links

          Activity

            People

              flaviarnn Flavia Rainone
              rhn-support-mmiura Masafumi Miura
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: