Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Upgrading jetty from 9.2.18 to 9.4.8
One potential breaking change - it has support for TLS1.2 alone. Meaning it disables (by default) all cipher suites that matches ^.*_(MD5|SHA|SHA1)$ which are the only ones which work with TLS 1.0 and TLS1.1. So if any of the client uses TLS1.1 or TLS1.0 then the communication will fail. Need to test if this is an issue for us or not.
This version fixes some known issues with JDK9
fixes a class loader leak issue on the version we were on
bunch of bug fixes and a few feature enhancements
  • Loading branch information
jyotisingh committed Apr 10, 2018
1 parent 1b6ddff commit c94853c
Show file tree
Hide file tree
Showing 14 changed files with 178 additions and 70 deletions.
3 changes: 3 additions & 0 deletions agent/build.gradle
Expand Up @@ -128,6 +128,9 @@ task verifyJar(type: VerifyJarTask) {
"jdom-2.0.2.jar",
"jetty-io-${versions.jetty}.jar",
"jetty-util-${versions.jetty}.jar",
"jetty-client-${versions.jetty}.jar",
"jetty-http-${versions.jetty}.jar",
"jetty-xml-${versions.jetty}.jar",
"joda-time-2.3.jar",
"jolt-core-0.1.0.jar",
"json-utils-0.1.0.jar",
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -157,7 +157,7 @@ rootProject.ext.versions = [
gson : '2.8.2',
hamcrest : '1.3',
jcommander : '1.72',
jetty : '9.2.18.v20160721',
jetty : '9.4.8.v20171121',
jgit : '4.9.0.201710071750-r',
jsonAssert : '1.5.0',
jsonUnit : '1.28.1',
Expand Down
Expand Up @@ -59,6 +59,12 @@ private AssetsHandler() {
resourceHandler.setEtags(false);
}

@Override
protected void doStart() throws Exception {
resourceHandler.doStart();
super.doStart();
}

public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
if (shouldNotHandle()) return;
this.resourceHandler.handle(target, baseRequest, request, response);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2017 ThoughtWorks, Inc.
* Copyright 2018 ThoughtWorks, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,7 +28,8 @@
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.servlets.gzip.GzipHandler;
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.webapp.JettyWebXmlConfiguration;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.webapp.WebInfConfiguration;
Expand All @@ -54,7 +55,7 @@
public class Jetty9Server extends AppServer {
protected static String JETTY_XML_LOCATION_IN_JAR = "/defaultFiles/config";
private static final String JETTY_XML = "jetty.xml";
private static final String JETTY_VERSION = "jetty-v9.2.3";
private static final String JETTY_VERSION = "jetty-v9.4.8.v20171121";
private Server server;
private WebAppContext webAppContext;
private static final Logger LOG = LoggerFactory.getLogger(Jetty9Server.class);
Expand Down Expand Up @@ -139,12 +140,12 @@ public void addExtraJarsToClasspath(String extraClasspath) {

@Override
public void setSessionConfig() {
SessionManager sessionManager = webAppContext.getSessionHandler().getSessionManager();
SessionCookieConfig sessionCookieConfig = sessionManager.getSessionCookieConfig();
SessionHandler sessionHandler = webAppContext.getSessionHandler();
SessionCookieConfig sessionCookieConfig = sessionHandler.getSessionCookieConfig();
sessionCookieConfig.setHttpOnly(true);
sessionCookieConfig.setSecure(systemEnvironment.isSessionCookieSecure());
sessionCookieConfig.setMaxAge(systemEnvironment.sessionCookieMaxAgeInSeconds());
sessionManager.setMaxInactiveInterval(systemEnvironment.sessionTimeoutInSeconds());
sessionHandler.setMaxInactiveInterval(systemEnvironment.sessionTimeoutInSeconds());
}

@Override
Expand Down
@@ -1,21 +1,22 @@
/*************************GO-LICENSE-START*********************************
* Copyright 2015 ThoughtWorks, Inc.
/*
* Copyright 2018 ThoughtWorks, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*************************GO-LICENSE-END***********************************/
*/

package com.thoughtworks.go.server.util;

import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.server.Request;

public class Jetty9Request implements ServletRequest {
Expand All @@ -32,17 +33,17 @@ public String getUrl() {

@Override
public String getUriPath() {
return request.getUri().getPath();
return request.getHttpURI().getPath();
}

@Override
public String getUriAsString() {
return request.getUri().toString();
return request.getHttpURI().getPathQuery();
}

@Override
public void setRequestURI(String uri) {
request.setRequestURI(uri);
request.getHttpURI().setPath(uri);
}

@Override
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2016 ThoughtWorks, Inc.
* Copyright 2018 ThoughtWorks, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,6 +28,7 @@
import org.hamcrest.Matcher;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
Expand All @@ -38,18 +39,21 @@
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.*;
import static org.mockito.MockitoAnnotations.initMocks;

public class AssetsContextHandlerTest {


private AssetsContextHandler handler;
@Mock
private SystemEnvironment systemEnvironment;
@Mock
private WebAppContext webAppContext;

@Before
public void setUp() throws Exception {
systemEnvironment = mock(SystemEnvironment.class);
initMocks(this);
when(systemEnvironment.getWebappContextPath()).thenReturn("/go");
WebAppContext webAppContext = mock(WebAppContext.class);
when(webAppContext.getInitParameter("rails.root")).thenReturn("/rails.root");
when(webAppContext.getWebInf()).thenReturn(Resource.newResource("WEB-INF"));
handler = new AssetsContextHandler(systemEnvironment);
Expand All @@ -64,17 +68,17 @@ public void shouldSetHeadersAndBaseDirectory() throws IOException {
AssetsContextHandler.AssetsHandler assetsHandler = (AssetsContextHandler.AssetsHandler) ((HandlerWrapper) handler.getHandler()).getHandler();
ResourceHandler resourceHandler = (ResourceHandler) ReflectionUtil.getField(assetsHandler, "resourceHandler");
assertThat(resourceHandler.getCacheControl(), is("max-age=31536000,public"));
assertThat(resourceHandler.getResourceBase(), isSameFileAs(new File("WEB-INF/rails.root/public/assets").toURI().toString()));
assertThat(resourceHandler.getResourceBase(), isSameFileAs(new File("WEB-INF/rails.root/public/assets").toPath().toAbsolutePath().toUri().toString()));
}

@Test
public void shouldPassOverHandlingToResourceHandler() throws IOException, ServletException {
public void shouldPassOverHandlingToResourceHandler() throws Exception {
when(systemEnvironment.useCompressedJs()).thenReturn(true);
String target = "/go/assets/junk";
Request request = mock(Request.class);
HttpServletResponse response = mock(HttpServletResponse.class);
Request baseRequest = mock(Request.class);
ResourceHandler resourceHandler = mock(ResourceHandler.class);
AssetsContextHandler.AssetsHandler resourceHandler = mock(AssetsContextHandler.AssetsHandler.class);
handler.setHandler(resourceHandler);

handler.getHandler().handle(target, baseRequest, request, response);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2017 ThoughtWorks, Inc.
* Copyright 2018 ThoughtWorks, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,7 +22,8 @@
import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.server.*;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.servlets.gzip.GzipHandler;
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.webapp.JettyWebXmlConfiguration;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.webapp.WebInfConfiguration;
Expand All @@ -33,6 +34,7 @@
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
Expand All @@ -56,20 +58,25 @@
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.*;
import static org.mockito.MockitoAnnotations.initMocks;

public class Jetty9ServerTest {

private Jetty9Server jetty9Server;
@Mock
private Server server;
@Mock
private SystemEnvironment systemEnvironment;
@Rule
public final TemporaryFolder temporaryFolder = new TemporaryFolder();
private File configDir;
@Mock
private SSLSocketFactory sslSocketFactory;

@Before
public void setUp() throws Exception {
server = mock(Server.class);

initMocks(this);
when(server.getThreadPool()).thenReturn(new QueuedThreadPool(1));
Answer<Void> setHandlerMock = new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
Expand All @@ -80,7 +87,6 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
};
Mockito.doAnswer(setHandlerMock).when(server).setHandler(any(Handler.class));

systemEnvironment = mock(SystemEnvironment.class);
when(systemEnvironment.getServerPort()).thenReturn(1234);
when(systemEnvironment.keystore()).thenReturn(temporaryFolder.newFolder());
when(systemEnvironment.truststore()).thenReturn(temporaryFolder.newFolder());
Expand All @@ -99,7 +105,6 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
when(systemEnvironment.sessionCookieMaxAgeInSeconds()).thenReturn(5678);


SSLSocketFactory sslSocketFactory = mock(SSLSocketFactory.class);
when(sslSocketFactory.getSupportedCipherSuites()).thenReturn(new String[]{});
jetty9Server = new Jetty9Server(systemEnvironment, "pwd", sslSocketFactory, server);
ReflectionUtil.setStaticField(Jetty9Server.class, "JETTY_XML_LOCATION_IN_JAR", "config");
Expand Down Expand Up @@ -151,7 +156,8 @@ public void shouldAddSSLSocketConnector() throws Exception {
ConnectionFactory second = iterator.next();
assertThat(first instanceof SslConnectionFactory, is(true));
SslConnectionFactory sslConnectionFactory = (SslConnectionFactory) first;
assertThat(sslConnectionFactory.getProtocol(), is("SSL-HTTP/1.1"));
assertThat(sslConnectionFactory.getProtocol(), is("SSL"));
assertThat(sslConnectionFactory.getNextProtocol(), is("HTTP/1.1"));
assertThat(second instanceof HttpConnectionFactory, is(true));
}

Expand Down Expand Up @@ -292,7 +298,7 @@ public void shouldSetSessionMaxInactiveInterval() throws Exception {
jetty9Server.setSessionConfig();

WebAppContext webAppContext = getWebAppContext(jetty9Server);
assertThat(webAppContext.getSessionHandler().getSessionManager().getMaxInactiveInterval(), is(1234));
assertThat(webAppContext.getSessionHandler().getMaxInactiveInterval(), is(1234));
}

@Test
Expand All @@ -302,7 +308,7 @@ public void shouldSetSessionCookieConfig() throws Exception {
jetty9Server.setSessionConfig();

WebAppContext webAppContext = getWebAppContext(jetty9Server);
SessionCookieConfig sessionCookieConfig = webAppContext.getSessionHandler().getSessionManager().getSessionCookieConfig();
SessionCookieConfig sessionCookieConfig = webAppContext.getSessionHandler().getSessionCookieConfig();
assertThat(sessionCookieConfig.isHttpOnly(), is(true));
assertThat(sessionCookieConfig.isSecure(), is(true));
assertThat(sessionCookieConfig.getMaxAge(), is(5678));
Expand Down Expand Up @@ -343,7 +349,7 @@ public void shouldNotReplaceJettyXmlIfItAlreadyContainsCorrespondingVersionNumbe
File jettyXml = temporaryFolder.newFile("jetty.xml");
when(systemEnvironment.getJettyConfigFile()).thenReturn(jettyXml);

String originalContent = "jetty-v9.2.3\nsome other local changes";
String originalContent = "jetty-v9.4.8.v20171121\nsome other local changes";
FileUtils.writeStringToFile(jettyXml, originalContent, UTF_8);
jetty9Server.replaceJettyXmlIfItBelongsToADifferentVersion(systemEnvironment.getJettyConfigFile());
assertThat(FileUtils.readFileToString(systemEnvironment.getJettyConfigFile(), UTF_8), is(originalContent));
Expand Down

0 comments on commit c94853c

Please sign in to comment.