Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import jakarta.servlet.ServletException;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -55,9 +56,11 @@
@RunWith(DefaultServer.class)
@ProxyIgnore
public class ProxyForwardedTestCase {
protected static int PORT;

@BeforeClass
public static void setup() throws ServletException {
PORT = DefaultServer.getHostPort("default");
final PathHandler root = new PathHandler();
final ServletContainer container = ServletContainer.Factory.newInstance();

Expand Down Expand Up @@ -95,12 +98,13 @@ public void testForwardedHandler() throws IOException {
HttpEntity entity = result.getEntity();
String results = EntityUtils.toString(entity);
Map<String, String> map = convertWithStream(results);
InetSocketAddress serverAddress = DefaultServer.getDefaultServerAddress();
Socket socket = new Socket();
socket.connect(new InetSocketAddress(DefaultServer.getHostAddress(), PORT));

Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Assert.assertEquals(serverAddress.getAddress().getHostAddress(), map.get(GenericServletConstants.LOCAL_ADDR));
Assert.assertEquals(serverAddress.getAddress().getHostName(), map.get(GenericServletConstants.LOCAL_NAME));
Assert.assertEquals(serverAddress.getPort(), Integer.parseInt(map.get(GenericServletConstants.LOCAL_PORT)));
Assert.assertEquals(socket.getLocalAddress().getHostAddress(), map.get(GenericServletConstants.LOCAL_ADDR));
Assert.assertEquals(socket.getLocalAddress().getHostName(), map.get(GenericServletConstants.LOCAL_NAME));
Assert.assertEquals(PORT, Integer.parseInt(map.get(GenericServletConstants.LOCAL_PORT)));
Assert.assertEquals("192.0.2.10", map.get(GenericServletConstants.SERVER_NAME));
Assert.assertEquals("8888", map.get(GenericServletConstants.SERVER_PORT));
Assert.assertEquals("192.0.2.43", map.get(GenericServletConstants.REMOTE_ADDR));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import jakarta.servlet.ServletException;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -55,9 +56,11 @@
@RunWith(DefaultServer.class)
@ProxyIgnore
public class ProxyXForwardedTestCase {
protected static int PORT;

@BeforeClass
public static void setup() throws ServletException {
PORT = DefaultServer.getHostPort("default");
final PathHandler root = new PathHandler();
final ServletContainer container = ServletContainer.Factory.newInstance();

Expand Down Expand Up @@ -93,12 +96,13 @@ public void testProxyPeerHandler() throws IOException, ServletException {
HttpEntity entity = result.getEntity();
String results = EntityUtils.toString(entity);
Map<String, String> map = convertWithStream(results);
InetSocketAddress serverAddress = DefaultServer.getDefaultServerAddress();
Socket socket = new Socket();
socket.connect(new InetSocketAddress(DefaultServer.getHostAddress(), PORT));

Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Assert.assertEquals(serverAddress.getAddress().getHostAddress(), map.get(GenericServletConstants.LOCAL_ADDR));
Assert.assertEquals(serverAddress.getAddress().getHostName(), map.get(GenericServletConstants.LOCAL_NAME));
Assert.assertEquals(serverAddress.getPort(), Integer.parseInt(map.get(GenericServletConstants.LOCAL_PORT)));
Assert.assertEquals(socket.getLocalAddress().getHostAddress(), map.get(GenericServletConstants.LOCAL_ADDR));
Assert.assertEquals(socket.getLocalAddress().getHostName(), map.get(GenericServletConstants.LOCAL_NAME));
Assert.assertEquals(PORT, Integer.parseInt(map.get(GenericServletConstants.LOCAL_PORT)));
Assert.assertEquals("192.0.2.10", map.get(GenericServletConstants.SERVER_NAME));
Assert.assertEquals("8888", map.get(GenericServletConstants.SERVER_PORT));
Assert.assertEquals("192.0.2.43", map.get(GenericServletConstants.REMOTE_ADDR));
Expand Down
Loading