Issue #9309 - Introducing test for requestlog format with spaces

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
Joakim Erdfelt 2023-02-03 08:45:35 -06:00
parent 016de2faeb
commit 46a316d4df
No known key found for this signature in database
GPG Key ID: 2D0E1FB8FE4B68B4
1 changed files with 54 additions and 0 deletions

View File

@ -23,6 +23,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Queue;
@ -1238,6 +1239,59 @@ public class DistributionTests extends AbstractJettyHomeTest
}
}
@Test
public void testRequestLogFormatWithSpaces() throws Exception
{
Path jettyBase = newTestJettyBaseDirectory();
String jettyVersion = System.getProperty("jettyVersion");
JettyHomeTester distribution = JettyHomeTester.Builder.newInstance()
.jettyVersion(jettyVersion)
.jettyBase(jettyBase)
.mavenLocalRepository(System.getProperty("mavenRepoPath"))
.build();
String[] args1 = {"--add-module=server,http,deploy,requestlog"};
try (JettyHomeTester.Run run1 = distribution.start(args1))
{
assertTrue(run1.awaitFor(10, TimeUnit.SECONDS));
assertEquals(0, run1.getExitValue());
// Setup custom format string with spaces
Path requestLogIni = distribution.getJettyBase().resolve("start.d/requestlog.ini");
List<String> lines = List.of(
"--module=requestlog",
"jetty.requestlog.filePath=logs/test.request.log",
"jetty.requestlog.formatString=%{client}a - %u %{dd/MMM/yyyy:HH:mm:ss ZZZ|GMT}t [foo space here] \"%r\" %s %O \"%{Referer}i\" \"%{User-Agent}i\""
);
Files.write(requestLogIni, lines, StandardCharsets.UTF_8, StandardOpenOption.TRUNCATE_EXISTING);
int port = distribution.freePort();
String[] args2 = {
"jetty.http.port=" + port,
};
try (JettyHomeTester.Run run2 = distribution.start(args2))
{
assertTrue(run2.awaitConsoleLogsFor("Started Server@", 10, TimeUnit.SECONDS));
startHttpClient(false);
String uri = "http://localhost:" + port + "/test";
// Generate a request
ContentResponse response = client.GET(uri + "/");
// Don't really care about the result, as any request should be logged in the requestlog
// We are just asserting a status here to ensure that the request is complete
assertThat(response.getStatus(), is(HttpStatus.NOT_FOUND_404));
Path requestLog = distribution.getJettyBase().resolve("logs/test.request.log");
List<String> loggedLines = Files.readAllLines(requestLog, StandardCharsets.UTF_8);
for (String loggedLine: loggedLines)
{
assertThat(loggedLine, containsString(" [foo space here] "));
}
}
}
}
@Test
public void testDryRunProperties() throws Exception
{