use of org.sonar.api.rules.RuleType.SECURITY_HOTSPOT 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.sonar.api.rules.RuleType.SECURITY_HOTSPOT 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);
}
use of org.sonar.api.rules.RuleType.SECURITY_HOTSPOT in project sonarqube by SonarSource.
the class SearchActionTest method returns_hotspots_of_specified_project_assigned_to_current_user_if_only_mine_is_set.
@Test
@UseDataProvider("onlyMineParamValues")
public void returns_hotspots_of_specified_project_assigned_to_current_user_if_only_mine_is_set(String onlyMineParameter, boolean shouldFilter) {
ComponentDto project1 = dbTester.components().insertPublicProject();
String assigneeUuid = this.userSessionRule.logIn().registerComponents(project1).getUuid();
indexPermissions();
ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project1));
IssueDto[] assigneeHotspots = IntStream.range(0, 1 + RANDOM.nextInt(10)).mapToObj(i -> {
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
insertHotspot(rule, project1, file1, randomAlphabetic(5));
return insertHotspot(rule, project1, file1, assigneeUuid);
}).toArray(IssueDto[]::new);
indexIssues();
SearchWsResponse allHotspots = newRequest(project1).executeProtobuf(SearchWsResponse.class);
SearchWsResponse userHotspots = newRequest(project1, r -> r.setParam("onlyMine", onlyMineParameter)).executeProtobuf(SearchWsResponse.class);
assertThat(allHotspots.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).contains(Arrays.stream(assigneeHotspots).map(IssueDto::getKey).toArray(String[]::new)).hasSizeGreaterThan(assigneeHotspots.length);
if (shouldFilter) {
assertThat(userHotspots.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsOnly(Arrays.stream(assigneeHotspots).map(IssueDto::getKey).toArray(String[]::new));
} else {
assertThat(userHotspots.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsOnly(allHotspots.getHotspotsList().stream().map(SearchWsResponse.Hotspot::getKey).toArray(String[]::new));
}
}
use of org.sonar.api.rules.RuleType.SECURITY_HOTSPOT in project sonarqube by SonarSource.
the class SearchActionTest method returns_hotspots_of_specified_project.
@Test
public void returns_hotspots_of_specified_project() {
ComponentDto project1 = dbTester.components().insertPublicProject();
ComponentDto project2 = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project1, project2);
indexPermissions();
ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project1));
ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project2));
IssueDto[] hotspots2 = IntStream.range(0, 1 + RANDOM.nextInt(10)).mapToObj(i -> {
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
insertHotspot(project1, file1, rule);
return insertHotspot(project2, file2, rule);
}).toArray(IssueDto[]::new);
indexIssues();
SearchWsResponse responseProject1 = newRequest(project1).executeProtobuf(SearchWsResponse.class);
assertThat(responseProject1.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).doesNotContainAnyElementsOf(Arrays.stream(hotspots2).map(IssueDto::getKey).collect(toList()));
assertThat(responseProject1.getComponentsList()).extracting(Component::getKey).containsOnly(project1.getKey(), file1.getKey());
SearchWsResponse responseProject2 = newRequest(project2).executeProtobuf(SearchWsResponse.class);
assertThat(responseProject2.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsOnly(Arrays.stream(hotspots2).map(IssueDto::getKey).toArray(String[]::new));
assertThat(responseProject2.getComponentsList()).extracting(Component::getKey).containsOnly(project2.getKey(), file2.getKey());
}
use of org.sonar.api.rules.RuleType.SECURITY_HOTSPOT in project sonarqube by SonarSource.
the class SearchActionTest method returns_only_hotspots_to_review_or_reviewed_of_project.
@Test
public void returns_only_hotspots_to_review_or_reviewed_of_project() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
IssueDto[] hotspots = STATUSES.stream().map(status -> {
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
return insertHotspot(rule, project, file, t -> t.setStatus(status));
}).toArray(IssueDto[]::new);
indexIssues();
String[] expectedKeys = Arrays.stream(hotspots).filter(t -> STATUS_REVIEWED.equals(t.getStatus()) || STATUS_TO_REVIEW.equals(t.getStatus())).map(IssueDto::getKey).toArray(String[]::new);
SearchWsResponse response = newRequest(project).executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsOnly(expectedKeys);
}
Aggregations