aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-qa-util/src
diff options
context:
space:
mode:
authorEric Hartmann <hartmann.eric@gmail.com>2017-11-13 18:02:33 +0100
committerEric Hartmann <hartmann.eric@gmail.Com>2017-11-14 13:10:17 +0100
commit30b3fee0d53040738b6106b905642310737e6618 (patch)
treeb734032de4b75bd65fba3b91ef1fb252606d9275 /server/sonar-qa-util/src
parent0369e48456a4ad3c238a9ad0b8980f77ed36e612 (diff)
downloadsonarqube-30b3fee0d53040738b6106b905642310737e6618.tar.gz
sonarqube-30b3fee0d53040738b6106b905642310737e6618.zip
Fix quality flaws
Diffstat (limited to 'server/sonar-qa-util/src')
-rw-r--r--server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/SelenideConfig.java11
-rw-r--r--server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/Navigation.java49
-rw-r--r--server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RuleDetails.java12
-rw-r--r--server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RulesPage.java2
4 files changed, 38 insertions, 36 deletions
diff --git a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/SelenideConfig.java b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/SelenideConfig.java
index 155ded5ee56..5146af560e8 100644
--- a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/SelenideConfig.java
+++ b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/SelenideConfig.java
@@ -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();
diff --git a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/Navigation.java b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/Navigation.java
index fbfb8862fe7..b9770335aad 100644
--- a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/Navigation.java
+++ b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/Navigation.java
@@ -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;
diff --git a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RuleDetails.java b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RuleDetails.java
index 035a66f3019..d50164f91c0 100644
--- a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RuleDetails.java
+++ b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RuleDetails.java
@@ -19,20 +19,14 @@
*/
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;
}
diff --git a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RulesPage.java b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RulesPage.java
index 6b2916e5240..897d84cbdab 100644
--- a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RulesPage.java
+++ b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RulesPage.java
@@ -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();
}
}