diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2018-06-19 11:38:59 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2018-06-19 18:34:42 +0200 |
commit | 3ba09d3fb4328ee12b68c33b1b9a16824cb04a25 (patch) | |
tree | 7e06b6079875b2dbaa2246001e170709efe9a00a /tests | |
parent | 335cb657544f2c01b9efdc561b42534e8dc558ee (diff) | |
download | sonarqube-3ba09d3fb4328ee12b68c33b1b9a16824cb04a25.tar.gz sonarqube-3ba09d3fb4328ee12b68c33b1b9a16824cb04a25.zip |
Replace some selenium tests by selenide in LocalAuthenticationTest
Diffstat (limited to 'tests')
5 files changed, 52 insertions, 261 deletions
diff --git a/tests/src/test/java/org/sonarqube/tests/user/LocalAuthenticationTest.java b/tests/src/test/java/org/sonarqube/tests/user/LocalAuthenticationTest.java index 51e258bdfb8..0b15743fc48 100644 --- a/tests/src/test/java/org/sonarqube/tests/user/LocalAuthenticationTest.java +++ b/tests/src/test/java/org/sonarqube/tests/user/LocalAuthenticationTest.java @@ -22,7 +22,6 @@ package org.sonarqube.tests.user; import com.codeborne.selenide.Condition; import com.sonar.orchestrator.Orchestrator; import java.util.UUID; -import org.junit.After; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; @@ -46,10 +45,10 @@ import org.sonarqube.ws.client.usertokens.SearchRequest; import org.sonarqube.ws.client.usertokens.UserTokensService; import util.selenium.Selenese; +import static com.codeborne.selenide.WebDriverRunner.url; import static java.lang.String.format; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; -import static util.ItUtils.resetSettings; import static util.ItUtils.setServerProperty; public class LocalAuthenticationTest { @@ -60,11 +59,6 @@ public class LocalAuthenticationTest { @Rule public Tester tester = new Tester(orchestrator).disableOrganizations(); - @After - public void resetProperties() { - resetSettings(orchestrator, null, "sonar.forceAuthentication"); - } - @Test public void log_in_with_correct_credentials_then_log_out() { User user = tester.users().generate(); @@ -170,16 +164,57 @@ public class LocalAuthenticationTest { } @Test - public void test_authentication_redirects_in_ui() { - tester.users().generate(u -> u.setLogin("simple-user").setPassword("password")); - tester.users().generateAdministrator(u -> u.setLogin("admin-user").setPassword("admin-user")); - Selenese.runSelenese(orchestrator, - "/user/LocalAuthenticationTest/redirect_to_login_when_not_enough_privilege.html", - // SONAR-2132 - "/user/LocalAuthenticationTest/redirect_to_original_url_after_direct_login.html", - "/user/LocalAuthenticationTest/redirect_to_original_url_with_parameters_after_direct_login.html", - // SONAR-2009 - "/user/LocalAuthenticationTest/redirect_to_original_url_after_indirect_login.html"); + public void redirect_to_login_when_not_enough_privilege() { + User user = tester.users().generate(); + Navigation navigation = tester.openBrowser() + .logIn() + .submitCredentials(user.getLogin()); + + navigation.open("/settings"); + + navigation.shouldBeRedirectedToLogin(); + } + + @Test + public void redirect_to_original_url_after_indirect_login() { + User admin = tester.users().generateAdministrator(); + Navigation navigation = tester.openBrowser(); + + navigation.open("/settings"); + navigation + .shouldBeRedirectedToLogin() + .submitCredentials(admin.getLogin()) + .shouldBeLoggedIn(); + + assertThat(url()).endsWith("/settings"); + } + + @Test + public void redirect_to_original_url_after_direct_login() { + User user = tester.users().generate(); + Navigation navigation = tester.openBrowser(); + + navigation.openQualityGates(); + navigation + .logIn() + .submitCredentials(user.getLogin()) + .shouldBeLoggedIn(); + + assertThat(url()).contains("quality_gates"); + } + + @Test + public void redirect_to_original_url_with_parameters_after_direct_login() { + User admin = tester.users().generateAdministrator(); + Navigation navigation = tester.openBrowser(); + + navigation.openProjectsWithQuery("gate=OK&reliability=1&security=1"); + navigation + .logIn() + .submitCredentials(admin.getLogin()) + .shouldBeLoggedIn(); + + assertThat(url()).endsWith("/projects?gate=OK&reliability=1&security=1"); } @Test diff --git a/tests/src/test/resources/user/LocalAuthenticationTest/redirect_to_login_when_not_enough_privilege.html b/tests/src/test/resources/user/LocalAuthenticationTest/redirect_to_login_when_not_enough_privilege.html deleted file mode 100644 index d461a89cb7e..00000000000 --- a/tests/src/test/resources/user/LocalAuthenticationTest/redirect_to_login_when_not_enough_privilege.html +++ /dev/null @@ -1,59 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -<head profile="http://selenium-ide.openqa.org/profiles/test-case"> - <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> - <title>redirect-to-original-url-after-direct-login</title> -</head> -<body> -<table cellpadding="1" cellspacing="1" border="1"> - <tbody> - <tr> - <td>open</td> - <td>/sessions/new</td> - <td></td> -</tr> -<tr> - <td>waitForText</td> - <td>content</td> - <td>*Log In to SonarQube*</td> -</tr> -<tr> - <td>type</td> - <td>login</td> - <td>simple-user</td> -</tr> -<tr> - <td>type</td> - <td>password</td> - <td>password</td> -</tr> -<tr> - <td>clickAndWait</td> - <td>[type=submit]</td> - <td></td> -</tr> -<tr> - <td>waitForElementPresent</td> - <td>css=.js-user-authenticated</td> - <td></td> -</tr> -<tr> - <td>open</td> - <td>/settings</td> - <td></td> -</tr> -<tr> - <td>waitForText</td> - <td>content</td> - <td>*Log In to SonarQube*</td> -</tr> -<tr> - <td>assertText</td> - <td>content</td> - <td>*You are not authorized to access this page. Please log in with more privileges and try again.*</td> -</tr> -</tbody> -</table> -</body> -</html> diff --git a/tests/src/test/resources/user/LocalAuthenticationTest/redirect_to_original_url_after_direct_login.html b/tests/src/test/resources/user/LocalAuthenticationTest/redirect_to_original_url_after_direct_login.html deleted file mode 100644 index 4fb3a5df6ee..00000000000 --- a/tests/src/test/resources/user/LocalAuthenticationTest/redirect_to_original_url_after_direct_login.html +++ /dev/null @@ -1,59 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -<head profile="http://selenium-ide.openqa.org/profiles/test-case"> - <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> - <title>redirect-to-original-url-after-direct-login</title> -</head> -<body> -<table cellpadding="1" cellspacing="1" border="1"> - <tbody> - <tr> - <td>open</td> - <td>/sessions/logout</td> - <td></td> - </tr> - <tr> - <td>waitForText</td> - <td>global-navigation</td> - <td>*Log in*</td> - </tr> - <tr> - <td>open</td> - <td>/settings?category=general</td> - <td></td> - </tr> - <tr> - <td>waitForText</td> - <td>content</td> - <td>*Log In to SonarQube*</td> - </tr> - <tr> - <td>type</td> - <td>login</td> - <td>admin-user</td> - </tr> - <tr> - <td>type</td> - <td>password</td> - <td>admin-user</td> - </tr> - <tr> - <td>clickAndWait</td> - <td>[type=submit]</td> - <td></td> - </tr> - <tr> - <td>waitForElementPresent</td> - <td>css=.js-user-authenticated</td> - <td></td> - </tr> - <tr> - <td>assertLocation</td> - <td>glob:*/settings?category=general*</td> - <td></td> - </tr> - </tbody> -</table> -</body> -</html> diff --git a/tests/src/test/resources/user/LocalAuthenticationTest/redirect_to_original_url_after_indirect_login.html b/tests/src/test/resources/user/LocalAuthenticationTest/redirect_to_original_url_after_indirect_login.html deleted file mode 100644 index ab1cd03aa55..00000000000 --- a/tests/src/test/resources/user/LocalAuthenticationTest/redirect_to_original_url_after_indirect_login.html +++ /dev/null @@ -1,58 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -<head profile="http://selenium-ide.openqa.org/profiles/test-case"> - <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> -</head> -<body> -<table cellpadding="1" cellspacing="1" border="1"> - <tbody> - <tr> - <td>open</td> - <td>/sessions/logout</td> - <td></td> - </tr> - <tr> - <td>waitForText</td> - <td>global-navigation</td> - <td>*Log in*</td> - </tr> - <tr> - <td>open</td> - <td>/settings</td> - <td></td> - </tr> - <tr> - <td>waitForText</td> - <td>content</td> - <td>*Log In to SonarQube*</td> - </tr> - <tr> - <td>type</td> - <td>login</td> - <td>admin-user</td> - </tr> - <tr> - <td>type</td> - <td>password</td> - <td>admin-user</td> - </tr> - <tr> - <td>clickAndWait</td> - <td>[type=submit]</td> - <td></td> - </tr> - <tr> - <td>waitForElementPresent</td> - <td>css=.js-user-authenticated</td> - <td></td> - </tr> - <tr> - <td>assertLocation</td> - <td>*/settings</td> - <td></td> - </tr> - </tbody> -</table> -</body> -</html> diff --git a/tests/src/test/resources/user/LocalAuthenticationTest/redirect_to_original_url_with_parameters_after_direct_login.html b/tests/src/test/resources/user/LocalAuthenticationTest/redirect_to_original_url_with_parameters_after_direct_login.html deleted file mode 100644 index 907b27e1aae..00000000000 --- a/tests/src/test/resources/user/LocalAuthenticationTest/redirect_to_original_url_with_parameters_after_direct_login.html +++ /dev/null @@ -1,68 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -<head profile="http://selenium-ide.openqa.org/profiles/test-case"> - <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> -</head> -<body> -<table cellpadding="1" cellspacing="1" border="1"> - <tbody> - <tr> - <td>open</td> - <td>/sessions/logout</td> - <td></td> - </tr> - <tr> - <td>waitForText</td> - <td>global-navigation</td> - <td>*Log in*</td> - </tr> - <tr> - <td>open</td> - <td>/projects?gate=OK&reliability=1&security=1</td> - <td></td> - </tr> - <tr> - <td>waitForText</td> - <td>global-navigation</td> - <td>*Log in*</td> - </tr> - <tr> - <td>click</td> - <td>link=Log in</td> - <td></td> - </tr> - <tr> - <td>waitForText</td> - <td>content</td> - <td>*Log In to SonarQube*</td> - </tr> - <tr> - <td>type</td> - <td>login</td> - <td>admin-user</td> - </tr> - <tr> - <td>type</td> - <td>password</td> - <td>admin-user</td> - </tr> - <tr> - <td>clickAndWait</td> - <td>[type=submit]</td> - <td></td> - </tr> - <tr> - <td>waitForElementPresent</td> - <td>css=.js-user-authenticated</td> - <td></td> - </tr> - <tr> - <td>assertLocation</td> - <td>*/projects?gate=OK&reliability=1&security=1</td> - <td></td> - </tr> - </tbody> -</table> -</body> -</html> |