Merge pull request #7956 from eclipse/jetty-12.0.x-lachlan

fixes to Jetty 12 for Servlet/WebSocket tests
This commit is contained in:
Lachlan 2022-05-05 15:48:31 +10:00 committed by GitHub
commit 6fb717b1b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 275 additions and 279 deletions

View File

@ -19,6 +19,8 @@ import java.nio.ByteBuffer;
import java.nio.channels.WritableByteChannel;
import java.nio.charset.StandardCharsets;
import java.util.ListIterator;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.eclipse.jetty.http.BadMessageException;
import org.eclipse.jetty.http.CookieCompliance;
@ -26,6 +28,7 @@ import org.eclipse.jetty.http.HttpCookie;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpHeaderValue;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.io.QuietException;
import org.eclipse.jetty.server.handler.ErrorProcessor;
@ -270,6 +273,8 @@ public interface Response extends Content.Writer
return;
}
Response.ensureConsumeAllOrNotPersistent(request, response);
if (status <= 0)
status = HttpStatus.INTERNAL_SERVER_ERROR_500;
if (message == null)
@ -317,6 +322,79 @@ public interface Response extends Content.Writer
return -1;
}
static void ensureConsumeAllOrNotPersistent(Request request, Response response)
{
switch (request.getConnectionMetaData().getHttpVersion())
{
case HTTP_1_0:
if (consumeAll(request))
return;
// Remove any keep-alive value in Connection headers
response.getHeaders().computeField(HttpHeader.CONNECTION, (h, fields) ->
{
if (fields == null || fields.isEmpty())
return null;
String v = fields.stream()
.flatMap(field -> Stream.of(field.getValues()).filter(s -> !HttpHeaderValue.KEEP_ALIVE.is(s)))
.collect(Collectors.joining(", "));
if (StringUtil.isEmpty(v))
return null;
return new HttpField(HttpHeader.CONNECTION, v);
});
break;
case HTTP_1_1:
if (consumeAll(request))
return;
// Add close value to Connection headers
response.getHeaders().computeField(HttpHeader.CONNECTION, (h, fields) ->
{
if (fields == null || fields.isEmpty())
return HttpFields.CONNECTION_CLOSE;
if (fields.stream().anyMatch(f -> f.contains(HttpHeaderValue.CLOSE.asString())))
{
if (fields.size() == 1)
{
HttpField f = fields.get(0);
if (HttpFields.CONNECTION_CLOSE.equals(f))
return f;
}
return new HttpField(HttpHeader.CONNECTION, fields.stream()
.flatMap(field -> Stream.of(field.getValues()).filter(s -> !HttpHeaderValue.KEEP_ALIVE.is(s)))
.collect(Collectors.joining(", ")));
}
return new HttpField(HttpHeader.CONNECTION,
Stream.concat(fields.stream()
.flatMap(field -> Stream.of(field.getValues()).filter(s -> !HttpHeaderValue.KEEP_ALIVE.is(s))),
Stream.of(HttpHeaderValue.CLOSE.asString()))
.collect(Collectors.joining(", ")));
});
break;
default:
break;
}
}
static boolean consumeAll(Request request)
{
while (true)
{
Content content = request.readContent();
if (content == null)
return false;
content.release();
if (content.isLast())
return true;
}
}
class Wrapper implements Response
{
private final Request _request;

View File

@ -299,14 +299,14 @@ public class ResponseHttpFields implements HttpFields.Mutable
@Override
public void computeField(HttpHeader header, BiFunction<HttpHeader, List<HttpField>, HttpField> computeFn)
{
if (_committed.get())
if (!_committed.get())
_fields.computeField(header, computeFn);
}
@Override
public void computeField(String name, BiFunction<String, List<HttpField>, HttpField> computeFn)
{
if (_committed.get())
if (!_committed.get())
_fields.computeField(name, computeFn);
}

View File

@ -13,10 +13,14 @@
package org.eclipse.jetty.websocket.core.server.internal;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.ListIterator;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpHeaderValue;
public class HttpFieldsWrapper implements HttpFields.Mutable
{
@ -27,8 +31,6 @@ public class HttpFieldsWrapper implements HttpFields.Mutable
_fields = fields;
}
// TODO a signature that took HttpField would be better.
// TODO Do we need Put? Could it just be done as a onRemoveField then an onAddField?
public boolean onPutField(String name, String value)
{
return true;
@ -43,71 +45,122 @@ public class HttpFieldsWrapper implements HttpFields.Mutable
{
return true;
}
@Override
public Mutable add(String name, String value)
{
if (onAddField(name, value))
return _fields.add(name, value);
return this;
}
@Override
public Mutable add(HttpHeader header, HttpHeaderValue value)
{
if (onAddField(header.name(), value.asString()))
return _fields.add(header, value);
return this;
}
@Override
public Mutable add(HttpHeader header, String value)
{
if (onAddField(header.name(), value))
return _fields.add(header, value);
return this;
}
@Override
public Mutable add(HttpField field)
{
if (onAddField(field.getName(), field.getValue()))
return _fields.add(field);
return this;
}
@Override
public Mutable add(HttpFields fields)
{
for (HttpField field : fields)
{
add(field);
}
return this;
}
@Override
public Mutable clear()
{
return _fields.clear();
}
@Override
public Iterator<HttpField> iterator()
{
return _fields.iterator();
}
@Override
public ListIterator<HttpField> listIterator()
{
return new ListIterator<>()
return _fields.listIterator();
}
@Override
public Mutable put(HttpField field)
{
if (onPutField(field.getName(), field.getValue()))
return _fields.put(field);
return this;
}
@Override
public Mutable put(String name, String value)
{
if (onPutField(name, value))
return _fields.put(name, value);
return this;
}
@Override
public Mutable put(HttpHeader header, HttpHeaderValue value)
{
if (onPutField(header.name(), value.asString()))
return _fields.put(header, value);
return this;
}
@Override
public Mutable put(HttpHeader header, String value)
{
if (onPutField(header.name(), value))
return _fields.put(header, value);
return this;
}
@Override
public Mutable remove(HttpHeader header)
{
if (onRemoveField(header.name()))
return _fields.remove(header);
return this;
}
@Override
public Mutable remove(EnumSet<HttpHeader> fields)
{
for (HttpHeader header : fields)
{
final ListIterator<HttpField> _list = _fields.listIterator();
HttpField _last;
remove(header);
}
return this;
}
@Override
public boolean hasNext()
{
return _list.hasNext();
}
@Override
public HttpField next()
{
return _last = _list.next();
}
@Override
public boolean hasPrevious()
{
return _list.hasPrevious();
}
@Override
public HttpField previous()
{
return _last = _list.previous();
}
@Override
public int nextIndex()
{
return _list.nextIndex();
}
@Override
public int previousIndex()
{
return _list.previousIndex();
}
@Override
public void remove()
{
if (_last != null && HttpFieldsWrapper.this.onRemoveField(_last.getName()))
_list.remove();
}
@Override
public void set(HttpField httpField)
{
if (_last != null && HttpFieldsWrapper.this.onPutField(_last.getName(), _last.getValue()))
_list.set(httpField);
}
@Override
public void add(HttpField httpField)
{
if (_last != null && HttpFieldsWrapper.this.onAddField(_last.getName(), _last.getValue()))
_list.add(httpField);
}
};
@Override
public Mutable remove(String name)
{
if (onRemoveField(name))
return _fields.remove(name);
return this;
}
}

