Jetty 12: `ContextHandler.getTempDirectory()` does not respect the `Context.getTempDirectory()` contract (#11397)
#11396 fix ContextHandler.getTempDirectory() so it never returns null as the contract mandates Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
parent
aa5eff978c
commit
3a6ad49271
|
@ -1126,7 +1126,7 @@ public class ContextHandler extends Handler.Wrapper implements Attributes, Alias
|
|||
{
|
||||
File tempDirectory = ContextHandler.this.getTempDirectory();
|
||||
if (tempDirectory == null)
|
||||
tempDirectory = getServer().getTempDirectory();
|
||||
tempDirectory = getServer().getContext().getTempDirectory();
|
||||
return tempDirectory;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
package org.eclipse.jetty.server;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
@ -44,6 +45,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
|||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
public class ServerTest
|
||||
{
|
||||
|
@ -109,6 +111,13 @@ public class ServerTest
|
|||
_connector = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContextTempDirectory()
|
||||
{
|
||||
File tempDirectory = _server.getContext().getTempDirectory();
|
||||
assertThat(tempDirectory, not(nullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleGET() throws Exception
|
||||
{
|
||||
|
|
|
@ -86,6 +86,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
|||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
|
@ -136,6 +137,17 @@ public class ContextHandlerTest
|
|||
FS.ensureDeleted(TEST_BAD.toPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContextTempDirectory() throws Exception
|
||||
{
|
||||
HelloHandler helloHandler = new HelloHandler();
|
||||
_contextHandler.setHandler(helloHandler);
|
||||
_server.start();
|
||||
|
||||
File tempDirectory = _contextHandler.getContext().getTempDirectory();
|
||||
assertThat(tempDirectory, not(nullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMiss() throws Exception
|
||||
{
|
||||
|
|
|
@ -371,6 +371,58 @@ public class MultiPartServletTest
|
|||
assertThat(fileList.length, is(0));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {true, false})
|
||||
public void testDefaultTempDirectory(boolean eager) throws Exception
|
||||
{
|
||||
start(new HttpServlet()
|
||||
{
|
||||
@Override
|
||||
protected void service(HttpServletRequest request, HttpServletResponse response1) throws ServletException, IOException
|
||||
{
|
||||
Collection<Part> parts = request.getParts();
|
||||
assertNotNull(parts);
|
||||
assertEquals(1, parts.size());
|
||||
Part part = parts.iterator().next();
|
||||
assertEquals("part1", part.getName());
|
||||
Collection<String> headerNames = part.getHeaderNames();
|
||||
assertNotNull(headerNames);
|
||||
assertEquals(2, headerNames.size());
|
||||
String content1 = IO.toString(part.getInputStream(), UTF_8);
|
||||
assertEquals("content1", content1);
|
||||
}
|
||||
}, new MultipartConfigElement(null, MAX_FILE_SIZE, -1, 0), eager);
|
||||
|
||||
try (Socket socket = new Socket("localhost", connector.getLocalPort()))
|
||||
{
|
||||
OutputStream output = socket.getOutputStream();
|
||||
|
||||
String content = """
|
||||
--A1B2C3
|
||||
Content-Disposition: form-data; name="part1"
|
||||
Content-Type: text/plain; charset="UTF-8"
|
||||
|
||||
content1
|
||||
--A1B2C3--
|
||||
""";
|
||||
String header = """
|
||||
POST / HTTP/1.1
|
||||
Host: localhost
|
||||
Content-Type: multipart/form-data; boundary="A1B2C3"
|
||||
Content-Length: $L
|
||||
|
||||
""".replace("$L", String.valueOf(content.length()));
|
||||
|
||||
output.write(header.getBytes(UTF_8));
|
||||
output.write(content.getBytes(UTF_8));
|
||||
output.flush();
|
||||
|
||||
HttpTester.Response response = HttpTester.parseResponse(socket.getInputStream());
|
||||
assertNotNull(response);
|
||||
assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {true, false})
|
||||
public void testMultiPartGzip(boolean eager) throws Exception
|
||||
|
|
Loading…
Reference in New Issue