From: Sébastien Lesaint Date: Tue, 15 Nov 2016 15:18:11 +0000 (+0100) Subject: SONAR-8332 document use of %reqAttribute{ID} in access logs + add IT X-Git-Tag: 6.2-RC1~78 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4a70f34b373f454367f1a2139b306470dcc012d2;p=sonarqube.git SONAR-8332 document use of %reqAttribute{ID} in access logs + add IT --- diff --git a/it/it-tests/src/test/java/it/serverSystem/LogsTest.java b/it/it-tests/src/test/java/it/serverSystem/LogsTest.java index bd77db688bc..2a67c98e8a0 100644 --- a/it/it-tests/src/test/java/it/serverSystem/LogsTest.java +++ b/it/it-tests/src/test/java/it/serverSystem/LogsTest.java @@ -35,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class LogsTest { - public static final String ACCESS_LOGS_PATTERN = "\"%reqAttribute{LOGIN}\" \"%r\" %s"; + public static final String ACCESS_LOGS_PATTERN = "\"%reqAttribute{ID}\" \"%reqAttribute{LOGIN}\" \"%r\" %s"; private static final String PATH = "/called/from/LogsTest"; @ClassRule @@ -45,7 +45,7 @@ public class LogsTest { * SONAR-7581 */ @Test - public void test_access_logs() throws Exception { + public void verify_login_in_access_logs() throws Exception { // log "-" for anonymous sendHttpRequest(ItUtils.newWsClient(orchestrator), PATH); assertThat(accessLogsFile()).isFile().exists(); @@ -55,8 +55,18 @@ public class LogsTest { verifyLastAccessLogLine("admin", PATH, 404); } + @Test + public void verify_request_id_in_access_logs() throws IOException { + sendHttpRequest(ItUtils.newWsClient(orchestrator), PATH); + String lastAccessLog = readLastAccessLog(); + assertThat(lastAccessLog).doesNotStartWith("\"\"").startsWith("\""); + int firstQuote = lastAccessLog.indexOf('"'); + String requestId = lastAccessLog.substring(firstQuote + 1, lastAccessLog.indexOf('"', firstQuote + 1)); + assertThat(requestId.length()).isGreaterThanOrEqualTo(20); + } + private void verifyLastAccessLogLine(String login, String path, int status) throws IOException { - assertThat(readLastAccessLog()).isEqualTo(format("\"%s\" \"GET %s HTTP/1.1\" %d", login, path, status)); + assertThat(readLastAccessLog()).endsWith(format("\"%s\" \"GET %s HTTP/1.1\" %d", login, path, status)); } private String readLastAccessLog() throws IOException { diff --git a/sonar-application/src/main/assembly/conf/sonar.properties b/sonar-application/src/main/assembly/conf/sonar.properties index cab60b6040b..eeb779ad968 100644 --- a/sonar-application/src/main/assembly/conf/sonar.properties +++ b/sonar-application/src/main/assembly/conf/sonar.properties @@ -243,6 +243,7 @@ # - else a custom pattern. See http://logback.qos.ch/manual/layouts.html#AccessPatternLayout. # The login of authenticated user is not implemented with "%u" but with "%reqAttribute{LOGIN}" (since version 6.1). # The value displayed for anonymous users is "-". +# The SonarQube's HTTP request ID can be added to the pattern with "%reqAttribute{ID}" (since version 6.2). # If SonarQube is behind a reverse proxy, then the following value allows to display the correct remote IP address: #sonar.web.accessLogs.pattern=%i{X-Forwarded-For} %l %u [%t] "%r" %s %b "%i{Referer}" "%i{User-Agent}" # Default value is: