Search in sources :

Example 1 with CODE_SMELL

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());
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) IssueDto(org.sonar.db.issue.IssueDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Random(java.util.Random) MapSettings(org.sonar.api.config.internal.MapSettings) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) STATUS_CLOSED(org.sonar.api.issue.Issue.STATUS_CLOSED) ArrayList(java.util.ArrayList) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) ImmutableList(com.google.common.collect.ImmutableList) Configuration(org.sonar.api.config.Configuration) ComponentTesting(org.sonar.db.component.ComponentTesting) DateUtils.addDays(org.sonar.api.utils.DateUtils.addDays) Nullable(javax.annotation.Nullable) DbTester(org.sonar.db.DbTester) DefaultIssue(org.sonar.core.issue.DefaultIssue) System2(org.sonar.api.utils.System2) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) Collections.emptyList(java.util.Collections.emptyList) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) FieldDiffs(org.sonar.core.issue.FieldDiffs) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) Issue(org.sonar.api.issue.Issue) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) Collections(java.util.Collections) CODE_SMELL(org.sonar.api.rules.RuleType.CODE_SMELL) Mockito.mock(org.mockito.Mockito.mock) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) DefaultIssue(org.sonar.core.issue.DefaultIssue) Date(java.util.Date)

Example 2 with CODE_SMELL

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());
}
Also used : FACETS(org.sonar.api.server.ws.WebService.Param.FACETS) BUG(org.sonarqube.ws.Common.RuleType.BUG) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PARAM_ASSIGNEES(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ASSIGNEES) IssueWorkflow(org.sonar.server.issue.workflow.IssueWorkflow) Random(java.util.Random) DbSession(org.sonar.db.DbSession) PARAM_BRANCH(org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BRANCH) GroupPermissionDto(org.sonar.db.permission.GroupPermissionDto) FunctionExecutor(org.sonar.server.issue.workflow.FunctionExecutor) Collections.singletonList(java.util.Collections.singletonList) SearchWsResponse(org.sonarqube.ws.Issues.SearchWsResponse) Languages(org.sonar.api.resources.Languages) DbIssues(org.sonar.db.protobuf.DbIssues) WebService(org.sonar.api.server.ws.WebService) IssueIndex(org.sonar.server.issue.index.IssueIndex) IssueIteratorFactory(org.sonar.server.issue.index.IssueIteratorFactory) UserSessionRule.standalone(org.sonar.server.tester.UserSessionRule.standalone) Arrays.asList(java.util.Arrays.asList) AvatarResolverImpl(org.sonar.server.issue.AvatarResolverImpl) ComponentTesting(org.sonar.db.component.ComponentTesting) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) PARAM_COMPONENT_KEYS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS) PARAM_SINCE_LEAK_PERIOD(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SINCE_LEAK_PERIOD) DbTester(org.sonar.db.DbTester) IssueChangeDto(org.sonar.db.issue.IssueChangeDto) PULL_REQUEST_SEPARATOR(org.sonar.db.component.ComponentDto.PULL_REQUEST_SEPARATOR) RuleTesting(org.sonar.db.rule.RuleTesting) PermissionIndexer(org.sonar.server.permission.index.PermissionIndexer) System2(org.sonar.api.utils.System2) Issue(org.sonarqube.ws.Issues.Issue) RuleMetadataDto(org.sonar.db.rule.RuleMetadataDto) DateUtils.parseDate(org.sonar.api.utils.DateUtils.parseDate) Collectors(java.util.stream.Collectors) PARAM_CREATED_AFTER(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CREATED_AFTER) Sets(com.google.common.collect.Sets) Severity(org.sonarqube.ws.Common.Severity) Common(org.sonarqube.ws.Common) PARAM_HIDE_COMMENTS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_HIDE_COMMENTS) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions) Stream(java.util.stream.Stream) CODE_SMELL(org.sonar.api.rules.RuleType.CODE_SMELL) IntStream(java.util.stream.IntStream) ISSUE_ADMIN(org.sonar.api.web.UserRole.ISSUE_ADMIN) IssueDto(org.sonar.db.issue.IssueDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) EsTester(org.sonar.server.es.EsTester) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) RuleStatus(org.sonar.api.rule.RuleStatus) PARAM_RULES(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_RULES) STATUS_RESOLVED(org.sonar.api.issue.Issue.STATUS_RESOLVED) JsonParser(com.google.gson.JsonParser) RuleType(org.sonar.api.rules.RuleType) JsonElement(com.google.gson.JsonElement) IssueFieldsSetter(org.sonar.server.issue.IssueFieldsSetter) PARAM_IN_NEW_CODE_PERIOD(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_IN_NEW_CODE_PERIOD) Uuids(org.sonar.core.util.Uuids) TransitionService(org.sonar.server.issue.TransitionService) WebAuthorizationTypeSupport(org.sonar.server.permission.index.WebAuthorizationTypeSupport) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) PARAM_ADDITIONAL_FIELDS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ADDITIONAL_FIELDS) TextRangeResponseFormatter(org.sonar.server.issue.TextRangeResponseFormatter) IssueQueryFactory(org.sonar.server.issue.index.IssueQueryFactory) RESOLUTION_FIXED(org.sonar.api.issue.Issue.RESOLUTION_FIXED) Before(org.junit.Before) UserSessionRule(org.sonar.server.tester.UserSessionRule) BranchType(org.sonar.db.component.BranchType) PARAM_PULL_REQUEST(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PULL_REQUEST) Durations(org.sonar.api.utils.Durations) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test) WsActionTester(org.sonar.server.ws.WsActionTester) DbCommons(org.sonar.db.protobuf.DbCommons) IssueTesting.newDto(org.sonar.db.issue.IssueTesting.newDto) Consumer(java.util.function.Consumer) SECURITY_HOTSPOT_VALUE(org.sonarqube.ws.Common.RuleType.SECURITY_HOTSPOT_VALUE) Rule(org.junit.Rule) UNIT_TEST_FILE(org.sonar.api.resources.Qualifiers.UNIT_TEST_FILE) IssueIndexSyncProgressChecker(org.sonar.server.issue.index.IssueIndexSyncProgressChecker) RuleDto(org.sonar.db.rule.RuleDto) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) VULNERABILITY(org.sonarqube.ws.Common.RuleType.VULNERABILITY) Clock(java.time.Clock) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) SnapshotDto(org.sonar.db.component.SnapshotDto) Collections(java.util.Collections) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) IssueQuery(org.sonar.server.issue.index.IssueQuery) TestResponse(org.sonar.server.ws.TestResponse) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) SearchWsResponse(org.sonarqube.ws.Issues.SearchWsResponse) Test(org.junit.Test)

