From: Jacek Date: Wed, 30 Mar 2022 09:15:17 +0000 (+0200) Subject: SONAR-16179 Fix SSF-240 X-Git-Tag: 9.4.0.54424~28 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d2c8f6d5606578ab9939732afd73d7c5f06bf247;p=sonarqube.git SONAR-16179 Fix SSF-240 --- diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/email/ws/SendAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/email/ws/SendAction.java index 4f7a8b308d7..3c4a05d3c19 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/email/ws/SendAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/email/ws/SendAction.java @@ -19,10 +19,6 @@ */ package org.sonar.server.email.ws; -import com.google.common.base.Throwables; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; import org.apache.commons.mail.EmailException; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; @@ -32,7 +28,6 @@ import org.sonar.server.notification.email.EmailNotificationChannel; import org.sonar.server.user.UserSession; public class SendAction implements EmailsWsAction { - private static final String PARAM_TO = "to"; private static final String PARAM_SUBJECT = "subject"; private static final String PARAM_MESSAGE = "message"; @@ -75,18 +70,9 @@ public class SendAction implements EmailsWsAction { try { emailNotificationChannel.sendTestEmail(request.mandatoryParam(PARAM_TO), request.param(PARAM_SUBJECT), request.mandatoryParam(PARAM_MESSAGE)); } catch (EmailException emailException) { - throw createBadRequestException(emailException); + throw BadRequestException.create("Configuration invalid: please double check SMTP host, port, login and password."); } response.noContent(); } - private static BadRequestException createBadRequestException(EmailException emailException) { - List messages = Throwables.getCausalChain(emailException) - .stream() - .map(Throwable::getMessage) - .collect(Collectors.toList()); - Collections.reverse(messages); - return BadRequestException.create(messages); - } - } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/email/ws/SendActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/email/ws/SendActionTest.java index efde74dfadf..ced18781eb9 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/email/ws/SendActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/email/ws/SendActionTest.java @@ -41,13 +41,12 @@ import static org.mockito.Mockito.verify; public class SendActionTest { - @Rule - public UserSessionRule userSession = UserSessionRule.standalone(); + public final UserSessionRule userSession = UserSessionRule.standalone(); - private EmailNotificationChannel emailNotificationChannel = mock(EmailNotificationChannel.class); + private final EmailNotificationChannel emailNotificationChannel = mock(EmailNotificationChannel.class); - private WsActionTester ws = new WsActionTester(new SendAction(userSession, emailNotificationChannel)); + private final WsActionTester ws = new WsActionTester(new SendAction(userSession, emailNotificationChannel)); @Test public void send_test_email() throws Exception { @@ -91,7 +90,8 @@ public class SendActionTest { public void throw_ForbiddenException_if_not_system_administrator() { userSession.logIn().setNonSystemAdministrator(); - assertThatThrownBy(() -> ws.newRequest().execute()) + var request = ws.newRequest(); + assertThatThrownBy(request::execute) .isInstanceOf(ForbiddenException.class) .hasMessage("Insufficient privileges"); } @@ -109,8 +109,7 @@ public class SendActionTest { executeRequest("john@doo.com", "Test Message from SonarQube", "This is a test message from SonarQube at http://localhost:9000"); fail(); } catch (BadRequestException e) { - assertThat(e.errors()).containsExactly( - "root cause", "parent cause", "child cause", "last message"); + assertThat(e.errors()).containsExactly("Configuration invalid: please double check SMTP host, port, login and password."); } }