Merge remote-tracking branch 'origin/jetty-12.0.x' into fix/12.0.x/properties-update

This commit is contained in:
Joakim Erdfelt 2023-12-11 09:19:08 -06:00
commit 835ec6f467
No known key found for this signature in database
GPG Key ID: 2D0E1FB8FE4B68B4
3 changed files with 60 additions and 13 deletions

View File

@ -154,15 +154,20 @@ public class SniSslConnectionFactoryTest
{ {
start((ssl, customizer) -> start((ssl, customizer) ->
{ {
// Disable the host check because this keystore has no CN and no SAN. // Disable the host check because this keystore has no CN and a SAN only for www.example.com.
ssl.setKeyStorePath("src/test/resources/keystore_sni_nowild.p12"); ssl.setKeyStorePath("src/test/resources/keystore_sni_nowild.p12");
customizer.setSniHostCheck(false); customizer.setSniHostCheck(false);
}); });
// This request won't match any CN or SAN, so the "default" certificate will be returned.
String response = getResponse("www.acme.org", null); String response = getResponse("www.acme.org", null);
assertThat(response, Matchers.containsString("X-HOST: www.acme.org")); assertThat(response, Matchers.containsString("X-HOST: www.acme.org"));
assertThat(response, Matchers.containsString("X-CERT: OU=default")); // The JDK implementation may return aliases in random order, so the
// "default" certificate could be any of the two present in the KeyStore.
assertThat(response, Matchers.either(Matchers.containsString("X-CERT: OU=default"))
.or(Matchers.containsString("X-CERT: OU=example")));
// This request matches a SAN in the KeyStore.
response = getResponse("www.example.com", null); response = getResponse("www.example.com", null);
assertThat(response, Matchers.containsString("X-HOST: www.example.com")); assertThat(response, Matchers.containsString("X-HOST: www.example.com"));
assertThat(response, Matchers.containsString("X-CERT: OU=example")); assertThat(response, Matchers.containsString("X-CERT: OU=example"));

View File

@ -250,17 +250,6 @@ public abstract class CoreClientUpgradeRequest implements Response.CompleteListe
int status = response.getStatus(); int status = response.getStatus();
String responseLine = status + " " + response.getReason(); String responseLine = status + " " + response.getReason();
if (!upgraded)
{
// We have failed to upgrade but have received a response, so notify the listener.
Throwable listenerError = notifyUpgradeListeners((listener) -> listener.onHandshakeResponse(request, response));
if (listenerError != null)
{
if (LOG.isDebugEnabled())
LOG.debug("error from listener", listenerError);
}
}
if (result.isFailed()) if (result.isFailed())
{ {
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
@ -281,6 +270,17 @@ public abstract class CoreClientUpgradeRequest implements Response.CompleteListe
return; return;
} }
if (!upgraded)
{
// We have failed to upgrade but have received a response, so notify the listener.
Throwable listenerError = notifyUpgradeListeners((listener) -> listener.onHandshakeResponse(request, response));
if (listenerError != null)
{
if (LOG.isDebugEnabled())
LOG.debug("error from listener", listenerError);
}
}
if (status != HttpStatus.SWITCHING_PROTOCOLS_101) if (status != HttpStatus.SWITCHING_PROTOCOLS_101)
{ {
// Failed to upgrade (other reason) // Failed to upgrade (other reason)

View File

@ -13,6 +13,7 @@
package org.eclipse.jetty.websocket.tests.client; package org.eclipse.jetty.websocket.tests.client;
import java.io.EOFException;
import java.net.URI; import java.net.URI;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ -22,6 +23,7 @@ import org.eclipse.jetty.client.Request;
import org.eclipse.jetty.client.Response; import org.eclipse.jetty.client.Response;
import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.io.Content; import org.eclipse.jetty.io.Content;
import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.ContextHandler;
@ -120,4 +122,44 @@ public class ClientResponseTest
assertThat(response.getHeaders().get("specialHeader"), equalTo("value123")); assertThat(response.getHeaders().get("specialHeader"), equalTo("value123"));
assertThat(content, equalTo("failed by test")); assertThat(content, equalTo("failed by test"));
} }
@Test
public void testServerAbort() throws Exception
{
before((req, resp, cb) ->
{
req.getConnectionMetaData().getConnection().getEndPoint().close();
cb.failed(new EofException());
return null;
});
EchoSocket clientEndpoint = new EchoSocket();
URI uri = URI.create("ws://localhost:" + _connector.getLocalPort());
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
CompletableFuture<Void> onHandShakeRequest = new CompletableFuture<>();
CompletableFuture<Void> onHandShakeResponse = new CompletableFuture<>();
JettyUpgradeListener upgradeListener = new JettyUpgradeListener()
{
@Override
public void onHandshakeRequest(Request request)
{
onHandShakeRequest.complete(null);
}
@Override
public void onHandshakeResponse(Request request, Response response)
{
onHandShakeResponse.complete(null);
}
};
Throwable t = assertThrows(Throwable.class, () ->
_client.connect(clientEndpoint, uri, upgradeRequest, upgradeListener).get(5, TimeUnit.SECONDS));
assertThat(t, instanceOf(ExecutionException.class));
assertThat(t.getCause(), instanceOf(EOFException.class));
assertDoesNotThrow(() -> onHandShakeRequest.get(5, TimeUnit.SECONDS));
assertThrows(Throwable.class, () -> onHandShakeResponse.get(1, TimeUnit.SECONDS));
}
} }