View File

@ -79,6 +79,7 @@ public class WebSocketHttpFieldsWrapper extends HttpFieldsWrapper
if (HttpHeader.SEC_WEBSOCKET_EXTENSIONS.is(name))
{
// TODO: why add extensions??
_response.addExtensions(Collections.emptyList());
return false;
}

View File

@ -83,6 +83,11 @@ public class ErrorHandler implements Request.Processor
@Override
public void process(Request request, Response response, Callback callback) throws Exception
{
if (!errorPageForMethod(request.getMethod()))
{
callback.succeeded();
return;
}
ServletContextRequest servletContextRequest = Request.as(request, ServletContextRequest.class);

View File

@ -36,6 +36,7 @@ import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Content;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.util.Blocking;
@ -468,7 +469,7 @@ public class ServletChannel implements Runnable
// from the failed dispatch, then we try to consume it here and if we fail we add a
// Connection:close. This can't be deferred to COMPLETE as the response will be committed
// by then.
ensureConsumeAllOrNotPersistent();
Response.ensureConsumeAllOrNotPersistent(_request, _request.getResponse());
ContextHandler.Context context = (ContextHandler.Context)_request.getAttribute(ErrorHandler.ERROR_CONTEXT);
Request.Processor errorProcessor = ErrorHandler.getErrorProcessor(getServer(), context == null ? null : context.getContextHandler());
@ -554,7 +555,7 @@ public class ServletChannel implements Runnable
// Indicate Connection:close if we can't consume all.
if (getResponse().getStatus() >= 200)
ensureConsumeAllOrNotPersistent();
Response.ensureConsumeAllOrNotPersistent(_request, _request.getResponse());
}
@ -599,19 +600,6 @@ public class ServletChannel implements Runnable
return !suspended;
}
private void ensureConsumeAllOrNotPersistent()
{
while (true)
{
Content content = getRequest().readContent();
if (content == null)
break;
content.release();
if (content.isLast())
break;
}
}
/**
* @param message the error message.
* @return true if we have sent an error, false if we have aborted.

View File

@ -28,7 +28,6 @@ import org.eclipse.jetty.ee10.servlet.security.SpnegoUserIdentity;
import org.eclipse.jetty.ee10.servlet.security.SpnegoUserPrincipal;
import org.eclipse.jetty.ee10.servlet.security.UserAuthentication;
import org.eclipse.jetty.ee10.servlet.security.UserIdentity;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.server.Request;
@ -119,8 +118,8 @@ public class ConfigurableSpnegoAuthenticator extends LoginAuthenticator
ServletContextRequest servletContextRequest = Request.as(req, ServletContextRequest.class);
HttpField header = req.getHeaders().getField(HttpHeader.AUTHORIZATION);
String spnegoToken = getSpnegoToken(header.getValue());
String header = req.getHeaders().get(HttpHeader.AUTHORIZATION);
String spnegoToken = getSpnegoToken(header);
HttpSession httpSession = servletContextRequest.getServletApiRequest().getSession(false);
// We have a token from the client, so run the login.

View File

@ -32,12 +32,10 @@ import org.eclipse.jetty.http.HttpTester;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@Disabled
public class AsyncContextListenersTest
{
private Server _server;

View File

@ -49,7 +49,6 @@ import org.eclipse.jetty.server.Server;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -61,7 +60,6 @@ import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@Disabled
public class ErrorPageTest
{
private static final Logger LOG = LoggerFactory.getLogger(ErrorPageTest.class);
@ -165,7 +163,7 @@ public class ErrorPageTest
assertThat(body, containsString("ERROR_CODE: 595"));
assertThat(body, containsString("ERROR_EXCEPTION: null"));
assertThat(body, containsString("ERROR_EXCEPTION_TYPE: null"));
assertThat(body, containsString("ERROR_SERVLET: org.eclipse.jetty.servlet.ErrorPageTest$ErrorContentTypeCharsetWriterInitializedServlet-"));
assertThat(body, containsString("ERROR_SERVLET: org.eclipse.jetty.ee10.servlet.ErrorPageTest$ErrorContentTypeCharsetWriterInitializedServlet-"));
assertThat(body, containsString("ERROR_REQUEST_URI: /error-mime-charset-writer/"));
}
@ -179,7 +177,7 @@ public class ErrorPageTest
assertThat(response, Matchers.containsString("ERROR_CODE: 594"));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION: null"));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION_TYPE: null"));
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.servlet.ErrorPageTest$ErrorAndStatusServlet-"));
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.ee10.servlet.ErrorPageTest$ErrorAndStatusServlet-"));
assertThat(response, Matchers.containsString("ERROR_REQUEST_URI: /error-and-status/anything"));
}
@ -274,7 +272,7 @@ public class ErrorPageTest
assertThat(response, Matchers.containsString("ERROR_CODE: 599"));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION: null"));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION_TYPE: null"));
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.servlet.ErrorPageTest$FailClosedServlet-"));
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.ee10.servlet.ErrorPageTest$FailClosedServlet-"));
assertThat(response, Matchers.containsString("ERROR_REQUEST_URI: /fail-closed/"));
assertThat(response, not(containsString("This shouldn't be seen")));
@ -289,7 +287,7 @@ public class ErrorPageTest
assertThat(response, Matchers.containsString("ERROR_CODE: 599"));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION: null"));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION_TYPE: null"));
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.servlet.ErrorPageTest$FailServlet-"));
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.ee10.servlet.ErrorPageTest$FailServlet-"));
assertThat(response, Matchers.containsString("ERROR_REQUEST_URI: /fail/code"));
}
@ -305,7 +303,7 @@ public class ErrorPageTest
assertThat(response, Matchers.containsString("ERROR_CODE: 500"));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION: jakarta.servlet.ServletException: java.lang.IllegalStateException: Test Exception"));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION_TYPE: class jakarta.servlet.ServletException"));
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.servlet.ErrorPageTest$FailServlet-"));
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.ee10.servlet.ErrorPageTest$FailServlet-"));
assertThat(response, Matchers.containsString("ERROR_REQUEST_URI: /fail/exception"));
}
@ -318,7 +316,7 @@ public class ErrorPageTest
assertThat(response, Matchers.containsString("ERROR_CODE: 500"));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION: java.lang.IllegalStateException: Test Exception"));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION_TYPE: class java.lang.IllegalStateException"));
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.servlet.ErrorPageTest$FailServlet-"));
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.ee10.servlet.ErrorPageTest$FailServlet-"));
assertThat(response, Matchers.containsString("ERROR_REQUEST_URI: /fail/exception"));
}
}
@ -332,7 +330,7 @@ public class ErrorPageTest
assertThat(response, Matchers.containsString("ERROR_CODE: 598"));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION: null"));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION_TYPE: null"));
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.servlet.ErrorPageTest$FailServlet-"));
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.ee10.servlet.ErrorPageTest$FailServlet-"));
assertThat(response, Matchers.containsString("ERROR_REQUEST_URI: /fail/global"));
}
@ -347,7 +345,7 @@ public class ErrorPageTest
assertThat(response, Matchers.containsString("ERROR_CODE: 500"));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION: java.lang.NumberFormatException: For input string: \"NAN\""));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION_TYPE: class java.lang.NumberFormatException"));
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.servlet.ErrorPageTest$FailServlet-"));
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.ee10.servlet.ErrorPageTest$FailServlet-"));
assertThat(response, Matchers.containsString("ERROR_REQUEST_URI: /fail/global"));
}
}
@ -360,11 +358,11 @@ public class ErrorPageTest
String response = _connector.getResponse("GET /app?baa=%88%A4 HTTP/1.0\r\n\r\n");
assertThat(response, Matchers.containsString("HTTP/1.1 400 Bad Request"));
assertThat(response, Matchers.containsString("ERROR_PAGE: /BadMessageException"));
assertThat(response, Matchers.containsString("ERROR_MESSAGE: Bad query encoding"));
assertThat(response, Matchers.containsString("ERROR_MESSAGE: Unable to parse URI query"));
assertThat(response, Matchers.containsString("ERROR_CODE: 400"));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION: org.eclipse.jetty.http.BadMessageException: 400: Bad query encoding"));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION: org.eclipse.jetty.http.BadMessageException: 400: Unable to parse URI query"));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION_TYPE: class org.eclipse.jetty.http.BadMessageException"));
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.servlet.ErrorPageTest$AppServlet-"));
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.ee10.servlet.ErrorPageTest$AppServlet-"));
assertThat(response, Matchers.containsString("ERROR_REQUEST_URI: /app"));
assertThat(response, Matchers.containsString("getParameterMap()= {}"));
}
@ -381,7 +379,7 @@ public class ErrorPageTest
assertThat(response, Matchers.containsString("ERROR_CODE: 599"));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION: null"));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION_TYPE: null"));
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.servlet.ErrorPageTest$AsyncSendErrorServlet-"));
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.ee10.servlet.ErrorPageTest$AsyncSendErrorServlet-"));
assertThat(response, Matchers.containsString("ERROR_REQUEST_URI: /async/info"));
assertTrue(__asyncSendErrorCompleted.await(10, TimeUnit.SECONDS));
}
@ -398,7 +396,7 @@ public class ErrorPageTest
assertThat(response, Matchers.containsString("ERROR_CODE: 599"));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION: null"));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION_TYPE: null"));
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.servlet.ErrorPageTest$AsyncSendErrorServlet-"));
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.ee10.servlet.ErrorPageTest$AsyncSendErrorServlet-"));
assertThat(response, Matchers.containsString("ERROR_REQUEST_URI: /async/info"));
assertTrue(__asyncSendErrorCompleted.await(10, TimeUnit.SECONDS));
}
@ -415,7 +413,7 @@ public class ErrorPageTest
assertThat(response, Matchers.containsString("ERROR_CODE: 599"));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION: null"));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION_TYPE: null"));
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.servlet.ErrorPageTest$AsyncSendErrorServlet-"));
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.ee10.servlet.ErrorPageTest$AsyncSendErrorServlet-"));
assertThat(response, Matchers.containsString("ERROR_REQUEST_URI: /async/info"));
assertTrue(__asyncSendErrorCompleted.await(10, TimeUnit.SECONDS));
}
@ -424,15 +422,16 @@ public class ErrorPageTest
@Test
public void testNoop() throws Exception
{
// The ServletContextHandler does not handle so should go to the servers ErrorProcessor.
String response = _connector.getResponse("GET /noop/info HTTP/1.0\r\n\r\n");
assertThat(response, Matchers.containsString("HTTP/1.1 404 Not Found"));
assertThat(response, Matchers.containsString("DISPATCH: ERROR"));
assertThat(response, Matchers.containsString("ERROR_PAGE: /GlobalErrorPage"));
assertThat(response, Matchers.containsString("ERROR_CODE: 404"));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION: null"));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION_TYPE: null"));
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.servlet.DefaultServlet-"));
assertThat(response, Matchers.containsString("ERROR_REQUEST_URI: /noop/info"));
assertThat(response, not(Matchers.containsString("DISPATCH: ERROR")));
assertThat(response, not(Matchers.containsString("ERROR_PAGE: /GlobalErrorPage")));
assertThat(response, not(Matchers.containsString("ERROR_CODE: 404")));
assertThat(response, not(Matchers.containsString("ERROR_EXCEPTION: null")));
assertThat(response, not(Matchers.containsString("ERROR_EXCEPTION_TYPE: null")));
assertThat(response, not(Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.ee10.servlet.DefaultServlet-")));
assertThat(response, not(Matchers.containsString("ERROR_REQUEST_URI: /noop/info")));
}
@Test
@ -445,7 +444,7 @@ public class ErrorPageTest
assertThat(response, Matchers.containsString("ERROR_CODE: 500"));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION: null"));
assertThat(response, Matchers.containsString("ERROR_EXCEPTION_TYPE: null"));
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.servlet.ErrorPageTest$NotEnoughServlet-"));
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.ee10.servlet.ErrorPageTest$NotEnoughServlet-"));
assertThat(response, Matchers.containsString("ERROR_REQUEST_URI: /notenough/info"));
}

View File

@ -708,7 +708,6 @@ public class ConstraintTest
return scenarios.stream();
}
@Disabled
@ParameterizedTest
@MethodSource("basicScenarios")
public void testBasic(Scenario scenario) throws Exception

View File

@ -13,190 +13,71 @@
package org.eclipse.jetty.ee10.servlet.security.authentication;
import java.io.IOException;
import org.eclipse.jetty.server.AbstractConnector;
import org.eclipse.jetty.ee10.servlet.ServletContextHandler;
import org.eclipse.jetty.ee10.servlet.security.ConstraintMapping;
import org.eclipse.jetty.ee10.servlet.security.ConstraintSecurityHandler;
import org.eclipse.jetty.ee10.servlet.security.EmptyLoginService;
import org.eclipse.jetty.server.LocalConnector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.security.Constraint;
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.junit.jupiter.api.Assertions.fail;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
@Disabled
public class SpnegoAuthenticatorTest
{
private ConfigurableSpnegoAuthenticator _authenticator;
private Server _server;
private LocalConnector _localConnector;
@BeforeEach
public void setup()
public void setup() throws Exception
{
_authenticator = new ConfigurableSpnegoAuthenticator();
ConfigurableSpnegoAuthenticator authenticator = new ConfigurableSpnegoAuthenticator();
_server = new Server();
_localConnector = new LocalConnector(_server);
_server.addConnector(_localConnector);
ServletContextHandler contextHandler = new ServletContextHandler();
_server.setHandler(contextHandler);
ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
contextHandler.setSecurityHandler(securityHandler);
securityHandler.setAuthenticator(authenticator);
securityHandler.setLoginService(new EmptyLoginService());
Constraint adminConstraint = new Constraint();
adminConstraint.setName(Constraint.__OPENID_AUTH);
adminConstraint.setRoles(new String[]{"admin"});
adminConstraint.setAuthenticate(true);
ConstraintMapping adminMapping = new ConstraintMapping();
adminMapping.setConstraint(adminConstraint);
adminMapping.setPathSpec("/*");
securityHandler.addConstraintMapping(adminMapping);
_server.start();
}
@AfterEach
public void after() throws Exception
{
_server.stop();
}
@Test
public void testChallengeSentWithNoAuthorization() throws Exception
{
/*
HttpChannel channel = new HttpChannel(new MockConnector(), new HttpConfiguration(), null, null)
{
@Override
public Server getServer()
{
return null;
}
@Override
public boolean failed(Throwable x)
{
return false;
}
@Override
protected boolean eof()
{
return false;
}
@Override
public boolean needContent()
{
return false;
}
@Override
public HttpInput.Content produceContent()
{
return null;
}
@Override
public boolean failAllContent(Throwable failure)
{
return false;
}
@Override
protected HttpOutput newHttpOutput()
{
return new HttpOutput(this)
{
@Override
public void close() {}
@Override
public void flush() throws IOException {}
};
}
};
Request req = channel.getRequest();
Response res = channel.getResponse();
MetaData.Request metadata = new MetaData.Request(null, HttpURI.build("http://localhost"), null, HttpFields.EMPTY);
req.setMetaData(metadata);
assertThat(channel.getState().handling(), is(HttpChannelState.Action.DISPATCH));
assertEquals(Authentication.SEND_CONTINUE, _authenticator.validateRequest(req, res, true));
assertEquals(HttpHeader.NEGOTIATE.asString(), res.getHeader(HttpHeader.WWW_AUTHENTICATE.asString()));
assertEquals(HttpServletResponse.SC_UNAUTHORIZED, res.getStatus());
*/
fail("re-write test case");
String response = _localConnector.getResponse("GET / HTTP/1.1\r\nHost:localhost\r\n\r\n");
assertThat(response, containsString("HTTP/1.1 401 Unauthorized"));
assertThat(response, containsString("WWW-Authenticate: Negotiate"));
}
@Test
public void testChallengeSentWithUnhandledAuthorization() throws Exception
{
/*
HttpChannel channel = new HttpChannel(new MockConnector(), new HttpConfiguration(), null, null)
{
@Override
public Server getServer()
{
return null;
}
@Override
public boolean failed(Throwable x)
{
return false;
}
@Override
protected boolean eof()
{
return false;
}
@Override
public boolean needContent()
{
return false;
}
@Override
public HttpInput.Content produceContent()
{
return null;
}
@Override
public boolean failAllContent(Throwable failure)
{
return false;
}
@Override
protected HttpOutput newHttpOutput()
{
return new HttpOutput(this)
{
@Override
public void close() {}
@Override
public void flush() throws IOException {}
};
}
};
Request req = channel.getRequest();
Response res = channel.getResponse();
// Create a bogus Authorization header. We don't care about the actual credentials.
MetaData.Request metadata = new MetaData.Request(null, HttpURI.build("http://localhost"), null,
HttpFields.build().add(HttpHeader.AUTHORIZATION, "Basic asdf"));
req.setMetaData(metadata);
assertThat(channel.getState().handling(), is(HttpChannelState.Action.DISPATCH));
assertEquals(Authentication.SEND_CONTINUE, _authenticator.validateRequest(req, res, true));
assertEquals(HttpHeader.NEGOTIATE.asString(), res.getHeader(HttpHeader.WWW_AUTHENTICATE.asString()));
assertEquals(HttpServletResponse.SC_UNAUTHORIZED, res.getStatus());
*/
fail("re-write test case");
}
class MockConnector extends AbstractConnector
{
public MockConnector()
{
super(new Server(), null, null, null, 0);
}
@Override
protected void accept(int acceptorID) throws IOException, InterruptedException
{
}
@Override
public Object getTransport()
{
return null;
}
@Override
public String dumpSelf()
{
return null;
}
String response = _localConnector.getResponse("GET / HTTP/1.1\r\nHost:localhost\r\nAuthorization:basic asdf\r\n\r\n");
assertThat(response, containsString("HTTP/1.1 401 Unauthorized"));
assertThat(response, containsString("WWW-Authenticate: Negotiate"));
}
}