Example 3 with CODE_SMELL

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());
}
Also used : FACETS(org.sonar.api.server.ws.WebService.Param.FACETS) BUG(org.sonarqube.ws.Common.RuleType.BUG) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PARAM_ASSIGNEES(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ASSIGNEES) IssueWorkflow(org.sonar.server.issue.workflow.IssueWorkflow) Random(java.util.Random) DbSession(org.sonar.db.DbSession) PARAM_BRANCH(org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BRANCH) GroupPermissionDto(org.sonar.db.permission.GroupPermissionDto) FunctionExecutor(org.sonar.server.issue.workflow.FunctionExecutor) Collections.singletonList(java.util.Collections.singletonList) SearchWsResponse(org.sonarqube.ws.Issues.SearchWsResponse) Languages(org.sonar.api.resources.Languages) DbIssues(org.sonar.db.protobuf.DbIssues) WebService(org.sonar.api.server.ws.WebService) IssueIndex(org.sonar.server.issue.index.IssueIndex) IssueIteratorFactory(org.sonar.server.issue.index.IssueIteratorFactory) UserSessionRule.standalone(org.sonar.server.tester.UserSessionRule.standalone) Arrays.asList(java.util.Arrays.asList) AvatarResolverImpl(org.sonar.server.issue.AvatarResolverImpl) ComponentTesting(org.sonar.db.component.ComponentTesting) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) PARAM_COMPONENT_KEYS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS) PARAM_SINCE_LEAK_PERIOD(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SINCE_LEAK_PERIOD) DbTester(org.sonar.db.DbTester) IssueChangeDto(org.sonar.db.issue.IssueChangeDto) PULL_REQUEST_SEPARATOR(org.sonar.db.component.ComponentDto.PULL_REQUEST_SEPARATOR) RuleTesting(org.sonar.db.rule.RuleTesting) PermissionIndexer(org.sonar.server.permission.index.PermissionIndexer) System2(org.sonar.api.utils.System2) Issue(org.sonarqube.ws.Issues.Issue) RuleMetadataDto(org.sonar.db.rule.RuleMetadataDto) DateUtils.parseDate(org.sonar.api.utils.DateUtils.parseDate) Collectors(java.util.stream.Collectors) PARAM_CREATED_AFTER(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CREATED_AFTER) Sets(com.google.common.collect.Sets) Severity(org.sonarqube.ws.Common.Severity) Common(org.sonarqube.ws.Common) PARAM_HIDE_COMMENTS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_HIDE_COMMENTS) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions) Stream(java.util.stream.Stream) CODE_SMELL(org.sonar.api.rules.RuleType.CODE_SMELL) IntStream(java.util.stream.IntStream) ISSUE_ADMIN(org.sonar.api.web.UserRole.ISSUE_ADMIN) IssueDto(org.sonar.db.issue.IssueDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) EsTester(org.sonar.server.es.EsTester) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) RuleStatus(org.sonar.api.rule.RuleStatus) PARAM_RULES(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_RULES) STATUS_RESOLVED(org.sonar.api.issue.Issue.STATUS_RESOLVED) JsonParser(com.google.gson.JsonParser) RuleType(org.sonar.api.rules.RuleType) JsonElement(com.google.gson.JsonElement) IssueFieldsSetter(org.sonar.server.issue.IssueFieldsSetter) PARAM_IN_NEW_CODE_PERIOD(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_IN_NEW_CODE_PERIOD) Uuids(org.sonar.core.util.Uuids) TransitionService(org.sonar.server.issue.TransitionService) WebAuthorizationTypeSupport(org.sonar.server.permission.index.WebAuthorizationTypeSupport) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) PARAM_ADDITIONAL_FIELDS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ADDITIONAL_FIELDS) TextRangeResponseFormatter(org.sonar.server.issue.TextRangeResponseFormatter) IssueQueryFactory(org.sonar.server.issue.index.IssueQueryFactory) RESOLUTION_FIXED(org.sonar.api.issue.Issue.RESOLUTION_FIXED) Before(org.junit.Before) UserSessionRule(org.sonar.server.tester.UserSessionRule) BranchType(org.sonar.db.component.BranchType) PARAM_PULL_REQUEST(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PULL_REQUEST) Durations(org.sonar.api.utils.Durations) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test) WsActionTester(org.sonar.server.ws.WsActionTester) DbCommons(org.sonar.db.protobuf.DbCommons) IssueTesting.newDto(org.sonar.db.issue.IssueTesting.newDto) Consumer(java.util.function.Consumer) SECURITY_HOTSPOT_VALUE(org.sonarqube.ws.Common.RuleType.SECURITY_HOTSPOT_VALUE) Rule(org.junit.Rule) UNIT_TEST_FILE(org.sonar.api.resources.Qualifiers.UNIT_TEST_FILE) IssueIndexSyncProgressChecker(org.sonar.server.issue.index.IssueIndexSyncProgressChecker) RuleDto(org.sonar.db.rule.RuleDto) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) VULNERABILITY(org.sonarqube.ws.Common.RuleType.VULNERABILITY) Clock(java.time.Clock) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) SnapshotDto(org.sonar.db.component.SnapshotDto) Collections(java.util.Collections) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) IssueQuery(org.sonar.server.issue.index.IssueQuery) TestResponse(org.sonar.server.ws.TestResponse) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) SearchWsResponse(org.sonarqube.ws.Issues.SearchWsResponse) Test(org.junit.Test)

