aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server-common/src
diff options
context:
space:
mode:
authorLéo Geoffroy <leo.geoffroy@sonarsource.com>2022-03-30 12:16:19 +0200
committersonartech <sonartech@sonarsource.com>2022-04-01 08:22:58 +0000
commit965034a2fb6d40d52761187f0442d81dc047c3a1 (patch)
tree97b0493ea007b6bae7ef85f49fd0218758a0b710 /server/sonar-server-common/src
parent113b243ab6a13143fafa5dc528d7ffb2c7db8df3 (diff)
downloadsonarqube-965034a2fb6d40d52761187f0442d81dc047c3a1.tar.gz
sonarqube-965034a2fb6d40d52761187f0442d81dc047c3a1.zip
SONAR-12499 - Increase the size of security standard facets returned in issue search
Diffstat (limited to 'server/sonar-server-common/src')
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndex.java3
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java25
2 files changed, 27 insertions, 1 deletions
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndex.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndex.java
index 0c2e260eeae..f4df56d0a84 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndex.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndex.java
@@ -63,6 +63,7 @@ import org.sonar.server.es.SearchOptions;
import org.sonar.server.es.StickyFacetBuilder;
import org.sonar.server.es.newindex.DefaultIndexSettings;
import org.sonar.server.es.textsearch.JavaTokenizer;
+import org.sonar.server.security.SecurityStandards;
import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.Boolean.FALSE;
@@ -506,7 +507,7 @@ public class RuleIndex {
Collection<String> categories = query.getSonarsourceSecurity();
aggregations.put(FACET_SONARSOURCE_SECURITY,
stickyFacetBuilder.buildStickyFacet(FIELD_RULE_SONARSOURCE_SECURITY, FACET_SONARSOURCE_SECURITY,
- FACET_DEFAULT_SIZE, filterSecurityCategories(),
+ SecurityStandards.SQCategory.values().length, filterSecurityCategories(),
(categories == null) ? (new String[0]) : categories.toArray()));
}
}
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java
index 8f367c1069d..9ca8078f54f 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java
@@ -21,10 +21,15 @@ package org.sonar.server.rule.index;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Sets;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import org.assertj.core.api.Assertions;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.impl.utils.AlwaysIncreasingSystem2;
@@ -40,6 +45,7 @@ import org.sonar.server.es.Facets;
import org.sonar.server.es.SearchIdResult;
import org.sonar.server.es.SearchOptions;
import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
+import org.sonar.server.security.SecurityStandards;
import static com.google.common.collect.ImmutableSet.of;
import static java.util.Arrays.asList;
@@ -506,6 +512,25 @@ public class RuleIndexTest {
}
@Test
+ public void search_by_security_sonarsource_return_complete_list_of_facets() {
+
+ List<RuleDefinitionDto> rules = new ArrayList<>();
+
+ //Creation of one rule for each standard security category defined (except other)
+ for (Map.Entry<SecurityStandards.SQCategory, Set<String>> sqCategorySetEntry : SecurityStandards.CWES_BY_SQ_CATEGORY.entrySet()) {
+ rules.add(createRule(setSecurityStandards(of("cwe:" + sqCategorySetEntry.getValue().iterator().next())), r -> r.setType(SECURITY_HOTSPOT)));
+ }
+ index();
+
+ RuleQuery query = new RuleQuery();
+ SearchIdResult<String> results = underTest.search(query, new SearchOptions().addFacets("sonarsourceSecurity"));
+
+ assertThat(results.getFacets().get("sonarsourceSecurity"))
+ .as("It should have as many facets returned as there are rules defined, and it is not truncated")
+ .hasSize(rules.size());
+ }
+
+ @Test
public void compare_to_another_profile() {
String xoo = "xoo";
QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(xoo));