365048 - jetty Http client does not send proxy authentication when requesting a Https-resource through a web-proxy.
This commit is contained in:
parent
2fa5a63f3c
commit
69675d4d19
|
@ -180,9 +180,10 @@ public abstract class AbstractHttpConnection extends AbstractConnection implemen
|
|||
|
||||
String method=_exchange.getMethod();
|
||||
String uri = _exchange.getRequestURI();
|
||||
if (_destination.isProxied())
|
||||
if (_destination.isProxied())
|
||||
{
|
||||
if(!HttpMethods.CONNECT.equals(method) && uri.startsWith("/")){
|
||||
if (!HttpMethods.CONNECT.equals(method) && uri.startsWith("/"))
|
||||
{
|
||||
boolean secure = _destination.isSecure();
|
||||
String host = _destination.getAddress().getHost();
|
||||
int port = _destination.getAddress().getPort();
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
|
||||
package org.eclipse.jetty.client;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
@ -29,18 +27,11 @@ import org.eclipse.jetty.server.Server;
|
|||
import org.eclipse.jetty.server.handler.ConnectHandler;
|
||||
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Assume;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* This UnitTest class executes two tests. Both will send a http request to https://google.com through a misbehaving proxy server.
|
||||
* <p/>
|
||||
* The first test runs against a proxy which simply closes the connection (as nginx does) for a connect request. The second proxy server always responds with a
|
||||
* 500 error.
|
||||
* <p/>
|
||||
* The expected result for both tests is an exception and the HttpExchange should have status HttpExchange.STATUS_EXCEPTED.
|
||||
*/
|
||||
public class HttpsProxyAuthenticationTest
|
||||
{
|
||||
private Server _proxy = new Server();
|
||||
|
@ -50,22 +41,20 @@ public class HttpsProxyAuthenticationTest
|
|||
@Before
|
||||
public void init() throws Exception
|
||||
{
|
||||
// setup proxies with different behaviour
|
||||
_proxy.addConnector(new SelectChannelConnector());
|
||||
SelectChannelConnector connector = new SelectChannelConnector();
|
||||
_proxy.addConnector(connector);
|
||||
_proxy.setHandler(new ConnectHandler()
|
||||
{
|
||||
@Override
|
||||
protected boolean handleAuthentication(HttpServletRequest request, HttpServletResponse response, String address) throws ServletException,
|
||||
IOException
|
||||
protected boolean handleAuthentication(HttpServletRequest request, HttpServletResponse response, String address) throws ServletException, IOException
|
||||
{
|
||||
if(!request.getHeader("Authorization").isEmpty()){
|
||||
if (!request.getHeader("Authorization").isEmpty())
|
||||
authHandlerSend = true;
|
||||
}
|
||||
return super.handleAuthentication(request,response,address);
|
||||
}
|
||||
});
|
||||
_proxy.start();
|
||||
int proxyPort = _proxy.getConnectors()[0].getLocalPort();
|
||||
int proxyPort = connector.getLocalPort();
|
||||
|
||||
Authentication authentication = new BasicAuthentication(new Realm()
|
||||
{
|
||||
|
@ -85,7 +74,7 @@ public class HttpsProxyAuthenticationTest
|
|||
}
|
||||
});
|
||||
|
||||
_client.setProxy(new Address("localhost",proxyPort));
|
||||
_client.setProxy(new Address("localhost", proxyPort));
|
||||
_client.setProxyAuthentication(authentication);
|
||||
_client.start();
|
||||
}
|
||||
|
@ -95,22 +84,34 @@ public class HttpsProxyAuthenticationTest
|
|||
{
|
||||
_client.stop();
|
||||
_proxy.stop();
|
||||
_proxy.join();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpsViaProxyThatReturns504ErrorTest() throws Exception
|
||||
{
|
||||
sendRequestThroughProxy(new ContentExchange(),"google",7);
|
||||
assertTrue("Authorization header not set!",authHandlerSend);
|
||||
}
|
||||
// Assume that we can connect to google
|
||||
String host = "google.com";
|
||||
int port = 443;
|
||||
Socket socket = new Socket();
|
||||
try
|
||||
{
|
||||
socket.connect(new InetSocketAddress(host, port), 1000);
|
||||
}
|
||||
catch (IOException x)
|
||||
{
|
||||
Assume.assumeNoException(x);
|
||||
}
|
||||
finally
|
||||
{
|
||||
socket.close();
|
||||
}
|
||||
|
||||
private void sendRequestThroughProxy(HttpExchange exchange, String desiredBehaviour, int exptectedStatus) throws Exception
|
||||
{
|
||||
String url = "https://" + desiredBehaviour + ".com/";
|
||||
exchange.setURL(url);
|
||||
exchange.addRequestHeader("behaviour",desiredBehaviour);
|
||||
HttpExchange exchange = new ContentExchange();
|
||||
exchange.setURL("https://" + host + ":" + port);
|
||||
exchange.addRequestHeader("behaviour", "google");
|
||||
_client.send(exchange);
|
||||
assertEquals(HttpExchange.toState(exptectedStatus) + " status awaited",exptectedStatus,exchange.waitForDone());
|
||||
Assert.assertEquals(HttpExchange.STATUS_COMPLETED, exchange.waitForDone());
|
||||
Assert.assertTrue("Authorization header not set!", authHandlerSend);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue