|
44 | 44 | import jakarta.servlet.ServletException; |
45 | 45 | import java.io.IOException; |
46 | 46 | import java.net.InetSocketAddress; |
| 47 | +import java.net.Socket; |
47 | 48 | import java.util.Arrays; |
48 | 49 | import java.util.HashMap; |
49 | 50 | import java.util.Map; |
|
55 | 56 | @RunWith(DefaultServer.class) |
56 | 57 | @ProxyIgnore |
57 | 58 | public class ProxyXForwardedTestCase { |
| 59 | + protected static int PORT; |
58 | 60 |
|
59 | 61 | @BeforeClass |
60 | 62 | public static void setup() throws ServletException { |
| 63 | + PORT = DefaultServer.getHostPort("default"); |
61 | 64 | final PathHandler root = new PathHandler(); |
62 | 65 | final ServletContainer container = ServletContainer.Factory.newInstance(); |
63 | 66 |
|
@@ -93,12 +96,13 @@ public void testProxyPeerHandler() throws IOException, ServletException { |
93 | 96 | HttpEntity entity = result.getEntity(); |
94 | 97 | String results = EntityUtils.toString(entity); |
95 | 98 | Map<String, String> map = convertWithStream(results); |
96 | | - InetSocketAddress serverAddress = DefaultServer.getDefaultServerAddress(); |
| 99 | + Socket socket = new Socket(); |
| 100 | + socket.connect(new InetSocketAddress(DefaultServer.getHostAddress(), PORT)); |
97 | 101 |
|
98 | 102 | Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode()); |
99 | | - Assert.assertEquals(serverAddress.getAddress().getHostAddress(), map.get(GenericServletConstants.LOCAL_ADDR)); |
100 | | - Assert.assertEquals(serverAddress.getAddress().getHostName(), map.get(GenericServletConstants.LOCAL_NAME)); |
101 | | - Assert.assertEquals(serverAddress.getPort(), Integer.parseInt(map.get(GenericServletConstants.LOCAL_PORT))); |
| 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))); |
102 | 106 | Assert.assertEquals("192.0.2.10", map.get(GenericServletConstants.SERVER_NAME)); |
103 | 107 | Assert.assertEquals("8888", map.get(GenericServletConstants.SERVER_PORT)); |
104 | 108 | Assert.assertEquals("192.0.2.43", map.get(GenericServletConstants.REMOTE_ADDR)); |
|
0 commit comments