use of org.sonar.api.rules.RuleType.CODE_SMELL in project sonarqube by SonarSource.
the class ComponentIssuesLoaderTest method loadClosedIssues_returns_only_closed_issues_with_close_date_is_from_30_days_ago.
private void loadClosedIssues_returns_only_closed_issues_with_close_date_is_from_30_days_ago(ComponentIssuesLoader underTest) {
ComponentDto project = db.components().insertPublicProject();
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project));
RuleDefinitionDto rule = db.rules().insert(t -> t.setType(CODE_SMELL));
Date[] issueDates = new Date[] { addDays(NOW, -10), addDays(NOW, -31), addDays(NOW, -30), DATE_LIMIT_30_DAYS_BACK_MIDNIGHT, addDays(NOW, -29), addDays(NOW, -60) };
IssueDto[] issues = Arrays.stream(issueDates).map(issueDate -> {
IssueDto closedIssue = db.issues().insert(rule, project, file, t -> t.setStatus(STATUS_CLOSED).setIssueCloseDate(issueDate).setType(CODE_SMELL));
db.issues().insertFieldDiffs(closedIssue, newToClosedDiffsWithLine(issueDate, 10));
return closedIssue;
}).toArray(IssueDto[]::new);
when(system2.now()).thenReturn(NOW.getTime());
List<DefaultIssue> defaultIssues = underTest.loadClosedIssues(file.uuid());
assertThat(defaultIssues).extracting(DefaultIssue::key).containsOnly(issues[0].getKey(), issues[2].getKey(), issues[3].getKey(), issues[4].getKey());
}
use of org.sonar.api.rules.RuleType.CODE_SMELL in project sonarqube by SonarSource.
the class SearchActionTest method only_vulnerabilities_are_returned_by_owasp.
@Test
public void only_vulnerabilities_are_returned_by_owasp() {
ComponentDto project = db.components().insertPublicProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
Consumer<RuleDefinitionDto> ruleConsumer = ruleDefinitionDto -> ruleDefinitionDto.setSecurityStandards(Sets.newHashSet("cwe:20", "cwe:564", "cwe:89", "cwe:943", "owaspTop10:a1")).setSystemTags(Sets.newHashSet("bad-practice", "cwe", "owasp-a1", "sans-top25-insecure", "sql"));
Consumer<IssueDto> issueConsumer = issueDto -> issueDto.setTags(Sets.newHashSet("bad-practice", "cwe", "owasp-a1", "sans-top25-insecure", "sql"));
RuleDefinitionDto hotspotRule = db.rules().insertHotspotRule(ruleConsumer);
db.issues().insertHotspot(hotspotRule, project, file, issueConsumer);
RuleDefinitionDto issueRule = db.rules().insertIssueRule(ruleConsumer);
IssueDto issueDto1 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(RuleType.VULNERABILITY));
IssueDto issueDto2 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(RuleType.VULNERABILITY));
IssueDto issueDto3 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(CODE_SMELL));
indexPermissionsAndIssues();
SearchWsResponse result = ws.newRequest().setParam("owaspTop10", "a1").executeProtobuf(SearchWsResponse.class);
assertThat(result.getIssuesList()).extracting(Issue::getKey).containsExactlyInAnyOrder(issueDto1.getKey(), issueDto2.getKey());
}
use of org.sonar.api.rules.RuleType.CODE_SMELL in project sonarqube by SonarSource.
the class SearchActionTest method only_vulnerabilities_are_returned_by_sonarsource_security.
@Test
public void only_vulnerabilities_are_returned_by_sonarsource_security() {
ComponentDto project = db.components().insertPublicProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
Consumer<RuleDefinitionDto> ruleConsumer = ruleDefinitionDto -> ruleDefinitionDto.setSecurityStandards(Sets.newHashSet("cwe:20", "cwe:564", "cwe:89", "cwe:943", "owaspTop10:a1")).setSystemTags(Sets.newHashSet("cwe", "owasp-a1", "sans-top25-insecure", "sql"));
Consumer<IssueDto> issueConsumer = issueDto -> issueDto.setTags(Sets.newHashSet("cwe", "owasp-a1", "sans-top25-insecure", "sql"));
RuleDefinitionDto hotspotRule = db.rules().insertHotspotRule(ruleConsumer);
db.issues().insertHotspot(hotspotRule, project, file, issueConsumer);
RuleDefinitionDto issueRule = db.rules().insertIssueRule(ruleConsumer);
IssueDto issueDto1 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(RuleType.VULNERABILITY));
IssueDto issueDto2 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(RuleType.VULNERABILITY));
IssueDto issueDto3 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(CODE_SMELL));
indexPermissionsAndIssues();
SearchWsResponse result = ws.newRequest().setParam("sonarsourceSecurity", "sql-injection").executeProtobuf(SearchWsResponse.class);
assertThat(result.getIssuesList()).extracting(Issue::getKey).containsExactlyInAnyOrder(issueDto1.getKey(), issueDto2.getKey());
}
use of org.sonar.api.rules.RuleType.CODE_SMELL in project sonarqube by SonarSource.
the class SearchActionTest method only_vulnerabilities_are_returned_by_cwe.
@Test
public void only_vulnerabilities_are_returned_by_cwe() {
ComponentDto project = db.components().insertPublicProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
Consumer<RuleDefinitionDto> ruleConsumer = ruleDefinitionDto -> ruleDefinitionDto.setSecurityStandards(Sets.newHashSet("cwe:20", "cwe:564", "cwe:89", "cwe:943", "owaspTop10:a1")).setSystemTags(Sets.newHashSet("bad-practice", "cwe", "owasp-a1", "sans-top25-insecure", "sql"));
Consumer<IssueDto> issueConsumer = issueDto -> issueDto.setTags(Sets.newHashSet("bad-practice", "cwe", "owasp-a1", "sans-top25-insecure", "sql"));
RuleDefinitionDto hotspotRule = db.rules().insertHotspotRule(ruleConsumer);
db.issues().insertHotspot(hotspotRule, project, file, issueConsumer);
RuleDefinitionDto issueRule = db.rules().insertIssueRule(ruleConsumer);
IssueDto issueDto1 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(RuleType.VULNERABILITY));
IssueDto issueDto2 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(RuleType.VULNERABILITY));
IssueDto issueDto3 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(CODE_SMELL));
indexPermissionsAndIssues();
SearchWsResponse result = ws.newRequest().setParam("cwe", "20").executeProtobuf(SearchWsResponse.class);
assertThat(result.getIssuesList()).extracting(Issue::getKey).containsExactlyInAnyOrder(issueDto1.getKey(), issueDto2.getKey());
}
use of org.sonar.api.rules.RuleType.CODE_SMELL in project sonarqube by SonarSource.
the class SearchActionTest method only_vulnerabilities_are_returned_by_sansTop25.
@Test
public void only_vulnerabilities_are_returned_by_sansTop25() {
ComponentDto project = db.components().insertPublicProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
Consumer<RuleDefinitionDto> ruleConsumer = ruleDefinitionDto -> ruleDefinitionDto.setSecurityStandards(Sets.newHashSet("cwe:266", "cwe:732", "owaspTop10:a5")).setSystemTags(Sets.newHashSet("cert", "cwe", "owasp-a5", "sans-top25-porous"));
Consumer<IssueDto> issueConsumer = issueDto -> issueDto.setTags(Sets.newHashSet("cert", "cwe", "owasp-a5", "sans-top25-porous"));
RuleDefinitionDto hotspotRule = db.rules().insertHotspotRule(ruleConsumer);
db.issues().insertHotspot(hotspotRule, project, file, issueConsumer);
RuleDefinitionDto issueRule = db.rules().insertIssueRule(ruleConsumer);
IssueDto issueDto1 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(RuleType.VULNERABILITY));
IssueDto issueDto2 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(RuleType.VULNERABILITY));
IssueDto issueDto3 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(CODE_SMELL));
indexPermissionsAndIssues();
SearchWsResponse result = ws.newRequest().setParam("sansTop25", "porous-defenses").executeProtobuf(SearchWsResponse.class);
assertThat(result.getIssuesList()).extracting(Issue::getKey).containsExactlyInAnyOrder(issueDto1.getKey(), issueDto2.getKey());
}
Aggregations