]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorEric Hartmann <hartmann.eric@gmail.com>
Mon, 13 Nov 2017 17:02:33 +0000 (18:02 +0100)
committerEric Hartmann <hartmann.eric@gmail.Com>
Tue, 14 Nov 2017 12:10:17 +0000 (13:10 +0100)
server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/SelenideConfig.java
server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/Navigation.java
server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RuleDetails.java
server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RulesPage.java

index 155ded5ee56c0abc7e6e8e68c35b0ff6f1c69627..5146af560e88fc1f1e80485f1c1ab16c9ff469a4 100644 (file)
@@ -22,6 +22,7 @@ package org.sonarqube.qa.util;
 import com.codeborne.selenide.Configuration;
 import com.codeborne.selenide.WebDriverRunner;
 import com.sonar.orchestrator.Orchestrator;
+import java.util.Locale;
 import java.util.stream.Collectors;
 import org.openqa.selenium.WebDriver;
 
@@ -30,9 +31,9 @@ import static java.util.Arrays.stream;
 public class SelenideConfig {
 
   private enum Browser {
-    firefox("(v46 and lower)"),
-    marionette("(recent Firefox, require Geckodriver)"),
-    chrome("(require Chromedriver)");
+    FIREFOX("(v46 and lower)"),
+    MARIONETTE("(recent Firefox, require Geckodriver)"),
+    CHROME("(require Chromedriver)");
 
     private final String label;
 
@@ -42,7 +43,7 @@ public class SelenideConfig {
 
     static Browser of(String s) {
       try {
-        return Browser.valueOf(s);
+        return Browser.valueOf(s.toUpperCase(Locale.US));
       } catch (Exception e) {
         throw new IllegalArgumentException("Invalid browser: " + s + ". Supported values are " +
           stream(values()).map(b -> b.name() + " " + b.label).collect(Collectors.joining(", ")));
@@ -51,7 +52,7 @@ public class SelenideConfig {
   }
 
   public static WebDriver configure(Orchestrator orchestrator) {
-    String browserKey = orchestrator.getConfiguration().getString("orchestrator.browser", Browser.firefox.name());
+    String browserKey = orchestrator.getConfiguration().getString("orchestrator.browser", Browser.FIREFOX.name());
     Browser browser = Browser.of(browserKey);
     Configuration.browser = browser.name();
     Configuration.baseUrl = orchestrator.getServer().getUrl();
index fbfb8862fe7d2f17976d047b6f90331ffa1c867c..b9770335aad766ee3d2c5a8e124d9107aa307c3b 100644 (file)
@@ -38,6 +38,8 @@ import org.sonarqube.qa.util.pageobjects.organization.MembersPage;
 import org.sonarqube.qa.util.pageobjects.projects.ProjectsPage;
 import org.sonarqube.qa.util.pageobjects.settings.SettingsPage;
 
+import static java.lang.String.format;
+
 public class Navigation {
 
   public Navigation() {
@@ -92,14 +94,12 @@ public class Navigation {
   }
 
   public ProjectDashboardPage openProjectDashboard(String projectKey) {
-    // TODO encode projectKey
-    String url = "/dashboard?id=" + projectKey;
+    String url = "/dashboard?id=" + escape(projectKey);
     return open(url, ProjectDashboardPage.class);
   }
 
   public ProjectLinksPage openProjectLinks(String projectKey) {
-    // TODO encode projectKey
-    String url = "/project/links?id=" + projectKey;
+    String url = "/project/links?id=" + escape(projectKey);
     return open(url, ProjectLinksPage.class);
   }
 
@@ -109,43 +109,37 @@ public class Navigation {
   }
 
   public QualityGatePage openQualityGates(String organization) {
-    String url = "/organizations/" + organization + "/quality_gates";
+    String url = "/organizations/" + escape(organization) + "/quality_gates";
     return open(url, QualityGatePage.class);
   }
 
   public ProjectQualityGatePage openProjectQualityGate(String projectKey) {
-    // TODO encode projectKey
-    String url = "/project/quality_gate?id=" + projectKey;
+    String url = "/project/quality_gate?id=" + escape(projectKey);
     return open(url, ProjectQualityGatePage.class);
   }
 
   public ProjectKeyPage openProjectKey(String projectKey) {
-    // TODO encode projectKey
-    String url = "/project/key?id=" + projectKey;
+    String url = "/project/key?id=" + escape(projectKey);
     return open(url, ProjectKeyPage.class);
   }
 
   public ProjectActivityPage openProjectActivity(String projectKey) {
-    // TODO encode projectKey
-    String url = "/project/activity?id=" + projectKey;
+    String url = "/project/activity?id=" + escape(projectKey);
     return open(url, ProjectActivityPage.class);
   }
 
   public MeasuresPage openProjectMeasures(String projectKey) {
-    // TODO encode projectKey
-    String url = "/component_measures?id=" + projectKey;
+    String url = "/component_measures?id=" + escape(projectKey);
     return open(url, MeasuresPage.class);
   }
 
   public ProjectCodePage openCode(String projectKey) {
-    // TODO encode projectKey
-    String url = "/code?id=" + projectKey;
+    String url = "/code?id=" + escape(projectKey);
     return open(url, ProjectCodePage.class);
   }
 
   public ProjectCodePage openCode(String projectKey, String selected) {
-    // TODO encode projectKey and selected
-    String url = "/code?id=" + projectKey + "&selected=" + selected;
+    String url = "/code?id=" + escape(projectKey) + "&selected=" + escape(selected);
     return open(url, ProjectCodePage.class);
   }
 
@@ -155,7 +149,7 @@ public class Navigation {
   }
 
   public QualityProfilePage openQualityProfile(String language, String name, String organization) {
-    String profileUrl = "/quality_profiles/show?language=" + language + "&name=" + name;
+    String profileUrl = "/quality_profiles/show?language=" + escape(language) + "&name=" + escape(name);
     return open("/organizations/" + organization + profileUrl, QualityProfilePage.class);
   }
 
@@ -163,8 +157,8 @@ public class Navigation {
     return open("/background_tasks", BackgroundTasksPage.class);
   }
 
-  public SettingsPage openSettings(@Nullable String projectKey) throws UnsupportedEncodingException {
-    String url = projectKey != null ? ("/project/settings?id=" + URLEncoder.encode(projectKey, "UTF-8")) : "/settings";
+  public SettingsPage openSettings(@Nullable String projectKey) {
+    String url = projectKey != null ? ("/project/settings?id=" + escape(projectKey)) : "/settings";
     return open(url, SettingsPage.class);
   }
 
@@ -185,7 +179,7 @@ public class Navigation {
   }
 
   public ProjectPermissionsPage openProjectPermissions(String projectKey) {
-    String url = "/project_roles?id=" + projectKey;
+    String url = "/project_roles?id=" + escape(projectKey);
     return open(url, ProjectPermissionsPage.class);
   }
 
@@ -257,6 +251,19 @@ public class Navigation {
     return Selenide.$(".js-user-authenticated");
   }
 
+  /**
+   * Safe encoding for  URL parameters
+   * @param parameter the parameter to escape value
+   * @return the escaped value of parameter
+   */
+  private static String escape(String parameter) {
+    try {
+      return URLEncoder.encode(parameter, "UTF-8");
+    } catch (UnsupportedEncodingException e) {
+      throw new IllegalArgumentException(format("Unable to escape [%s]", parameter));
+    }
+  }
+
   public Navigation shouldBeRedirectedToLogin() {
     Selenide.$("#login_form").should(Condition.visible);
     return this;
index 035a66f3019d7affc41d50ab08016da331896c96..d50164f91c01dd1e85808ba3aca60e9aa57da3da 100644 (file)
  */
 package org.sonarqube.qa.util.pageobjects;
 
-import com.codeborne.selenide.Condition;
 import com.codeborne.selenide.Selenide;
-import com.codeborne.selenide.SelenideElement;
 
-public class RuleDetails {
-
-  private final SelenideElement elt;
+import static com.codeborne.selenide.Condition.text;
 
-  public RuleDetails(SelenideElement elt) {
-    this.elt = elt;
-  }
+public class RuleDetails {
 
   public RuleDetails shouldBeActivatedOn(String profileName) {
-    Selenide.$("#coding-rules-detail-quality-profiles").shouldHave(Condition.text(profileName));
+    Selenide.$("#coding-rules-detail-quality-profiles").shouldHave(text(profileName));
     return this;
   }
 
index 6b2916e5240e28badc177e68e62c10a1f76b5fc9..897d84cbdab255709d5403e1d32282cd46ee8115 100644 (file)
@@ -60,7 +60,7 @@ public class RulesPage extends Navigation {
   public RuleDetails openFirstRule() {
     Selenide.$$(".js-rule").first().click();
     Selenide.$(".coding-rules-details").shouldBe(Condition.visible);
-    return new RuleDetails(Selenide.$(".coding-rules-details"));
+    return new RuleDetails();
   }
 
 }