use of org.sonar.api.rules.RuleType.SECURITY_HOTSPOT in project sonarqube by SonarSource.
the class SearchActionTest method returns_hotspots_of_specified_application_branch.
@Test
public void returns_hotspots_of_specified_application_branch() {
ComponentDto application = dbTester.components().insertPublicApplication();
ComponentDto applicationBranch = dbTester.components().insertProjectBranch(application);
ComponentDto project1 = dbTester.components().insertPublicProject();
ComponentDto project2 = dbTester.components().insertPublicProject();
dbTester.components().insertComponent(ComponentTesting.newProjectCopy(project1, application));
dbTester.components().insertComponent(ComponentTesting.newProjectCopy(project2, applicationBranch));
indexViews();
userSessionRule.registerApplication(application, applicationBranch, 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 responseApplication = newRequest(application).executeProtobuf(SearchWsResponse.class);
assertThat(responseApplication.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).doesNotContainAnyElementsOf(Arrays.stream(hotspots2).map(IssueDto::getKey).collect(toList()));
assertThat(responseApplication.getComponentsList()).extracting(Component::getKey).containsOnly(project1.getKey(), file1.getKey());
SearchWsResponse responseApplicationBranch = newRequest(applicationBranch).executeProtobuf(SearchWsResponse.class);
assertThat(responseApplicationBranch.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsOnly(Arrays.stream(hotspots2).map(IssueDto::getKey).toArray(String[]::new));
assertThat(responseApplicationBranch.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_single_component_when_all_hotspots_are_on_project.
@Test
public void returns_single_component_when_all_hotspots_are_on_project() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
IssueDto[] hotspots = IntStream.range(0, 1 + RANDOM.nextInt(10)).mapToObj(i -> {
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
return insertHotspot(project, project, rule);
}).toArray(IssueDto[]::new);
indexIssues();
SearchWsResponse response = newRequest(project).executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList()).extracting(Hotspots.SearchWsResponse.Hotspot::getKey).containsOnly(Arrays.stream(hotspots).map(IssueDto::getKey).toArray(String[]::new));
assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly(project.getKey());
}
use of org.sonar.api.rules.RuleType.SECURITY_HOTSPOT in project sonarqube by SonarSource.
the class SearchActionTest method returns_hotspot_with_secondary_locations.
@Test
public void returns_hotspot_with_secondary_locations() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
ComponentDto anotherFile = dbTester.components().insertComponent(newFileDto(project));
List<DbIssues.Location> hotspotLocations = Stream.of(newHotspotLocation(file.uuid(), "security hotspot flow message 0", 1, 1, 0, 12), newHotspotLocation(file.uuid(), "security hotspot flow message 1", 3, 3, 0, 10), newHotspotLocation(anotherFile.uuid(), "security hotspot flow message 2", 5, 5, 0, 15), newHotspotLocation(anotherFile.uuid(), "security hotspot flow message 3", 7, 7, 0, 18), newHotspotLocation(null, "security hotspot flow message 4", 12, 12, 2, 8)).collect(toList());
DbIssues.Locations.Builder locations = DbIssues.Locations.newBuilder().addFlow(DbIssues.Flow.newBuilder().addAllLocation(hotspotLocations));
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
dbTester.issues().insertHotspot(rule, project, file, h -> h.setLocations(locations.build()));
indexIssues();
SearchWsResponse response = newRequest(project).executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsCount()).isOne();
assertThat(response.getHotspotsList().stream().findFirst().get().getFlowsCount()).isEqualTo(1);
assertThat(response.getHotspotsList().stream().findFirst().get().getFlowsList().stream().findFirst().get().getLocationsCount()).isEqualTo(5);
assertThat(response.getHotspotsList().stream().findFirst().get().getFlowsList().stream().findFirst().get().getLocationsList()).extracting(Common.Location::getComponent, Common.Location::getMsg, l -> l.getTextRange().getStartLine(), l -> l.getTextRange().getEndLine(), l -> l.getTextRange().getStartOffset(), l -> l.getTextRange().getEndOffset()).containsExactlyInAnyOrder(tuple(file.getKey(), "security hotspot flow message 0", 1, 1, 0, 12), tuple(file.getKey(), "security hotspot flow message 1", 3, 3, 0, 10), tuple(anotherFile.getKey(), "security hotspot flow message 2", 5, 5, 0, 15), tuple(anotherFile.getKey(), "security hotspot flow message 3", 7, 7, 0, 18), tuple(file.getKey(), "security hotspot flow message 4", 12, 12, 2, 8));
}
use of org.sonar.api.rules.RuleType.SECURITY_HOTSPOT in project sonarqube by SonarSource.
the class SearchActionTest method returns_specified_hotspots.
@Test
public void returns_specified_hotspots() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
int total = 1 + RANDOM.nextInt(20);
List<IssueDto> hotspots = IntStream.range(0, total).mapToObj(i -> dbTester.issues().insertHotspot(rule, project, file, t -> t.setLine(i))).collect(toList());
Collections.shuffle(hotspots);
List<IssueDto> selectedHotspots = hotspots.stream().limit(total == 1 ? 1 : 1 + RANDOM.nextInt(total - 1)).collect(toList());
indexIssues();
SearchWsResponse response = newRequest(selectedHotspots.stream().map(IssueDto::getKey).collect(toList())).executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactlyInAnyOrder(selectedHotspots.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_empty_if_none_of_hotspot_keys_exist.
@Test
public void returns_empty_if_none_of_hotspot_keys_exist() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
List<IssueDto> hotspots = IntStream.range(0, 1 + RANDOM.nextInt(15)).mapToObj(i -> dbTester.issues().insertHotspot(rule, project, file, t -> t.setLine(i))).collect(toList());
indexIssues();
SearchWsResponse response = newRequest(IntStream.range(0, 1 + RANDOM.nextInt(30)).mapToObj(i -> "key_" + i).collect(toList())).executeProtobuf(SearchWsResponse.class);
verify(issueIndexSyncProgressChecker).checkIfIssueSyncInProgress(any());
assertThat(response.getHotspotsList()).isEmpty();
}
Aggregations