Example 4 with CODE_SMELL

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());
}
Also used : FACETS(org.sonar.api.server.ws.WebService.Param.FACETS) BUG(org.sonarqube.ws.Common.RuleType.BUG) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PARAM_ASSIGNEES(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ASSIGNEES) IssueWorkflow(org.sonar.server.issue.workflow.IssueWorkflow) Random(java.util.Random) DbSession(org.sonar.db.DbSession) PARAM_BRANCH(org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BRANCH) GroupPermissionDto(org.sonar.db.permission.GroupPermissionDto) FunctionExecutor(org.sonar.server.issue.workflow.FunctionExecutor) Collections.singletonList(java.util.Collections.singletonList) SearchWsResponse(org.sonarqube.ws.Issues.SearchWsResponse) Languages(org.sonar.api.resources.Languages) DbIssues(org.sonar.db.protobuf.DbIssues) WebService(org.sonar.api.server.ws.WebService) IssueIndex(org.sonar.server.issue.index.IssueIndex) IssueIteratorFactory(org.sonar.server.issue.index.IssueIteratorFactory) UserSessionRule.standalone(org.sonar.server.tester.UserSessionRule.standalone) Arrays.asList(java.util.Arrays.asList) AvatarResolverImpl(org.sonar.server.issue.AvatarResolverImpl) ComponentTesting(org.sonar.db.component.ComponentTesting) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) PARAM_COMPONENT_KEYS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS) PARAM_SINCE_LEAK_PERIOD(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SINCE_LEAK_PERIOD) DbTester(org.sonar.db.DbTester) IssueChangeDto(org.sonar.db.issue.IssueChangeDto) PULL_REQUEST_SEPARATOR(org.sonar.db.component.ComponentDto.PULL_REQUEST_SEPARATOR) RuleTesting(org.sonar.db.rule.RuleTesting) PermissionIndexer(org.sonar.server.permission.index.PermissionIndexer) System2(org.sonar.api.utils.System2) Issue(org.sonarqube.ws.Issues.Issue) RuleMetadataDto(org.sonar.db.rule.RuleMetadataDto) DateUtils.parseDate(org.sonar.api.utils.DateUtils.parseDate) Collectors(java.util.stream.Collectors) PARAM_CREATED_AFTER(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CREATED_AFTER) Sets(com.google.common.collect.Sets) Severity(org.sonarqube.ws.Common.Severity) Common(org.sonarqube.ws.Common) PARAM_HIDE_COMMENTS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_HIDE_COMMENTS) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions) Stream(java.util.stream.Stream) CODE_SMELL(org.sonar.api.rules.RuleType.CODE_SMELL) IntStream(java.util.stream.IntStream) ISSUE_ADMIN(org.sonar.api.web.UserRole.ISSUE_ADMIN) IssueDto(org.sonar.db.issue.IssueDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) EsTester(org.sonar.server.es.EsTester) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) RuleStatus(org.sonar.api.rule.RuleStatus) PARAM_RULES(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_RULES) STATUS_RESOLVED(org.sonar.api.issue.Issue.STATUS_RESOLVED) JsonParser(com.google.gson.JsonParser) RuleType(org.sonar.api.rules.RuleType) JsonElement(com.google.gson.JsonElement) IssueFieldsSetter(org.sonar.server.issue.IssueFieldsSetter) PARAM_IN_NEW_CODE_PERIOD(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_IN_NEW_CODE_PERIOD) Uuids(org.sonar.core.util.Uuids) TransitionService(org.sonar.server.issue.TransitionService) WebAuthorizationTypeSupport(org.sonar.server.permission.index.WebAuthorizationTypeSupport) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) PARAM_ADDITIONAL_FIELDS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ADDITIONAL_FIELDS) TextRangeResponseFormatter(org.sonar.server.issue.TextRangeResponseFormatter) IssueQueryFactory(org.sonar.server.issue.index.IssueQueryFactory) RESOLUTION_FIXED(org.sonar.api.issue.Issue.RESOLUTION_FIXED) Before(org.junit.Before) UserSessionRule(org.sonar.server.tester.UserSessionRule) BranchType(org.sonar.db.component.BranchType) PARAM_PULL_REQUEST(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PULL_REQUEST) Durations(org.sonar.api.utils.Durations) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test) WsActionTester(org.sonar.server.ws.WsActionTester) DbCommons(org.sonar.db.protobuf.DbCommons) IssueTesting.newDto(org.sonar.db.issue.IssueTesting.newDto) Consumer(java.util.function.Consumer) SECURITY_HOTSPOT_VALUE(org.sonarqube.ws.Common.RuleType.SECURITY_HOTSPOT_VALUE) Rule(org.junit.Rule) UNIT_TEST_FILE(org.sonar.api.resources.Qualifiers.UNIT_TEST_FILE) IssueIndexSyncProgressChecker(org.sonar.server.issue.index.IssueIndexSyncProgressChecker) RuleDto(org.sonar.db.rule.RuleDto) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) VULNERABILITY(org.sonarqube.ws.Common.RuleType.VULNERABILITY) Clock(java.time.Clock) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) SnapshotDto(org.sonar.db.component.SnapshotDto) Collections(java.util.Collections) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) IssueQuery(org.sonar.server.issue.index.IssueQuery) TestResponse(org.sonar.server.ws.TestResponse) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) SearchWsResponse(org.sonarqube.ws.Issues.SearchWsResponse) Test(org.junit.Test)

