use of org.sonarqube.ws.Hotspots.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method returns_hotspots_with_specified_sansTop25_category.
@Test
public void returns_hotspots_with_specified_sansTop25_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("sansTop25", "insecure-interaction").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_hotspot_of_branch_or_pullRequest.
@Test
public void returns_hotspot_of_branch_or_pullRequest() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
ComponentDto branch = dbTester.components().insertProjectBranch(project);
ComponentDto pullRequest = dbTester.components().insertProjectBranch(project, t -> t.setBranchType(BranchType.PULL_REQUEST));
ComponentDto fileProject = dbTester.components().insertComponent(newFileDto(project));
ComponentDto fileBranch = dbTester.components().insertComponent(newFileDto(branch));
ComponentDto filePR = dbTester.components().insertComponent(newFileDto(pullRequest));
IssueDto[] hotspotProject = IntStream.range(0, 1 + RANDOM.nextInt(10)).mapToObj(i -> {
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
return insertHotspot(project, fileProject, rule);
}).toArray(IssueDto[]::new);
IssueDto[] hotspotBranch = IntStream.range(0, 1 + RANDOM.nextInt(10)).mapToObj(i -> {
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
return insertHotspot(branch, fileBranch, rule);
}).toArray(IssueDto[]::new);
IssueDto[] hotspotPR = IntStream.range(0, 1 + RANDOM.nextInt(10)).mapToObj(i -> {
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
return insertHotspot(pullRequest, filePR, rule);
}).toArray(IssueDto[]::new);
indexIssues();
SearchWsResponse responseProject = newRequest(project).executeProtobuf(SearchWsResponse.class);
SearchWsResponse responseBranch = newRequest(branch).executeProtobuf(SearchWsResponse.class);
SearchWsResponse responsePR = newRequest(pullRequest).executeProtobuf(SearchWsResponse.class);
assertThat(responseProject.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactlyInAnyOrder(Arrays.stream(hotspotProject).map(IssueDto::getKey).toArray(String[]::new));
assertThat(responseBranch.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactlyInAnyOrder(Arrays.stream(hotspotBranch).map(IssueDto::getKey).toArray(String[]::new));
assertThat(responsePR.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactlyInAnyOrder(Arrays.stream(hotspotPR).map(IssueDto::getKey).toArray(String[]::new));
verify(issueIndexSyncProgressChecker, times(3)).checkIfComponentNeedIssueSync(any(), eq(project.getDbKey()));
}
use of org.sonarqube.ws.Hotspots.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method returns_hotspots_on_the_leak_period_when_sinceLeakPeriod_is_true_and_branch_uses_reference_branch.
@Test
public void returns_hotspots_on_the_leak_period_when_sinceLeakPeriod_is_true_and_branch_uses_reference_branch() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
dbTester.components().insertSnapshot(project, t -> t.setPeriodMode(REFERENCE_BRANCH.name()).setPeriodParam("master"));
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
List<IssueDto> hotspotsInLeakPeriod = IntStream.range(0, 1 + RANDOM.nextInt(20)).mapToObj(i -> dbTester.issues().insertHotspot(rule, project, file, t -> t.setLine(i))).collect(toList());
hotspotsInLeakPeriod.stream().forEach(i -> dbTester.issues().insertNewCodeReferenceIssue(newCodeReferenceIssue(i)));
List<IssueDto> hotspotsNotInLeakPeriod = IntStream.range(0, 1 + RANDOM.nextInt(20)).mapToObj(i -> dbTester.issues().insertHotspot(rule, project, file, t -> t.setLine(i))).collect(toList());
indexIssues();
SearchWsResponse responseAll = newRequest(project).executeProtobuf(SearchWsResponse.class);
assertThat(responseAll.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactlyInAnyOrder(Stream.of(hotspotsInLeakPeriod.stream(), hotspotsNotInLeakPeriod.stream()).flatMap(t -> t).map(IssueDto::getKey).toArray(String[]::new));
SearchWsResponse responseOnLeak = newRequest(project, t -> t.setParam("sinceLeakPeriod", "true")).executeProtobuf(SearchWsResponse.class);
assertThat(responseOnLeak.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactlyInAnyOrder(hotspotsInLeakPeriod.stream().map(IssueDto::getKey).toArray(String[]::new));
}
use of org.sonarqube.ws.Hotspots.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method returns_hotspots_on_the_leak_period_when_sinceLeakPeriod_is_true.
@Test
public void returns_hotspots_on_the_leak_period_when_sinceLeakPeriod_is_true() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
long periodDate = 800_996_999_332L;
dbTester.components().insertSnapshot(project, t -> t.setPeriodDate(periodDate).setLast(false));
dbTester.components().insertSnapshot(project, t -> t.setPeriodDate(periodDate - 1_500).setLast(true));
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
List<IssueDto> hotspotsInLeakPeriod = IntStream.range(0, 1 + RANDOM.nextInt(20)).mapToObj(i -> {
long issueCreationDate = periodDate + ONE_MINUTE + (RANDOM.nextInt(300) * ONE_MINUTE);
return dbTester.issues().insertHotspot(rule, project, file, t -> t.setLine(i).setIssueCreationTime(issueCreationDate));
}).collect(toList());
// included because
List<IssueDto> atLeakPeriod = IntStream.range(0, 1 + RANDOM.nextInt(20)).mapToObj(i -> dbTester.issues().insertHotspot(rule, project, file, t -> t.setType(SECURITY_HOTSPOT).setLine(i).setIssueCreationTime(periodDate))).collect(toList());
List<IssueDto> hotspotsBefore = IntStream.range(0, 1 + RANDOM.nextInt(20)).mapToObj(i -> {
long issueCreationDate = periodDate - ONE_MINUTE - (RANDOM.nextInt(300) * ONE_MINUTE);
return dbTester.issues().insertHotspot(rule, project, file, t -> t.setLine(i).setIssueCreationTime(issueCreationDate));
}).collect(toList());
indexIssues();
SearchWsResponse responseAll = newRequest(project).executeProtobuf(SearchWsResponse.class);
assertThat(responseAll.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactlyInAnyOrder(Stream.of(hotspotsInLeakPeriod.stream(), atLeakPeriod.stream(), hotspotsBefore.stream()).flatMap(t -> t).map(IssueDto::getKey).toArray(String[]::new));
SearchWsResponse responseOnLeak = newRequest(project, t -> t.setParam("sinceLeakPeriod", "true")).executeProtobuf(SearchWsResponse.class);
assertThat(responseOnLeak.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactlyInAnyOrder(Stream.concat(hotspotsInLeakPeriod.stream(), atLeakPeriod.stream()).map(IssueDto::getKey).toArray(String[]::new));
}
use of org.sonarqube.ws.Hotspots.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method returns_first_page_with_100_results_by_default.
@Test
public void returns_first_page_with_100_results_by_default() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
int total = 436;
List<IssueDto> hotspots = IntStream.range(0, total).mapToObj(i -> dbTester.issues().insertHotspot(rule, project, file, t -> t.setLine(i))).collect(toList());
indexIssues();
TestRequest request = newRequest(project);
SearchWsResponse response = request.executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactly(hotspots.stream().limit(100).map(IssueDto::getKey).toArray(String[]::new));
assertThat(response.getPaging().getTotal()).isEqualTo(hotspots.size());
assertThat(response.getPaging().getPageIndex()).isOne();
assertThat(response.getPaging().getPageSize()).isEqualTo(100);
}
Aggregations