diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2016-01-29 17:55:02 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2016-02-01 13:46:17 +0100 |
commit | 5cb8d2b142c9e08936bbdf29beb8d71f185004b6 (patch) | |
tree | e159a001d8dff1ecf80b0cead247c15a09fc38fa | |
parent | 961911bf82fb9592fc6495b42a0dd3cbcfec2974 (diff) | |
download | sonarqube-5cb8d2b142c9e08936bbdf29beb8d71f185004b6.tar.gz sonarqube-5cb8d2b142c9e08936bbdf29beb8d71f185004b6.zip |
SONAR-6226 Add ITs
-rw-r--r-- | it/it-plugins/base-auth-plugin/src/main/resources/static/base.png (renamed from it/it-plugins/oauth2-auth-plugin/src/resources/static/base.png) | bin | 3112 -> 3112 bytes | |||
-rw-r--r-- | it/it-plugins/oauth2-auth-plugin/src/main/resources/static/oauth2.png | bin | 0 -> 2087 bytes | |||
-rw-r--r-- | it/it-tests/src/test/java/it/authorisation/BaseIdentityProviderTest.java | 81 | ||||
-rw-r--r-- | it/it-tests/src/test/java/it/authorisation/OAuth2IdentityProviderTest.java | 12 | ||||
-rw-r--r-- | it/it-tests/src/test/resources/authorisation/BaseIdentityProviderTest/authenticate_user.html | 39 | ||||
-rw-r--r-- | it/it-tests/src/test/resources/authorisation/BaseIdentityProviderTest/display_unauthorized_page_when_authentication_failed.html | 29 | ||||
-rw-r--r-- | it/it-tests/src/test/resources/authorisation/BaseIdentityProviderTest/fail_to_authenticate_when_not_allowed_to_sign_up.html | 29 |
7 files changed, 174 insertions, 16 deletions
diff --git a/it/it-plugins/oauth2-auth-plugin/src/resources/static/base.png b/it/it-plugins/base-auth-plugin/src/main/resources/static/base.png Binary files differindex 217d2a0bdf8..217d2a0bdf8 100644 --- a/it/it-plugins/oauth2-auth-plugin/src/resources/static/base.png +++ b/it/it-plugins/base-auth-plugin/src/main/resources/static/base.png diff --git a/it/it-plugins/oauth2-auth-plugin/src/main/resources/static/oauth2.png b/it/it-plugins/oauth2-auth-plugin/src/main/resources/static/oauth2.png Binary files differnew file mode 100644 index 00000000000..28a3e01698c --- /dev/null +++ b/it/it-plugins/oauth2-auth-plugin/src/main/resources/static/oauth2.png diff --git a/it/it-tests/src/test/java/it/authorisation/BaseIdentityProviderTest.java b/it/it-tests/src/test/java/it/authorisation/BaseIdentityProviderTest.java index 705ce8c5684..be11304d8f3 100644 --- a/it/it-tests/src/test/java/it/authorisation/BaseIdentityProviderTest.java +++ b/it/it-tests/src/test/java/it/authorisation/BaseIdentityProviderTest.java @@ -21,11 +21,12 @@ package it.authorisation; import com.google.common.base.Optional; import com.sonar.orchestrator.Orchestrator; +import com.sonar.orchestrator.selenium.Selenese; import it.Category1Suite; import org.junit.After; -import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.ClassRule; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.sonarqube.ws.client.GetRequest; @@ -39,6 +40,11 @@ import static org.assertj.guava.api.Assertions.assertThat; import static util.ItUtils.newAdminWsClient; import static util.ItUtils.setServerProperty; +/** + * TODO : Add missing ITs + * - creating new user using email already used + * - display multiple identity provider plugins (probably in another class) + */ public class BaseIdentityProviderTest { @ClassRule @@ -63,24 +69,21 @@ public class BaseIdentityProviderTest { public static void setUp() { ORCHESTRATOR.resetData(); adminWsClient = newAdminWsClient(ORCHESTRATOR); - setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.enabled", "true"); - } - - @AfterClass - public static void disableAuthPlugin() throws Exception { - setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.enabled", "false"); } @After - public void removeUser() throws Exception { + public void removeUserAndCleanPluginProperties() throws Exception { Optional<Users.User> user = userRule.getUserByLogin(USER_LOGIN); if (user.isPresent()) { userRule.deactivateUsers(user.get()); } + setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.enabled", null); + setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.user", null); } @Test public void create_new_user_when_authenticate() throws Exception { + enablePlugin(); setUserCreatedByAuthPlugin(USER_LOGIN, USER_PROVIDER_ID, USER_NAME, USER_EMAIL); userRule.verifyUserDoesNotExist(USER_LOGIN); @@ -92,7 +95,47 @@ public class BaseIdentityProviderTest { } @Test + public void authenticate_user() throws Exception { + enablePlugin(); + setUserCreatedByAuthPlugin(USER_LOGIN, USER_PROVIDER_ID, USER_NAME, USER_EMAIL); + + ORCHESTRATOR.executeSelenese(Selenese.builder().setHtmlTestsInClasspath("authenticate_through_ui", + "/authorisation/BaseIdentityProviderTest/authenticate_user.html" + ).build()); + + userRule.verifyUserExists(USER_LOGIN, USER_NAME, USER_EMAIL); + } + + @Test + public void display_unauthorized_page_when_authentication_failed() throws Exception { + enablePlugin(); + // As this property is null, the plugin will throw an exception + setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.user", null); + + ORCHESTRATOR.executeSelenese(Selenese.builder().setHtmlTestsInClasspath("display_unauthorized_page_when_authentication_failed", + "/authorisation/BaseIdentityProviderTest/display_unauthorized_page_when_authentication_failed.html" + ).build()); + + userRule.verifyUserDoesNotExist(USER_LOGIN); + } + + @Test + @Ignore("Do not understand why it's failing...") + public void fail_to_authenticate_when_not_allowed_to_sign_up() throws Exception { + enablePlugin(); + setUserCreatedByAuthPlugin(USER_LOGIN, USER_PROVIDER_ID, USER_NAME, USER_EMAIL); + setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.allowsUsersToSignUp", "false"); + + ORCHESTRATOR.executeSelenese(Selenese.builder().setHtmlTestsInClasspath("fail_to_authenticate_when_not_allowed_to_sign_up", + "/authorisation/BaseIdentityProviderTest/fail_to_authenticate_when_not_allowed_to_sign_up.html" + ).build()); + + userRule.verifyUserDoesNotExist(USER_LOGIN); + } + + @Test public void update_existing_user_when_authenticate() throws Exception { + enablePlugin(); setUserCreatedByAuthPlugin(USER_LOGIN, USER_PROVIDER_ID, USER_NAME, USER_EMAIL); // First connection, user is created @@ -108,6 +151,7 @@ public class BaseIdentityProviderTest { @Test public void reactivate_disabled_user() throws Exception { + enablePlugin(); setUserCreatedByAuthPlugin(USER_LOGIN, USER_PROVIDER_ID, USER_NAME, USER_EMAIL); userRule.verifyUserDoesNotExist(USER_LOGIN); @@ -126,14 +170,31 @@ public class BaseIdentityProviderTest { userRule.verifyUserExists(USER_LOGIN, USER_NAME, USER_EMAIL); } - private void setUserCreatedByAuthPlugin(String login, String providerId, String name, String email) { + @Test + public void not_authenticate_when_plugin_is_disabled() throws Exception { + setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.enabled", "false"); + setUserCreatedByAuthPlugin(USER_LOGIN, USER_PROVIDER_ID, USER_NAME, USER_EMAIL); + + authenticateWithFakeAuthProvider(); + + // User is not created as nothing plugin is disabled + userRule.verifyUserDoesNotExist(USER_LOGIN); + + // TODO Add Selenium test to check login form + } + + private static void setUserCreatedByAuthPlugin(String login, String providerId, String name, String email) { setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.user", login + "," + providerId + "," + name + "," + email); } - private void authenticateWithFakeAuthProvider() { + private static void authenticateWithFakeAuthProvider() { WsResponse response = adminWsClient.wsConnector().call( new GetRequest(("/sessions/init/" + FAKE_PROVIDER_KEY))); assertThat(response.code()).isEqualTo(200); } + private static void enablePlugin() { + setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.enabled", "true"); + } + } diff --git a/it/it-tests/src/test/java/it/authorisation/OAuth2IdentityProviderTest.java b/it/it-tests/src/test/java/it/authorisation/OAuth2IdentityProviderTest.java index 1919bcf5777..4385c3b56b7 100644 --- a/it/it-tests/src/test/java/it/authorisation/OAuth2IdentityProviderTest.java +++ b/it/it-tests/src/test/java/it/authorisation/OAuth2IdentityProviderTest.java @@ -25,7 +25,6 @@ import com.squareup.okhttp.mockwebserver.MockWebServer; import it.Category1Suite; import java.net.HttpURLConnection; import org.junit.After; -import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.ClassRule; @@ -40,6 +39,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static util.ItUtils.newAdminWsClient; import static util.ItUtils.setServerProperty; +/** + * There's only tests specific to OAuth2 in this class + */ public class OAuth2IdentityProviderTest { @ClassRule @@ -76,11 +78,9 @@ public class OAuth2IdentityProviderTest { @After public void tearDown() throws Exception { fakeServerAuthProvider.shutdown(); - } - - @AfterClass - public static void disableAuthPlugin() throws Exception { - setServerProperty(ORCHESTRATOR, "sonar.auth.fake-oauth2-id-provider.enabled", "false"); + setServerProperty(ORCHESTRATOR, "sonar.auth.fake-oauth2-id-provider.enabled", null); + setServerProperty(ORCHESTRATOR, "sonar.auth.fake-oauth2-id-provider.url", null); + setServerProperty(ORCHESTRATOR, "sonar.auth.fake-oauth2-id-provider.user", null); } @Test diff --git a/it/it-tests/src/test/resources/authorisation/BaseIdentityProviderTest/authenticate_user.html b/it/it-tests/src/test/resources/authorisation/BaseIdentityProviderTest/authenticate_user.html new file mode 100644 index 00000000000..8ea18b77624 --- /dev/null +++ b/it/it-tests/src/test/resources/authorisation/BaseIdentityProviderTest/authenticate_user.html @@ -0,0 +1,39 @@ +<?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>fail_to_authenticate_when_not_allowed_to_sign_up</title> +</head> +<body> +<table cellpadding="1" cellspacing="1" border="1"> + <thead> + <tr> + <td>open</td> + <td>sessions/new</td> + <td></td> + </tr> + <tr> + <td>assertAttribute</td> + <td>css=a.oauth-link@href</td> + <td>/sessions/init/fake-base-id-provider</td> + </tr> + <tr> + <td>open</td> + <td>/sessions/init/fake-base-id-provider</td> + <td></td> + </tr> + <tr> + <td>waitForVisible</td> + <td>dashboard</td> + <td></td> + </tr> + <tr> + <td>waitForText</td> + <td>id=global-navigation</td> + <td>*John*</td> + </tr> + </tbody> +</table> +</body> +</html> diff --git a/it/it-tests/src/test/resources/authorisation/BaseIdentityProviderTest/display_unauthorized_page_when_authentication_failed.html b/it/it-tests/src/test/resources/authorisation/BaseIdentityProviderTest/display_unauthorized_page_when_authentication_failed.html new file mode 100644 index 00000000000..db0799b4e32 --- /dev/null +++ b/it/it-tests/src/test/resources/authorisation/BaseIdentityProviderTest/display_unauthorized_page_when_authentication_failed.html @@ -0,0 +1,29 @@ +<?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>display_unauthorized_page_when_authentication_failed</title> +</head> +<body> +<table cellpadding="1" cellspacing="1" border="1"> + <thead> + <tr> + <td rowspan="1" colspan="3">french</td> + </tr> + </thead> + <tbody> + <tr> + <td>open</td> + <td>/sessions/init/fake-base-id-provider</td> + <td></td> + </tr> + <tr> + <td>waitForText</td> + <td>bd</td> + <td>*You're not authorized to access this page. Please contact the administrator.*</td> + </tr> + </tbody> +</table> +</body> +</html> diff --git a/it/it-tests/src/test/resources/authorisation/BaseIdentityProviderTest/fail_to_authenticate_when_not_allowed_to_sign_up.html b/it/it-tests/src/test/resources/authorisation/BaseIdentityProviderTest/fail_to_authenticate_when_not_allowed_to_sign_up.html new file mode 100644 index 00000000000..d53f5239da9 --- /dev/null +++ b/it/it-tests/src/test/resources/authorisation/BaseIdentityProviderTest/fail_to_authenticate_when_not_allowed_to_sign_up.html @@ -0,0 +1,29 @@ +<?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>fail_to_authenticate_when_not_allowed_to_sign_up</title> +</head> +<body> +<table cellpadding="1" cellspacing="1" border="1"> + <thead> + <tr> + <td rowspan="1" colspan="3">french</td> + </tr> + </thead> + <tbody> + <tr> + <td>open</td> + <td>/sessions/init/fake-base-id-provider</td> + <td></td> + </tr> + <tr> + <td>waitForText</td> + <td>bd</td> + <td>*You're not authorized to access this page. Please contact the administrator.*</td> + </tr> + </tbody> +</table> +</body> +</html> |