Example 5 with CODE_SMELL

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());
}
Also used : FACETS(org.sonar.api.server.ws.WebService.Param.FACETS) BUG(org.sonarqube.ws.Common.RuleType.BUG) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PARAM_ASSIGNEES(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ASSIGNEES) IssueWorkflow(org.sonar.server.issue.workflow.IssueWorkflow) Random(java.util.Random) DbSession(org.sonar.db.DbSession) PARAM_BRANCH(org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BRANCH) GroupPermissionDto(org.sonar.db.permission.GroupPermissionDto) FunctionExecutor(org.sonar.server.issue.workflow.FunctionExecutor) Collections.singletonList(java.util.Collections.singletonList) SearchWsResponse(org.sonarqube.ws.Issues.SearchWsResponse) Languages(org.sonar.api.resources.Languages) DbIssues(org.sonar.db.protobuf.DbIssues) WebService(org.sonar.api.server.ws.WebService) IssueIndex(org.sonar.server.issue.index.IssueIndex) IssueIteratorFactory(org.sonar.server.issue.index.IssueIteratorFactory) UserSessionRule.standalone(org.sonar.server.tester.UserSessionRule.standalone) Arrays.asList(java.util.Arrays.asList) AvatarResolverImpl(org.sonar.server.issue.AvatarResolverImpl) ComponentTesting(org.sonar.db.component.ComponentTesting) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) PARAM_COMPONENT_KEYS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS) PARAM_SINCE_LEAK_PERIOD(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SINCE_LEAK_PERIOD) DbTester(org.sonar.db.DbTester) IssueChangeDto(org.sonar.db.issue.IssueChangeDto) PULL_REQUEST_SEPARATOR(org.sonar.db.component.ComponentDto.PULL_REQUEST_SEPARATOR) RuleTesting(org.sonar.db.rule.RuleTesting) PermissionIndexer(org.sonar.server.permission.index.PermissionIndexer) System2(org.sonar.api.utils.System2) Issue(org.sonarqube.ws.Issues.Issue) RuleMetadataDto(org.sonar.db.rule.RuleMetadataDto) DateUtils.parseDate(org.sonar.api.utils.DateUtils.parseDate) Collectors(java.util.stream.Collectors) PARAM_CREATED_AFTER(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CREATED_AFTER) Sets(com.google.common.collect.Sets) Severity(org.sonarqube.ws.Common.Severity) Common(org.sonarqube.ws.Common) PARAM_HIDE_COMMENTS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_HIDE_COMMENTS) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions) Stream(java.util.stream.Stream) CODE_SMELL(org.sonar.api.rules.RuleType.CODE_SMELL) IntStream(java.util.stream.IntStream) ISSUE_ADMIN(org.sonar.api.web.UserRole.ISSUE_ADMIN) IssueDto(org.sonar.db.issue.IssueDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) EsTester(org.sonar.server.es.EsTester) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) RuleStatus(org.sonar.api.rule.RuleStatus) PARAM_RULES(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_RULES) STATUS_RESOLVED(org.sonar.api.issue.Issue.STATUS_RESOLVED) JsonParser(com.google.gson.JsonParser) RuleType(org.sonar.api.rules.RuleType) JsonElement(com.google.gson.JsonElement) IssueFieldsSetter(org.sonar.server.issue.IssueFieldsSetter) PARAM_IN_NEW_CODE_PERIOD(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_IN_NEW_CODE_PERIOD) Uuids(org.sonar.core.util.Uuids) TransitionService(org.sonar.server.issue.TransitionService) WebAuthorizationTypeSupport(org.sonar.server.permission.index.WebAuthorizationTypeSupport) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) PARAM_ADDITIONAL_FIELDS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ADDITIONAL_FIELDS) TextRangeResponseFormatter(org.sonar.server.issue.TextRangeResponseFormatter) IssueQueryFactory(org.sonar.server.issue.index.IssueQueryFactory) RESOLUTION_FIXED(org.sonar.api.issue.Issue.RESOLUTION_FIXED) Before(org.junit.Before) UserSessionRule(org.sonar.server.tester.UserSessionRule) BranchType(org.sonar.db.component.BranchType) PARAM_PULL_REQUEST(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PULL_REQUEST) Durations(org.sonar.api.utils.Durations) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test) WsActionTester(org.sonar.server.ws.WsActionTester) DbCommons(org.sonar.db.protobuf.DbCommons) IssueTesting.newDto(org.sonar.db.issue.IssueTesting.newDto) Consumer(java.util.function.Consumer) SECURITY_HOTSPOT_VALUE(org.sonarqube.ws.Common.RuleType.SECURITY_HOTSPOT_VALUE) Rule(org.junit.Rule) UNIT_TEST_FILE(org.sonar.api.resources.Qualifiers.UNIT_TEST_FILE) IssueIndexSyncProgressChecker(org.sonar.server.issue.index.IssueIndexSyncProgressChecker) RuleDto(org.sonar.db.rule.RuleDto) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) VULNERABILITY(org.sonarqube.ws.Common.RuleType.VULNERABILITY) Clock(java.time.Clock) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) SnapshotDto(org.sonar.db.component.SnapshotDto) Collections(java.util.Collections) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) IssueQuery(org.sonar.server.issue.index.IssueQuery) TestResponse(org.sonar.server.ws.TestResponse) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) SearchWsResponse(org.sonarqube.ws.Issues.SearchWsResponse) Test(org.junit.Test)

Aggregations

Arrays (java.util.Arrays)5 Collections (java.util.Collections)5 List (java.util.List)5 Random (java.util.Random)5 IntStream (java.util.stream.IntStream)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 Rule (org.junit.Rule)5 Test (org.junit.Test)5 CODE_SMELL (org.sonar.api.rules.RuleType.CODE_SMELL)5 DateUtils.parseDateTime (org.sonar.api.utils.DateUtils.parseDateTime)5 System2 (org.sonar.api.utils.System2)5 DbClient (org.sonar.db.DbClient)5 DbTester (org.sonar.db.DbTester)5 Sets (com.google.common.collect.Sets)4 JsonElement (com.google.gson.JsonElement)4 JsonParser (com.google.gson.JsonParser)4 Clock (java.time.Clock)4 Arrays.asList (java.util.Arrays.asList)4 Collections.singletonList (java.util.Collections.singletonList)4 Consumer (java.util.function.Consumer)4