use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class RuleIndexerTest method log_debug_when_hotspot_rule_description_has_none_of_the_key_titles.
@Test
public void log_debug_when_hotspot_rule_description_has_none_of_the_key_titles() {
RuleDefinitionDto rule = dbTester.rules().insert(RuleTesting.newRule().setType(RuleType.SECURITY_HOTSPOT).setDescription(randomAlphabetic(30)));
underTest.commitAndIndex(dbTester.getSession(), rule.getUuid());
assertThat(logTester.getLogs()).hasSize(1);
assertThat(logTester.logs(LoggerLevel.DEBUG).get(0)).isEqualTo(format("Description of Security Hotspot Rule %s can't be fully parsed: What is the risk?=ok, Are you vulnerable?=missing, How to fix it=missing", rule.getKey()));
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class RuleIndexerTest method log_debug_when_hotspot_rule_description_is_missing_fixIt_tab_content.
@Test
public void log_debug_when_hotspot_rule_description_is_missing_fixIt_tab_content() {
RuleDefinitionDto rule = dbTester.rules().insert(RuleTesting.newRule().setType(RuleType.SECURITY_HOTSPOT).setDescription("bar\n" + "<h2>Ask Yourself Whether</h2>\n" + "foo"));
underTest.commitAndIndex(dbTester.getSession(), rule.getUuid());
assertThat(logTester.getLogs()).hasSize(1);
assertThat(logTester.logs(LoggerLevel.DEBUG).get(0)).isEqualTo(format("Description of Security Hotspot Rule %s can't be fully parsed: What is the risk?=ok, Are you vulnerable?=ok, How to fix it=missing", rule.getKey()));
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class RuleIndexerTest method log_debug_if_hotspot_rule_maps_to_multiple_SQCategories.
@Test
@UseDataProvider("twoDifferentCategoriesButOTHERS")
public void log_debug_if_hotspot_rule_maps_to_multiple_SQCategories(SQCategory sqCategory1, SQCategory sqCategory2) {
Set<String> standards = Stream.of(sqCategory1, sqCategory2).flatMap(t -> CWES_BY_SQ_CATEGORY.get(t).stream().map(e -> "cwe:" + e)).collect(toSet());
SecurityStandards securityStandards = SecurityStandards.fromSecurityStandards(standards);
RuleDefinitionDto rule = dbTester.rules().insert(RuleTesting.newRule().setType(RuleType.SECURITY_HOTSPOT).setSecurityStandards(standards).setDescription(VALID_HOTSPOT_RULE_DESCRIPTION));
underTest.commitAndIndex(dbTester.getSession(), rule.getUuid());
assertThat(logTester.getLogs()).hasSize(1);
assertThat(logTester.logs(LoggerLevel.DEBUG).get(0)).isEqualTo(format("Rule %s with CWEs '%s' maps to multiple SQ Security Categories: %s", rule.getKey(), String.join(", ", securityStandards.getCwe()), ImmutableSet.of(sqCategory1, sqCategory2).stream().map(SQCategory::getKey).sorted(SQ_CATEGORY_KEYS_ORDERING).collect(joining(", "))));
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class RuleIndexerTest method log_debug_when_hotspot_rule_description_is_missing_risk_tab_content.
@Test
public void log_debug_when_hotspot_rule_description_is_missing_risk_tab_content() {
RuleDefinitionDto rule = dbTester.rules().insert(RuleTesting.newRule().setType(RuleType.SECURITY_HOTSPOT).setDescription("<h2>Ask Yourself Whether</h2>\n" + "bar\n" + "<h2>Recommended Secure Coding Practices</h2>\n" + "foo"));
underTest.commitAndIndex(dbTester.getSession(), rule.getUuid());
assertThat(logTester.getLogs()).hasSize(1);
assertThat(logTester.logs(LoggerLevel.DEBUG).get(0)).isEqualTo(format("Description of Security Hotspot Rule %s can't be fully parsed: What is the risk?=missing, Are you vulnerable?=ok, How to fix it=ok", rule.getKey()));
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class RuleIndexTest method search_by_is_template.
@Test
public void search_by_is_template() {
RuleDefinitionDto ruleNoTemplate = createRule(setIsTemplate(false));
RuleDefinitionDto ruleIsTemplate = createRule(setIsTemplate(true));
index();
// find all
RuleQuery query = new RuleQuery();
SearchIdResult<String> results = underTest.search(query, new SearchOptions());
assertThat(results.getUuids()).hasSize(2);
// Only template
query = new RuleQuery().setIsTemplate(true);
results = underTest.search(query, new SearchOptions());
assertThat(results.getUuids()).containsOnly(ruleIsTemplate.getUuid());
// Only not template
query = new RuleQuery().setIsTemplate(false);
results = underTest.search(query, new SearchOptions());
assertThat(results.getUuids()).containsOnly(ruleNoTemplate.getUuid());
// null => no filter
query = new RuleQuery().setIsTemplate(null);
results = underTest.search(query, new SearchOptions());
assertThat(results.getUuids()).containsOnly(ruleIsTemplate.getUuid(), ruleNoTemplate.getUuid());
}
Aggregations