Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-enable and fix websocket tests for Jetty 12 ee9 and ee10 #8742

Merged
merged 7 commits into from
Oct 21, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,25 @@
import java.util.Map;
import java.util.stream.Collectors;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.websocket.server.HandshakeRequest;
import org.eclipse.jetty.http.pathmap.PathSpec;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.util.Fields;
import org.eclipse.jetty.websocket.core.WebSocketConstants;
import org.eclipse.jetty.websocket.core.server.ServerUpgradeRequest;

public class JsrHandshakeRequest implements HandshakeRequest
{
private final ServerUpgradeRequest delegate;
private final HttpServletRequest httpServletRequest;
private Map<String, List<String>> parameterMap;

public JsrHandshakeRequest(ServerUpgradeRequest req)
{
this.delegate = req;
this.httpServletRequest = (HttpServletRequest)req
.getAttribute(WebSocketConstants.WEBSOCKET_WRAPPED_REQUEST_ATTRIBUTE);
}

@Override
Expand All @@ -49,8 +54,7 @@ public Map<String, List<String>> getHeaders()
@Override
public Object getHttpSession()
{
// TODO
return null;
return httpServletRequest.getSession(false);
}

@Override
Expand Down Expand Up @@ -94,14 +98,12 @@ public URI getRequestURI()
@Override
public Principal getUserPrincipal()
{
// TODO;
return null;
return httpServletRequest.getUserPrincipal();
}

@Override
public boolean isUserInRole(String role)
{
// TODO;
return false;
return httpServletRequest.isUserInRole(role);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package org.eclipse.jetty.ee10.websocket.jakarta.server.internal;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand All @@ -25,18 +24,19 @@
public class JsrHandshakeResponse implements HandshakeResponse
{
private final ServerUpgradeResponse delegate;
private final Map<String, List<String>> headers;

public JsrHandshakeResponse(ServerUpgradeResponse resp)
{
this.delegate = resp;
this.headers = delegate.getHeaders().getFieldNamesCollection().stream()
.collect(Collectors.toMap((name) -> name, (name) -> new ArrayList<>(delegate.getHeaders().getValuesList(name))));
}

@Override
public Map<String, List<String>> getHeaders()
{
Map<String, List<String>> headers = delegate.getHeaders().getFieldNamesCollection().stream()
.collect(Collectors.toMap((name) -> name, (name) -> new ArrayList<>(delegate.getHeaders().getValuesList(name))));
return Collections.unmodifiableMap(headers);
return headers;
}

public void setHeaders(Map<String, List<String>> headers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@
import org.eclipse.jetty.websocket.core.OpCode;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

@Disabled
public class AnnotatedServerEndpointTest
{
private LocalServer server;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnJre;
import org.junit.jupiter.api.condition.JRE;
Expand All @@ -63,7 +62,6 @@ public void stopServer() throws Exception
server.stop();
}

@Disabled
@Test
public void testBadPathParamSignature() throws Exception
{
Expand Down Expand Up @@ -95,7 +93,6 @@ public void testBadPathParamSignature() throws Exception
* @throws Exception if there is an error during the test.
*/
@Test
@Disabled
@DisabledOnJre({JRE.JAVA_14, JRE.JAVA_15})
public void testDifferentWebAppsWithSameClassInSignature() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.eclipse.jetty.websocket.core.OpCode;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -114,7 +113,6 @@ public void testInputStreamSocket() throws Exception
}
}

@Disabled
@Test
public void testInputStreamParamSocket() throws Exception
{
Expand All @@ -125,7 +123,7 @@ public void testInputStreamParamSocket() throws Exception
send.add(CloseStatus.toFrame(CloseStatus.NORMAL));

List<Frame> expect = new ArrayList<>();
expect.add(new Frame(OpCode.TEXT).setPayload("Hello World|Every Person"));
expect.add(new Frame(OpCode.TEXT).setPayload("Hello World|Every%20Person"));
expect.add(CloseStatus.toFrame(CloseStatus.NORMAL));

try (Fuzzer session = server.newNetworkFuzzer(requestPath))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.eclipse.jetty.websocket.core.OpCode;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -114,7 +113,6 @@ public void testReaderSocket() throws Exception
}
}

@Disabled
@Test
public void testReaderParamSocket() throws Exception
{
Expand All @@ -125,7 +123,7 @@ public void testReaderParamSocket() throws Exception
send.add(CloseStatus.toFrame(CloseStatus.NORMAL));

List<Frame> expect = new ArrayList<>();
expect.add(new Frame(OpCode.TEXT).setPayload("Hello World|Every Person"));
expect.add(new Frame(OpCode.TEXT).setPayload("Hello World|Every%20Person"));
expect.add(CloseStatus.toFrame(CloseStatus.NORMAL));

try (Fuzzer session = server.newNetworkFuzzer(requestPath))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.eclipse.jetty.util.security.Credential;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -145,7 +144,6 @@ private static SecurityHandler getSecurityHandler(String username, String passwo
return security;
}

@Disabled
@Test
public void testMyAuthedSocket() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,25 @@
import java.util.Map;
import java.util.stream.Collectors;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.websocket.server.HandshakeRequest;
import org.eclipse.jetty.http.pathmap.PathSpec;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.util.Fields;
import org.eclipse.jetty.websocket.core.WebSocketConstants;
import org.eclipse.jetty.websocket.core.server.ServerUpgradeRequest;

public class JsrHandshakeRequest implements HandshakeRequest
{
private final ServerUpgradeRequest delegate;
private final HttpServletRequest httpServletRequest;
private Map<String, List<String>> parameterMap;

public JsrHandshakeRequest(ServerUpgradeRequest req)
{
this.delegate = req;
this.httpServletRequest = (HttpServletRequest)req
.getAttribute(WebSocketConstants.WEBSOCKET_WRAPPED_REQUEST_ATTRIBUTE);
}

@Override
Expand All @@ -49,8 +54,7 @@ public Map<String, List<String>> getHeaders()
@Override
public Object getHttpSession()
{
// TODO
return null;
return httpServletRequest.getSession(false);
}

@Override
Expand Down Expand Up @@ -94,14 +98,12 @@ public URI getRequestURI()
@Override
public Principal getUserPrincipal()
{
// TODO;
return null;
return httpServletRequest.getUserPrincipal();
}

@Override
public boolean isUserInRole(String role)
{
// TODO;
return false;
return httpServletRequest.isUserInRole(role);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package org.eclipse.jetty.ee9.websocket.jakarta.server.internal;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand All @@ -25,18 +24,19 @@
public class JsrHandshakeResponse implements HandshakeResponse
{
private final ServerUpgradeResponse delegate;
private final Map<String, List<String>> headers;

public JsrHandshakeResponse(ServerUpgradeResponse resp)
{
this.delegate = resp;
this.headers = delegate.getHeaders().getFieldNamesCollection().stream()
.collect(Collectors.toMap((name) -> name, (name) -> new ArrayList<>(delegate.getHeaders().getValuesList(name))));
}

@Override
public Map<String, List<String>> getHeaders()
{
Map<String, List<String>> headers = delegate.getHeaders().getFieldNamesCollection().stream()
.collect(Collectors.toMap((name) -> name, (name) -> new ArrayList<>(delegate.getHeaders().getValuesList(name))));
return Collections.unmodifiableMap(headers);
return headers;
}

public void setHeaders(Map<String, List<String>> headers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.eclipse.jetty.server.ServerConnector;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -88,7 +87,6 @@ public void after() throws Exception
server.stop();
}

@Disabled
@Test
public void testShutdownWithContextHandler() throws Exception
{
Expand All @@ -101,7 +99,7 @@ public void testShutdownWithContextHandler() throws Exception
assertThat(clientContainer.isRunning(), is(true));

// The container should be a bean on the ContextHandler.
Collection<WebSocketContainer> containedBeans = contextHandler.getBeans(WebSocketContainer.class);
Collection<WebSocketContainer> containedBeans = contextHandler.getCoreContextHandler().getBeans(WebSocketContainer.class);
assertThat(containedBeans.size(), is(1));
assertThat(containedBeans.toArray()[0], is(container));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.eclipse.jetty.websocket.core.server.WebSocketServerComponents;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -38,7 +37,6 @@
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

@Disabled
public class JakartaWebSocketRestartTest
{
private Server server;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@
import org.eclipse.jetty.websocket.core.OpCode;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

@Disabled
public class AnnotatedServerEndpointTest
{
private LocalServer server;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.eclipse.jetty.websocket.core.exception.InvalidSignatureException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
Expand All @@ -47,7 +46,6 @@
* Deploy various {@link ServerEndpoint} annotated classes with invalid signatures,
* check for {@link DeploymentException}
*/
@Disabled
public class DeploymentExceptionTest
{
public static Stream<Arguments> data()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnJre;
import org.junit.jupiter.api.condition.JRE;
Expand All @@ -63,7 +62,6 @@ public void stopServer() throws Exception
server.stop();
}

@Disabled
@Test
public void testBadPathParamSignature() throws Exception
{
Expand Down Expand Up @@ -94,7 +92,6 @@ public void testBadPathParamSignature() throws Exception
* @see <a href="https://bugs.openjdk.java.net/browse/JDK-8244090">JDK-8244090</a>
* @throws Exception if there is an error during the test.
*/
@Disabled
@Test
@DisabledOnJre({JRE.JAVA_14, JRE.JAVA_15})
public void testDifferentWebAppsWithSameClassInSignature() throws Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.eclipse.jetty.websocket.core.OpCode;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -114,7 +113,6 @@ public void testInputStreamSocket() throws Exception
}
}

@Disabled
@Test
public void testInputStreamParamSocket() throws Exception
{
Expand All @@ -125,7 +123,7 @@ public void testInputStreamParamSocket() throws Exception
send.add(CloseStatus.toFrame(CloseStatus.NORMAL));

List<Frame> expect = new ArrayList<>();
expect.add(new Frame(OpCode.TEXT).setPayload("Hello World|Every Person"));
expect.add(new Frame(OpCode.TEXT).setPayload("Hello World|Every%20Person"));
expect.add(CloseStatus.toFrame(CloseStatus.NORMAL));

try (Fuzzer session = server.newNetworkFuzzer(requestPath))
Expand Down
Loading