use of org.sonarqube.ws.Hotspots.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method returns_branch_field_of_components_of_branch.
@Test
public void returns_branch_field_of_components_of_branch() {
ComponentDto project = dbTester.components().insertPublicProject();
ComponentDto branch = dbTester.components().insertProjectBranch(project);
userSessionRule.registerComponents(project, branch);
indexPermissions();
ComponentDto directory = dbTester.components().insertComponent(newDirectory(branch, "donut/acme"));
ComponentDto file = dbTester.components().insertComponent(newFileDto(branch));
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
IssueDto fileHotspot = insertHotspot(branch, file, rule);
IssueDto dirHotspot = insertHotspot(branch, directory, rule);
IssueDto projectHotspot = insertHotspot(branch, branch, rule);
indexIssues();
SearchWsResponse response = newRequest(branch).executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsOnly(fileHotspot.getKey(), dirHotspot.getKey(), projectHotspot.getKey());
assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly(project.getKey(), directory.getKey(), file.getKey());
Map<String, Component> componentByKey = response.getComponentsList().stream().collect(uniqueIndex(Component::getKey));
Component actualProject = componentByKey.get(project.getKey());
assertThat(actualProject.getBranch()).isEqualTo(branch.getBranch());
assertThat(actualProject.hasPullRequest()).isFalse();
Component actualDirectory = componentByKey.get(directory.getKey());
assertThat(actualDirectory.getBranch()).isEqualTo(branch.getBranch());
assertThat(actualDirectory.hasPullRequest()).isFalse();
Component actualFile = componentByKey.get(file.getKey());
assertThat(actualFile.getBranch()).isEqualTo(branch.getBranch());
assertThat(actualFile.hasPullRequest()).isFalse();
}
use of org.sonarqube.ws.Hotspots.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method returns_hotspots_with_specified_owaspTop10_category.
@Test
public void returns_hotspots_with_specified_owaspTop10_category() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDefinitionDto rule1 = newRule(SECURITY_HOTSPOT);
RuleDefinitionDto rule2 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(of("cwe:117", "cwe:190")));
RuleDefinitionDto rule3 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(of("owaspTop10:a1", "cwe:601")));
insertHotspot(project, file, rule1);
insertHotspot(project, file, rule2);
IssueDto hotspot3 = insertHotspot(project, file, rule3);
indexIssues();
SearchWsResponse response = newRequest(project).setParam("owaspTop10", "a1").executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactly(hotspot3.getKey());
}
use of org.sonarqube.ws.Hotspots.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method returns_issues_when_sinceLeakPeriod_is_true_and_is_application_for_branch_other_than_main.
@Test
public void returns_issues_when_sinceLeakPeriod_is_true_and_is_application_for_branch_other_than_main() {
long referenceDate = 800_996_999_332L;
system2.setNow(referenceDate + 10_000);
ProjectDto application = dbTester.components().insertPublicApplicationDto();
BranchDto applicationBranch = dbTester.components().insertProjectBranch(application, branchDto -> branchDto.setKey("application_branch_1"));
ProjectDto project = dbTester.components().insertPublicProjectDto();
BranchDto projectBranch = dbTester.components().insertProjectBranch(project, branchDto -> branchDto.setKey("project_1_branch_1"));
ProjectDto project2 = dbTester.components().insertPublicProjectDto();
BranchDto project2Branch = dbTester.components().insertProjectBranch(project2, branchDto -> branchDto.setKey("project_2_branch_1"));
dbTester.components().addApplicationProject(application, project);
dbTester.components().addApplicationProject(application, project2);
dbTester.components().addProjectBranchToApplicationBranch(applicationBranch, projectBranch, project2Branch);
ComponentDto applicationBranchComponentDto = dbClient.componentDao().selectByUuid(dbTester.getSession(), applicationBranch.getUuid()).get();
ComponentDto projectBranchComponentDto = dbClient.componentDao().selectByUuid(dbTester.getSession(), projectBranch.getUuid()).get();
ComponentDto project2BranchComponentDto = dbClient.componentDao().selectByUuid(dbTester.getSession(), project2Branch.getUuid()).get();
dbTester.components().insertComponent(ComponentTesting.newProjectCopy(projectBranchComponentDto, applicationBranchComponentDto));
dbTester.components().insertComponent(ComponentTesting.newProjectCopy(project2BranchComponentDto, applicationBranchComponentDto));
indexViews();
userSessionRule.registerApplication(application, project, project2);
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(projectBranchComponentDto));
dbTester.components().insertSnapshot(projectBranch, t -> t.setPeriodDate(referenceDate).setLast(true));
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
IssueDto afterRef = dbTester.issues().insertHotspot(rule, projectBranchComponentDto, file, t -> t.setIssueCreationTime(referenceDate + 1000));
IssueDto atRef = dbTester.issues().insertHotspot(rule, projectBranchComponentDto, file, t -> t.setType(SECURITY_HOTSPOT).setIssueCreationTime(referenceDate));
IssueDto beforeRef = dbTester.issues().insertHotspot(rule, projectBranchComponentDto, file, t -> t.setIssueCreationTime(referenceDate - 1000));
ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project2BranchComponentDto));
IssueDto project2Issue = dbTester.issues().insertHotspot(rule, project2BranchComponentDto, file2, t -> t.setIssueCreationTime(referenceDate - 1000));
indexIssues();
ComponentDto applicationComponentDto = dbClient.componentDao().selectByUuid(dbTester.getSession(), application.getUuid()).get();
SearchWsResponse responseAll = newRequest(applicationComponentDto, t -> t.setParam("branch", applicationBranch.getKey())).executeProtobuf(SearchWsResponse.class);
assertThat(responseAll.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactlyInAnyOrder(afterRef.getKey(), atRef.getKey(), beforeRef.getKey(), project2Issue.getKey());
SearchWsResponse responseOnLeak = newRequest(applicationComponentDto, t -> t.setParam("sinceLeakPeriod", "true").setParam("branch", applicationBranch.getKey())).executeProtobuf(SearchWsResponse.class);
assertThat(responseOnLeak.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactlyInAnyOrder(afterRef.getKey());
}
use of org.sonarqube.ws.Hotspots.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method returns_no_hotspot_component_nor_rule_when_project_has_no_hotspot.
@Test
public void returns_no_hotspot_component_nor_rule_when_project_has_no_hotspot() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
Arrays.stream(RuleType.values()).filter(t -> t != SECURITY_HOTSPOT).forEach(ruleType -> {
RuleDefinitionDto rule = newRule(ruleType);
dbTester.issues().insert(rule, project, file, t -> t.setType(ruleType));
});
indexIssues();
SearchWsResponse response = newRequest(project).executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList()).isEmpty();
}
use of org.sonarqube.ws.Hotspots.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method returns_hotspots_with_specified_sonarsourceSecurity_category.
@Test
public void returns_hotspots_with_specified_sonarsourceSecurity_category() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDefinitionDto rule1 = newRule(SECURITY_HOTSPOT);
RuleDefinitionDto rule2 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(of("cwe:117", "cwe:190")));
RuleDefinitionDto rule3 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(of("owaspTop10:a1", "cwe:601")));
insertHotspot(project, file, rule1);
IssueDto hotspot2 = insertHotspot(project, file, rule2);
insertHotspot(project, file, rule3);
indexIssues();
SearchWsResponse response = newRequest(project).setParam("sonarsourceSecurity", "log-injection").executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactly(hotspot2.getKey());
}
Aggregations