]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7168 add user login to log message when restart is requested 717/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 18 Jan 2016 08:39:22 +0000 (09:39 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 18 Jan 2016 10:16:44 +0000 (11:16 +0100)
it/it-tests/src/test/java/it/serverSystem/RestartTest.java
server/sonar-server/src/main/java/org/sonar/server/platform/ws/RestartAction.java
server/sonar-server/src/test/java/org/sonar/server/platform/ws/RestartActionTest.java

index 949f8f193a2b3d47a6d9f72bbd93927d55659e82..3101b9cc7ecda6e6d4d5c197b9121cc666923585 100644 (file)
@@ -77,7 +77,7 @@ public class RestartTest {
       Thread.sleep(5000);
 
       assertThat(FileUtils.readFileToString(orchestrator.getServer().getLogs()))
-        .contains("Requesting SonarQube restart");
+        .contains("SonarQube restart requested by admin");
     }
   }
 
index e2fe1d5c1175c3cc8f5cfad8aed040bfefae0696..97d84b0609e0e631c7c2d1650b5361f2d7a72419 100644 (file)
@@ -72,8 +72,8 @@ public class RestartAction implements SystemWsAction {
       platform.restart();
       LOGGER.info("WebServer restarted");
     } else {
-      LOGGER.info("Requesting SonarQube restart");
       userSession.checkPermission(UserRole.ADMIN);
+      LOGGER.info("SonarQube restart requested by {}", userSession.getLogin());
 
       File shareDir = nonNullValueAsFile(PROPERTY_SHARED_PATH);
       int processNumber = nonNullAsInt(PROPERTY_PROCESS_INDEX);
index 2818364f53f394ae3565f09ce5b07fdfaa0c10af..21b51b62ca38da6b7487c06babd2e33b79154dc7 100644 (file)
@@ -25,6 +25,8 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.config.Settings;
+import org.sonar.api.utils.log.LogTester;
+import org.sonar.api.utils.log.LoggerLevel;
 import org.sonar.api.web.UserRole;
 import org.sonar.process.DefaultProcessCommands;
 import org.sonar.server.exceptions.ForbiddenException;
@@ -38,15 +40,14 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
 public class RestartActionTest {
-  private static final int PROCESS_NUMBER = 1;
-
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
-
+  @Rule
+  public LogTester logTester = new LogTester();
 
   Settings settings = new Settings();
   Platform platform = mock(Platform.class);
@@ -102,10 +103,24 @@ public class RestartActionTest {
     settings.setProperty("process.index", processNumber);
 
     DefaultProcessCommands processCommands = new DefaultProcessCommands(tempFolder, processNumber);
-    
+
     actionTester.newRequest().execute();
 
     assertThat(processCommands.askedForRestart()).isTrue();
   }
 
+  @Test
+  public void logs_login_of_authenticated_user_requesting_the_restart_in_production_mode() throws Exception {
+    String login = "BigBother";
+
+    userSessionRule.login(login).setGlobalPermissions(UserRole.ADMIN);
+    settings.setProperty("process.sharedDir", temp.newFolder().getAbsoluteFile().getAbsolutePath());
+    settings.setProperty("process.index", 2);
+
+    actionTester.newRequest().execute();
+
+    assertThat(logTester.logs(LoggerLevel.INFO))
+      .contains("SonarQube restart requested by " + login);
+  }
+
 }