diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-11-10 14:13:18 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-11-14 12:18:51 +0100 |
commit | fc8fa7830f47874a67f3a13b333d24a9ceafe856 (patch) | |
tree | 8ccfefc6eed59455f416a61f36315ca00e66b09c /server | |
parent | feda9c29f81ed7a1628afb9fbb5e47824f2f0c35 (diff) | |
download | sonarqube-fc8fa7830f47874a67f3a13b333d24a9ceafe856.tar.gz sonarqube-fc8fa7830f47874a67f3a13b333d24a9ceafe856.zip |
SONAR-8351 limit number of webhooks to 10
Diffstat (limited to 'server')
2 files changed, 30 insertions, 0 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookPostTask.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookPostTask.java index 81406a23203..58cc31e4203 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookPostTask.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookPostTask.java @@ -33,6 +33,7 @@ import org.sonar.server.computation.task.projectanalysis.component.SettingsRepos import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolder; import static java.lang.String.format; +import static org.sonar.core.config.WebhookProperties.MAX_WEBHOOKS_PER_TYPE; public class WebhookPostTask implements PostProjectAnalysisTask { @@ -68,6 +69,7 @@ public class WebhookPostTask implements PostProjectAnalysisTask { String[] webhookIds = settings.getStringArray(propertyKey); return Arrays.stream(webhookIds) .map(webhookId -> format("%s.%s", propertyKey, webhookId)) + .limit(MAX_WEBHOOKS_PER_TYPE) .collect(Collectors.toList(webhookIds.length)); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookPostTaskTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookPostTaskTest.java index dcdfbc8a4eb..e9c0e6eda84 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookPostTaskTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/webhook/WebhookPostTaskTest.java @@ -21,6 +21,8 @@ package org.sonar.server.computation.task.projectanalysis.webhook; import java.io.IOException; import java.util.Date; +import java.util.stream.Collectors; +import java.util.stream.IntStream; import org.junit.Rule; import org.junit.Test; import org.sonar.api.ce.posttask.CeTask; @@ -85,6 +87,7 @@ public class WebhookPostTaskTest { verify(deliveryStorage, times(2)).persist(any(WebhookDelivery.class)); verify(deliveryStorage).purge(PROJECT_UUID); } + @Test public void send_project_webhooks() { settings.setProperty("sonar.webhooks.project", "1"); @@ -100,6 +103,31 @@ public class WebhookPostTaskTest { verify(deliveryStorage).purge(PROJECT_UUID); } + @Test + public void process_only_the_10_first_global_webhooks() { + testMaxWebhooks("sonar.webhooks.global"); + } + + @Test + public void process_only_the_10_first_project_webhooks() { + testMaxWebhooks("sonar.webhooks.project"); + } + + private void testMaxWebhooks(String property) { + IntStream.range(1, 15) + .forEach(i -> { + settings.setProperty(property + "." + i + ".name", "First"); + settings.setProperty(property + "." + i + ".url", "http://url"); + caller.enqueueSuccess(NOW, 200, 1_234); + }); + settings.setProperty(property, IntStream.range(1, 15).mapToObj(String::valueOf).collect(Collectors.joining(","))); + + execute(); + + assertThat(caller.countSent()).isEqualTo(10); + assertThat(logTester.logs(LoggerLevel.DEBUG).stream().filter(log -> log.contains("Sent"))).hasSize(10); + } + private void execute() { SettingsRepository settingsRepository = new TestSettingsRepository(settings); WebhookPostTask task = new WebhookPostTask(rootHolder, settingsRepository, caller, deliveryStorage); |