]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-22516 Fix BBT using email configuration
authorAntoine Vigneau <antoine.vigneau@sonarsource.com>
Sun, 11 Aug 2024 21:14:17 +0000 (23:14 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 16 Aug 2024 20:02:59 +0000 (20:02 +0000)
server/sonar-server-common/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java
server/sonar-server-common/src/test/java/org/sonar/server/notification/email/EmailNotificationChannelTest.java
server/sonar-webserver-common/src/it/java/org/sonar/server/common/email/config/EmailConfigurationBuilder.java
sonar-ws/src/main/java/org/sonarqube/ws/client/DefaultWsClient.java
sonar-ws/src/main/java/org/sonarqube/ws/client/WsClient.java

index 9948abe4f1d94aa37df453f054c4fa3cb8f8086d..f4005480631c3e2063c4df65503a512531390d72 100644 (file)
@@ -321,7 +321,7 @@ public class EmailNotificationChannel extends NotificationChannel {
   }
 
   private void configureSecureConnection(Email email) {
-    if (StringUtils.equalsIgnoreCase(configuration.getSecureConnection(), "ssl")) {
+    if (StringUtils.equalsIgnoreCase(configuration.getSecureConnection(), "SSLTLS")) {
       email.setSSLOnConnect(true);
       email.setSSLCheckServerIdentity(true);
       email.setSslSmtpPort(String.valueOf(configuration.getSmtpPort()));
@@ -329,12 +329,12 @@ public class EmailNotificationChannel extends NotificationChannel {
       // this port is not used except in EmailException message, that's why it's set with the same value than SSL port.
       // It prevents from getting bad message.
       email.setSmtpPort(configuration.getSmtpPort());
-    } else if (StringUtils.equalsIgnoreCase(configuration.getSecureConnection(), "starttls")) {
+    } else if (StringUtils.equalsIgnoreCase(configuration.getSecureConnection(), "STARTTLS")) {
       email.setStartTLSEnabled(true);
       email.setStartTLSRequired(true);
       email.setSSLCheckServerIdentity(true);
       email.setSmtpPort(configuration.getSmtpPort());
-    } else if (StringUtils.isBlank(configuration.getSecureConnection())) {
+    } else if (StringUtils.equalsIgnoreCase(configuration.getSecureConnection(), "NONE")) {
       email.setSmtpPort(configuration.getSmtpPort());
     } else {
       throw new SonarException("Unknown type of SMTP secure connection: " + configuration.getSecureConnection());
index bd524e9e6a2f477102d4bab2dce7287faeb086c9..efff8f1b796b93c00e13ed96f3043b1b029d806f 100644 (file)
@@ -378,6 +378,7 @@ public class EmailNotificationChannelTest {
   private void configure() {
     when(configuration.getSmtpHost()).thenReturn("localhost");
     when(configuration.getSmtpPort()).thenReturn(smtpServer.getServer().getPort());
+    when(configuration.getSecureConnection()).thenReturn("NONE");
     when(configuration.getFrom()).thenReturn("server@nowhere");
     when(configuration.getFromName()).thenReturn("SonarQube from NoWhere");
     when(configuration.getPrefix()).thenReturn(SUBJECT_PREFIX);
index ae619646223af6a9615e85ac2add83824e084f9b..f94ce83e7c610f1e2441450da29ba59f795e9fc8 100644 (file)
@@ -35,13 +35,13 @@ public final class EmailConfigurationBuilder {
   private String oauthClientSecret;
   private String oauthTenant;
 
-  private EmailConfigurationBuilder() {
-  }
-
   public static EmailConfigurationBuilder builder() {
     return new EmailConfigurationBuilder();
   }
 
+  private EmailConfigurationBuilder() {
+  }
+
   public EmailConfigurationBuilder id(String id) {
     this.id = id;
     return this;
index 4f7ea365c7b7e2556eda468b1aec885edfbc1019..257e36b2ed018d7c2e290fb808df24ac002328c3 100644 (file)
@@ -32,6 +32,7 @@ import org.sonarqube.ws.client.components.ComponentsService;
 import org.sonarqube.ws.client.developers.DevelopersService;
 import org.sonarqube.ws.client.duplications.DuplicationsService;
 import org.sonarqube.ws.client.editions.EditionsService;
+import org.sonarqube.ws.client.emails.EmailConfigurationService;
 import org.sonarqube.ws.client.emails.EmailsService;
 import org.sonarqube.ws.client.favorites.FavoritesService;
 import org.sonarqube.ws.client.github.configuration.GithubConfigurationService;
@@ -101,6 +102,7 @@ class DefaultWsClient implements WsClient {
   private final DevelopersService developersService;
   private final DuplicationsService duplicationsService;
   private final EditionsService editionsService;
+  private final EmailConfigurationService emailConfigurationService;
   private final EmailsService emailsService;
   private final FavoritesService favoritesService;
   private final GovernanceReportsService governanceReportsService;
@@ -164,6 +166,7 @@ class DefaultWsClient implements WsClient {
     this.developersService = new DevelopersService(wsConnector);
     this.duplicationsService = new DuplicationsService(wsConnector);
     this.editionsService = new EditionsService(wsConnector);
+    this.emailConfigurationService = new EmailConfigurationService(wsConnector);
     this.emailsService = new EmailsService(wsConnector);
     this.favoritesService = new FavoritesService(wsConnector);
     this.governanceReportsService = new GovernanceReportsService(wsConnector);
@@ -279,6 +282,11 @@ class DefaultWsClient implements WsClient {
     return editionsService;
   }
 
+  @Override
+  public EmailConfigurationService emailConfiguration() {
+    return emailConfigurationService;
+  }
+
   @Override
   public EmailsService emails() {
     return emailsService;
index 53cd28e86abc9dd36c9f9b2f73598d2333eb9866..64117e79d9fd2e543869e82a82b4ac4fb5769530 100644 (file)
@@ -32,6 +32,7 @@ import org.sonarqube.ws.client.components.ComponentsService;
 import org.sonarqube.ws.client.developers.DevelopersService;
 import org.sonarqube.ws.client.duplications.DuplicationsService;
 import org.sonarqube.ws.client.editions.EditionsService;
+import org.sonarqube.ws.client.emails.EmailConfigurationService;
 import org.sonarqube.ws.client.emails.EmailsService;
 import org.sonarqube.ws.client.favorites.FavoritesService;
 import org.sonarqube.ws.client.github.configuration.GithubConfigurationService;
@@ -124,6 +125,8 @@ public interface WsClient {
 
   EditionsService editions();
 
+  EmailConfigurationService emailConfiguration();
+
   EmailsService emails();
 
   FavoritesService favorites();