]> source.dussan.org Git - sonarqube.git/commitdiff
Sanitize usage of ItUtils.setServerProperty
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 8 Sep 2016 09:30:58 +0000 (11:30 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 8 Sep 2016 09:54:29 +0000 (11:54 +0200)
- Period4 and period5 settings should only be reset at component level
- Replace empty string by null to remove setting when using ItUtils.setServerProperty

it/it-tests/src/test/java/it/settings/SettingsTest.java
it/it-tests/src/test/java/it/user/BaseIdentityProviderTest.java
it/it-tests/src/test/java/it/user/RealmAuthenticationTest.java
it/it-tests/src/test/java/util/ItUtils.java

index d44d6c3d92300a79433d076a11e76f986071e5ba..64d6da45e20b3ea9161ad7d834163b263d469f35 100644 (file)
@@ -76,7 +76,7 @@ public class SettingsTest {
    */
   @Test
   public void global_property_change_extension_point() throws IOException {
-    orchestrator.getServer().adminWsClient().post("api/properties/create?id=globalPropertyChange.received&value=NEWVALUE");
+    SETTINGS.set(SetRequest.builder().setKey("globalPropertyChange.received").setValue("NEWVALUE").build());
     assertThat(FileUtils.readFileToString(orchestrator.getServer().getLogs())).contains("Received change: [key=globalPropertyChange.received, newValue=NEWVALUE]");
   }
 
index 2890fc95d977003a84fb99dca714836ac1267d77..fcccdd5545a676ea60991a623f557134840f4112 100644 (file)
@@ -40,6 +40,7 @@ import util.user.Users;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.guava.api.Assertions.assertThat;
 import static util.ItUtils.newAdminWsClient;
+import static util.ItUtils.resetSettings;
 import static util.ItUtils.setServerProperty;
 
 /**
@@ -81,11 +82,8 @@ public class BaseIdentityProviderTest {
   public void cleanUpUsersAndGroupsAndProperties() throws Exception {
     userRule.deactivateUsers(USER_LOGIN);
     userRule.removeGroups(GROUP1, GROUP2, GROUP3);
-    setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.enabled", null);
-    setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.user", null);
-    setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.throwUnauthorizedMessage", null);
-    setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.enabledGroupsSync", null);
-    setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.groups", null);
+    resetSettings(ORCHESTRATOR, null, "sonar.auth.fake-base-id-provider.enabled", "sonar.auth.fake-base-id-provider.user",
+      "sonar.auth.fake-base-id-provider.throwUnauthorizedMessage", "sonar.auth.fake-base-id-provider.enabledGroupsSync", "sonar.auth.fake-base-id-provider.groups");
   }
 
   @Test
@@ -107,8 +105,7 @@ public class BaseIdentityProviderTest {
     setUserCreatedByAuthPlugin(USER_LOGIN, USER_PROVIDER_ID, USER_NAME, USER_EMAIL);
 
     new SeleneseTest(Selenese.builder().setHtmlTestsInClasspath("authenticate_through_ui",
-      "/user/BaseIdentityProviderTest/authenticate_user.html"
-      ).build()).runOn(ORCHESTRATOR);
+      "/user/BaseIdentityProviderTest/authenticate_user.html").build()).runOn(ORCHESTRATOR);
 
     userRule.verifyUserExists(USER_LOGIN, USER_NAME, USER_EMAIL);
   }
@@ -120,8 +117,7 @@ public class BaseIdentityProviderTest {
     setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.user", null);
 
     new SeleneseTest(Selenese.builder().setHtmlTestsInClasspath("display_unauthorized_page_when_authentication_failed",
-      "/user/BaseIdentityProviderTest/display_unauthorized_page_when_authentication_failed.html"
-      ).build()).runOn(ORCHESTRATOR);
+      "/user/BaseIdentityProviderTest/display_unauthorized_page_when_authentication_failed.html").build()).runOn(ORCHESTRATOR);
 
     userRule.verifyUserDoesNotExist(USER_LOGIN);
   }
@@ -133,8 +129,7 @@ public class BaseIdentityProviderTest {
     setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.allowsUsersToSignUp", "false");
 
     new SeleneseTest(Selenese.builder().setHtmlTestsInClasspath("fail_to_authenticate_when_not_allowed_to_sign_up",
-      "/user/BaseIdentityProviderTest/fail_to_authenticate_when_not_allowed_to_sign_up.html"
-      ).build()).runOn(ORCHESTRATOR);
+      "/user/BaseIdentityProviderTest/fail_to_authenticate_when_not_allowed_to_sign_up.html").build()).runOn(ORCHESTRATOR);
 
     userRule.verifyUserDoesNotExist(USER_LOGIN);
   }
@@ -196,8 +191,7 @@ public class BaseIdentityProviderTest {
     setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.throwUnauthorizedMessage", "true");
 
     new SeleneseTest(Selenese.builder().setHtmlTestsInClasspath("fail_to_authenticate_when_not_allowed_to_sign_up",
-      "/user/BaseIdentityProviderTest/fail_to_authenticate_when_not_allowed_to_sign_up.html"
-    ).build()).runOn(ORCHESTRATOR);
+      "/user/BaseIdentityProviderTest/fail_to_authenticate_when_not_allowed_to_sign_up.html").build()).runOn(ORCHESTRATOR);
 
     File logFile = ORCHESTRATOR.getServer().getLogs();
     assertThat(FileUtils.readFileToString(logFile)).doesNotContain("A functional error has happened");
@@ -263,7 +257,9 @@ public class BaseIdentityProviderTest {
 
   private static void setGroupsReturnedByAuthPlugin(String... groups) {
     setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.enabledGroupsSync", "true");
-    setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.groups", Joiner.on(",").join(groups));
+    if (groups.length > 0) {
+      setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.groups", Joiner.on(",").join(groups));
+    }
   }
 
   private static void authenticateWithFakeAuthProvider() {
index c61398ed44f1956a569b51a40c5a9889f544a53c..59863a364bf17b90982fb81f48d8b875727c947a 100644 (file)
@@ -25,6 +25,7 @@ import com.sonar.orchestrator.Orchestrator;
 import com.sonar.orchestrator.selenium.Selenese;
 import java.util.Map;
 import java.util.Objects;
+import javax.annotation.CheckForNull;
 import org.apache.commons.lang.RandomStringUtils;
 import org.junit.After;
 import org.junit.Before;
@@ -392,7 +393,11 @@ public class RealmAuthenticationTest {
     return new Sonar(new HttpClient4Connector(new Host(orchestrator.getServer().getUrl(), username, password)));
   }
 
+  @CheckForNull
   private static String format(Map<String, String> map) {
+    if (map.isEmpty()) {
+      return null;
+    }
     StringBuilder sb = new StringBuilder();
     for (Map.Entry<String, String> entry : map.entrySet()) {
       sb.append(entry.getKey()).append('=').append(entry.getValue()).append('\n');
index 9d1241340b156a045b26982b5736208979d9738d..9c00d48c63b8fb20322d67377d7be3a9067a5134 100644 (file)
@@ -36,7 +36,6 @@ import java.io.IOException;
 import java.lang.reflect.Type;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -56,6 +55,7 @@ import org.sonar.wsclient.services.PropertyUpdateQuery;
 import org.sonarqube.ws.client.HttpConnector;
 import org.sonarqube.ws.client.WsClient;
 import org.sonarqube.ws.client.WsClientFactories;
+import org.sonarqube.ws.client.setting.ResetRequest;
 
 import static com.google.common.base.Preconditions.checkState;
 import static com.google.common.collect.FluentIterable.from;
@@ -226,7 +226,7 @@ public class ItUtils {
   }
 
   public static void resetSettings(Orchestrator orchestrator, @Nullable String componentKey, String... keys) {
-    Arrays.stream(keys).forEach(key -> setServerProperty(orchestrator, componentKey, key, null));
+    newAdminWsClient(orchestrator).settingsService().reset(ResetRequest.builder().setKeys(keys).setComponentKey(componentKey).build());
   }
 
   public static void resetEmailSettings(Orchestrator orchestrator) {
@@ -235,8 +235,7 @@ public class ItUtils {
   }
 
   public static void resetPeriods(Orchestrator orchestrator) {
-    resetSettings(orchestrator, null, "sonar.timemachine.period1", "sonar.timemachine.period2", "sonar.timemachine.period3", "sonar.timemachine.period4",
-      "sonar.timemachine.period5");
+    resetSettings(orchestrator, null, "sonar.timemachine.period1", "sonar.timemachine.period2", "sonar.timemachine.period3");
   }
 
   /**