mirror of
https://github.com/jetty/jetty.project.git
synced 2025-03-02 20:09:21 +00:00
Issue #1202 - Adding testcase and fix for NPE in Sec-WebSocket-Extensions use
This commit is contained in:
parent
03a283235c
commit
bf80d822c0
@ -21,7 +21,6 @@ package org.eclipse.jetty.websocket.jsr356;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.security.Principal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@ -29,6 +28,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.websocket.CloseReason;
|
||||
import javax.websocket.EndpointConfig;
|
||||
@ -42,7 +42,6 @@ import javax.websocket.WebSocketContainer;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.websocket.api.BatchMode;
|
||||
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
||||
import org.eclipse.jetty.websocket.common.LogicalConnection;
|
||||
import org.eclipse.jetty.websocket.common.WebSocketSession;
|
||||
import org.eclipse.jetty.websocket.common.events.EventDriver;
|
||||
@ -241,13 +240,9 @@ public class JsrSession extends WebSocketSession implements javax.websocket.Sess
|
||||
@Override
|
||||
public List<Extension> getNegotiatedExtensions()
|
||||
{
|
||||
if (negotiatedExtensions == null)
|
||||
if ((negotiatedExtensions == null) && getUpgradeResponse().getExtensions() != null)
|
||||
{
|
||||
negotiatedExtensions = new ArrayList<Extension>();
|
||||
for (ExtensionConfig cfg : getUpgradeResponse().getExtensions())
|
||||
{
|
||||
negotiatedExtensions.add(new JsrExtension(cfg));
|
||||
}
|
||||
negotiatedExtensions = getUpgradeResponse().getExtensions().stream().map(JsrExtension::new).collect(Collectors.toList());
|
||||
}
|
||||
return negotiatedExtensions;
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ package org.eclipse.jetty.websocket.jsr356.server;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
@ -36,6 +37,7 @@ import java.util.TimeZone;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.websocket.DecodeException;
|
||||
import javax.websocket.Decoder;
|
||||
@ -97,9 +99,19 @@ public class ConfiguratorTest
|
||||
public static class NoExtensionsSocket
|
||||
{
|
||||
@OnMessage
|
||||
public String echo(String message)
|
||||
public String echo(Session session, String message)
|
||||
{
|
||||
return message;
|
||||
List<Extension> negotiatedExtensions = session.getNegotiatedExtensions();
|
||||
if (negotiatedExtensions == null)
|
||||
{
|
||||
return "negotiatedExtensions=null";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "negotiatedExtensions=" + negotiatedExtensions.stream()
|
||||
.map((ext) -> ext.getName())
|
||||
.collect(Collectors.joining(",", "[", "]"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -420,8 +432,13 @@ public class ConfiguratorTest
|
||||
client.addExtensions("identity");
|
||||
client.connect();
|
||||
client.sendStandardRequest();
|
||||
HttpResponse response = client.readResponseHeader();
|
||||
Assert.assertThat("response.extensions", response.getExtensionsHeader(), nullValue());
|
||||
HttpResponse response = client.expectUpgradeResponse();
|
||||
assertThat("response.extensions", response.getExtensionsHeader(), nullValue());
|
||||
|
||||
client.write(new TextFrame().setPayload("NegoExts"));
|
||||
EventQueue<WebSocketFrame> frames = client.readFrames(1, 1, TimeUnit.SECONDS);
|
||||
WebSocketFrame frame = frames.poll();
|
||||
assertThat("Frame Response", frame.getPayloadAsUTF8(), is("negotiatedExtensions=[]"));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user