View File

@ -34,7 +34,6 @@ import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.internal.HttpChannelState;
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;
@ -112,7 +111,6 @@ public class JettyWebSocketNegotiationTest
}
}
@Disabled
@Test
public void testManualNegotiationInCreator() throws Exception
{

View File

@ -36,7 +36,6 @@ import org.eclipse.jetty.util.BlockingArrayQueue;
import org.eclipse.jetty.util.BufferUtil;
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.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
@ -90,9 +89,8 @@ public class WebSocketListenerTest
server.stop();
}
@Disabled
@ParameterizedTest
@MethodSource("org.eclipse.jetty.websocket.tests.listeners.TextListeners#getTextListeners")
@MethodSource("org.eclipse.jetty.ee10.websocket.tests.listeners.TextListeners#getTextListeners")
public void testTextListeners(Class<?> clazz) throws Exception
{
EventSocket clientEndpoint = new EventSocket();
@ -111,9 +109,8 @@ public class WebSocketListenerTest
assertThat(clientEndpoint.closeReason, is("standard close"));
}
@Disabled
@ParameterizedTest
@MethodSource("org.eclipse.jetty.websocket.tests.listeners.BinaryListeners#getBinaryListeners")
@MethodSource("org.eclipse.jetty.ee10.websocket.tests.listeners.BinaryListeners#getBinaryListeners")
public void testBinaryListeners(Class<?> clazz) throws Exception
{
EventSocket clientEndpoint = new EventSocket();