diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2016-03-14 11:54:57 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2016-03-16 11:06:14 +0100 |
commit | ab9805fd7b22aa2c488d59d38d8f0cf707e7763d (patch) | |
tree | 31538745192817c6c7f61a0c6c82f4d5698d8225 /it | |
parent | f29df5da27030596d7d3ef07b4e833bb664cb940 (diff) | |
download | sonarqube-ab9805fd7b22aa2c488d59d38d8f0cf707e7763d.tar.gz sonarqube-ab9805fd7b22aa2c488d59d38d8f0cf707e7763d.zip |
SONAR-7444 Provide an UnauthorizedException to display functional error
Diffstat (limited to 'it')
3 files changed, 56 insertions, 2 deletions
diff --git a/it/it-plugins/base-auth-plugin/src/main/java/FakeBaseIdProvider.java b/it/it-plugins/base-auth-plugin/src/main/java/FakeBaseIdProvider.java index 730bef971e1..a7d897b137f 100644 --- a/it/it-plugins/base-auth-plugin/src/main/java/FakeBaseIdProvider.java +++ b/it/it-plugins/base-auth-plugin/src/main/java/FakeBaseIdProvider.java @@ -21,6 +21,7 @@ import java.io.IOException; import org.sonar.api.config.Settings; import org.sonar.api.server.authentication.BaseIdentityProvider; import org.sonar.api.server.authentication.Display; +import org.sonar.api.server.authentication.UnauthorizedException; import org.sonar.api.server.authentication.UserIdentity; public class FakeBaseIdProvider implements BaseIdentityProvider { @@ -29,6 +30,8 @@ public class FakeBaseIdProvider implements BaseIdentityProvider { private static final String ALLOWS_USERS_TO_SIGN_UP = "sonar.auth.fake-base-id-provider.allowsUsersToSignUp"; private static final String USER_INFO = "sonar.auth.fake-base-id-provider.user"; + private static final String THROW_UNAUTHORIZED_EXCEPTION = "sonar.auth.fake-base-id-provider.throwUnauthorizedMessage"; + private final Settings settings; public FakeBaseIdProvider(Settings settings) { @@ -41,6 +44,11 @@ public class FakeBaseIdProvider implements BaseIdentityProvider { if (userInfoProperty == null) { throw new IllegalStateException(String.format("The property %s is required", USER_INFO)); } + boolean throwUnauthorizedException = settings.getBoolean(THROW_UNAUTHORIZED_EXCEPTION); + if (throwUnauthorizedException) { + throw new UnauthorizedException("A functional error has happened"); + } + String[] userInfos = userInfoProperty.split(","); context.authenticate(UserIdentity.builder() .setLogin(userInfos[0]) diff --git a/it/it-tests/src/test/java/it/user/BaseIdentityProviderTest.java b/it/it-tests/src/test/java/it/user/BaseIdentityProviderTest.java index 242d78caf7d..eda3d581f12 100644 --- a/it/it-tests/src/test/java/it/user/BaseIdentityProviderTest.java +++ b/it/it-tests/src/test/java/it/user/BaseIdentityProviderTest.java @@ -23,10 +23,11 @@ import com.google.common.base.Optional; import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.selenium.Selenese; import it.Category4Suite; +import java.io.File; +import org.apache.commons.io.FileUtils; import org.junit.After; import org.junit.BeforeClass; import org.junit.ClassRule; -import org.junit.Ignore; import org.junit.Test; import org.junit.experimental.categories.Category; import org.sonarqube.ws.client.GetRequest; @@ -119,7 +120,6 @@ public class BaseIdentityProviderTest { } @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); @@ -182,6 +182,23 @@ public class BaseIdentityProviderTest { // TODO Add Selenium test to check login form } + @Test + public void display_message_in_ui_but_not_in_log_when_unauthorized_exception() throws Exception { + enablePlugin(); + setUserCreatedByAuthPlugin(USER_LOGIN, USER_PROVIDER_ID, USER_NAME, USER_EMAIL); + setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.throwUnauthorizedMessage", "true"); + + ORCHESTRATOR.executeSelenese(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()); + + File logFile = ORCHESTRATOR.getServer().getLogs(); + assertThat(FileUtils.readFileToString(logFile)).doesNotContain("A functional error has happened"); + assertThat(FileUtils.readFileToString(logFile)).doesNotContain("UnauthorizedException"); + + userRule.verifyUserDoesNotExist(USER_LOGIN); + } + 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); } diff --git a/it/it-tests/src/test/resources/user/BaseIdentityProviderTest/diplay_message_in_ui_but_not_in_log_when_unauthorized_exception.html b/it/it-tests/src/test/resources/user/BaseIdentityProviderTest/diplay_message_in_ui_but_not_in_log_when_unauthorized_exception.html new file mode 100644 index 00000000000..4d06368ae6c --- /dev/null +++ b/it/it-tests/src/test/resources/user/BaseIdentityProviderTest/diplay_message_in_ui_but_not_in_log_when_unauthorized_exception.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.*Reason : A functional error has happened*</td> + </tr> + </tbody> +</table> +</body> +</html> |