Search in sources :

Example 31 with RuleDefinitionDto

use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.

the class HotspotRuleDescriptionTest method parse_with_noncompliant_section_not_removed.

@Test
public void parse_with_noncompliant_section_not_removed() {
    RuleDefinitionDto dto = RuleTesting.newRule().setDescription(DESCRIPTION + NONCOMPLIANTCODE + COMPLIANTCODE);
    HotspotRuleDescription result = HotspotRuleDescription.from(dto);
    assertThat(result.getRisk()).contains(DESCRIPTION);
    assertThat(result.getVulnerable()).contains(NONCOMPLIANTCODE);
    assertThat(result.getFixIt()).contains(COMPLIANTCODE);
}
Also used : RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) Test(org.junit.Test)

Example 32 with RuleDefinitionDto

use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.

the class HotspotRuleDescriptionTest method parse_moved_noncompliant_code.

@Test
public void parse_moved_noncompliant_code() {
    RuleDefinitionDto dto = RuleTesting.newRule().setDescription(DESCRIPTION + RECOMMENTEDCODINGPRACTICE + NONCOMPLIANTCODE + SEE);
    HotspotRuleDescription result = HotspotRuleDescription.from(dto);
    assertThat(result.getRisk()).contains(DESCRIPTION);
    assertThat(result.getVulnerable()).contains(NONCOMPLIANTCODE);
    assertThat(result.getFixIt()).contains(RECOMMENTEDCODINGPRACTICE + SEE);
}
Also used : RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) Test(org.junit.Test)

Example 33 with RuleDefinitionDto

use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.

the class HotspotRuleDescriptionTest method parse_return_null_fixIt_when_desc_has_no_Recommended_Secure_Coding_Practices_title.

@Test
public void parse_return_null_fixIt_when_desc_has_no_Recommended_Secure_Coding_Practices_title() {
    RuleDefinitionDto dto = RuleTesting.newRule().setDescription(DESCRIPTION + ASKATRISK);
    HotspotRuleDescription result = HotspotRuleDescription.from(dto);
    assertThat(result.getRisk()).contains(DESCRIPTION);
    assertThat(result.getVulnerable()).contains(ASKATRISK);
    assertThat(result.getFixIt()).isEmpty();
}
Also used : RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) Test(org.junit.Test)

Example 34 with RuleDefinitionDto

use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.

the class RuleIndexerTest method log_debug_when_hotspot_rule_description_is_missing_vulnerable_tab_content.

@Test
public void log_debug_when_hotspot_rule_description_is_missing_vulnerable_tab_content() {
    RuleDefinitionDto rule = dbTester.rules().insert(RuleTesting.newRule().setType(RuleType.SECURITY_HOTSPOT).setDescription("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?=ok, Are you vulnerable?=missing, How to fix it=ok", rule.getKey()));
}
Also used : RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) Test(org.junit.Test)

Example 35 with RuleDefinitionDto

use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.

the class RuleIndexerTest method index_long_rule_description.

@Test
public void index_long_rule_description() {
    String description = IntStream.range(0, 100000).map(i -> i % 100).mapToObj(Integer::toString).collect(joining(" "));
    RuleDefinitionDto rule = dbTester.rules().insert(r -> r.setDescription(description));
    underTest.commitAndIndex(dbTester.getSession(), rule.getUuid());
    assertThat(es.countDocuments(TYPE_RULE)).isOne();
}
Also used : RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) Test(org.junit.Test)

Aggregations

RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)654 Test (org.junit.Test)583 ComponentDto (org.sonar.db.component.ComponentDto)305 IssueDto (org.sonar.db.issue.IssueDto)219 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)144 UserDto (org.sonar.db.user.UserDto)96 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)93 DbTester (org.sonar.db.DbTester)93 System2 (org.sonar.api.utils.System2)91 UserSessionRule (org.sonar.server.tester.UserSessionRule)84 List (java.util.List)80 Rule (org.junit.Rule)77 DbClient (org.sonar.db.DbClient)68 RuleParamDto (org.sonar.db.rule.RuleParamDto)67 Mockito.mock (org.mockito.Mockito.mock)65 TestRequest (org.sonar.server.ws.TestRequest)64 Consumer (java.util.function.Consumer)63 EsTester (org.sonar.server.es.EsTester)61 Random (java.util.Random)60 RuleType (org.sonar.api.rules.RuleType)60