use of com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails in project hub-alert by blackducksoftware.
the class PolicyOverrideNotificationMessageExtractorTest method createBomComponentDetailsMissingBomComponentTest.
@Test
public void createBomComponentDetailsMissingBomComponentTest() throws IntegrationException {
BlackDuckServicesFactory blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
Mockito.doThrow(new IntegrationRestException(HttpMethod.GET, new HttpUrl("https://google.com"), HttpStatus.NOT_FOUND.value(), "httpStatusMessageTest", "httpResponseContentTest", "IntegrationRestExceptionForAlertTest")).when(blackDuckApiClient).getResponse(Mockito.any(), Mockito.any());
List<BomComponentDetails> bomComponentDetailsList = extractor.createBomComponentDetails(policyOverrideUniquePolicyNotificationContent, blackDuckServicesFactory);
assertEquals(1, bomComponentDetailsList.size());
BomComponentDetails testBomComponentDetails = bomComponentDetailsList.get(0);
assertEquals(COMPONENT, testBomComponentDetails.getComponent());
assertEquals(1, testBomComponentDetails.getComponentConcerns().size());
assertTrue(testBomComponentDetails.getComponentVersion().isPresent());
assertEquals(COMPONENT_VERSION.getValue(), testBomComponentDetails.getComponentVersion().get().getValue());
assertTrue(testBomComponentDetails.getRelevantPolicies().isEmpty());
assertEquals(BlackDuckMessageLabels.VALUE_UNKNOWN_LICENSE, testBomComponentDetails.getLicense().getValue());
assertEquals(BlackDuckMessageLabels.VALUE_UNKNOWN_USAGE, testBomComponentDetails.getUsage());
}
use of com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails in project hub-alert by blackducksoftware.
the class IssueTrackerSearcherTest method findIssuesProjectIssueModel.
@Test
public void findIssuesProjectIssueModel() throws AlertException {
BomComponentDetails bomComponentDetails = Mockito.mock(BomComponentDetails.class);
ProjectMessage projectMessage = ProjectMessage.componentConcern(PROVIDER_DETAILS, PROJECT_ITEM, PROJECT_VERSION_ITEM, List.of(bomComponentDetails));
ProjectIssueModel projectIssueModel1 = Mockito.mock(ProjectIssueModel.class);
ExistingIssueDetails<String> issue1 = new ExistingIssueDetails<>("issue-1", "issue-1", "issue 1", "https://issue-1", IssueStatus.RESOLVABLE, IssueCategory.POLICY);
IssuePolicyDetails policyDetails = new IssuePolicyDetails("A policy", ItemOperation.DELETE, ComponentConcernSeverity.UNSPECIFIED_UNKNOWN);
ProjectIssueModel projectIssueModel2 = Mockito.mock(ProjectIssueModel.class);
Mockito.when(projectIssueModel2.getPolicyDetails()).thenReturn(Optional.of(policyDetails));
IssueVulnerabilityDetails vulnerabilityDetails = new IssueVulnerabilityDetails(true, List.of(), List.of(), List.of());
ProjectIssueModel projectIssueModel3 = Mockito.mock(ProjectIssueModel.class);
Mockito.when(projectIssueModel3.getVulnerabilityDetails()).thenReturn(Optional.of(vulnerabilityDetails));
ExactIssueFinder<String> exactIssueFinder = Mockito.mock(ExactIssueFinder.class);
Mockito.when(exactIssueFinder.findExistingIssuesByProjectIssueModel(projectIssueModel1)).thenReturn(List.of(issue1));
Mockito.when(exactIssueFinder.findExistingIssuesByProjectIssueModel(projectIssueModel2)).thenReturn(List.of());
ProjectMessageToIssueModelTransformer mockModelTransformer = Mockito.mock(ProjectMessageToIssueModelTransformer.class);
Mockito.when(mockModelTransformer.convertToIssueModels(Mockito.eq(projectMessage))).thenReturn(List.of(projectIssueModel1, projectIssueModel2, projectIssueModel3));
IssueTrackerSearcher<String> searcher = new IssueTrackerSearcher<>(null, null, null, exactIssueFinder, mockModelTransformer);
List<ActionableIssueSearchResult<String>> foundIssues = searcher.findIssues(projectMessage);
assertEquals(1, foundIssues.size());
ActionableIssueSearchResult<String> foundIssue = foundIssues.get(0);
assertEquals(issue1, foundIssue.getExistingIssueDetails().orElse(null));
}
use of com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails in project hub-alert by blackducksoftware.
the class IssueTrackerSearcherTest method findIssuesComponentUpdate.
@Test
public void findIssuesComponentUpdate() throws AlertException {
BomComponentDetails bomComponentDetails = Mockito.mock(BomComponentDetails.class);
ProjectMessage projectMessage = ProjectMessage.componentUpdate(PROVIDER_DETAILS, PROJECT_ITEM, PROJECT_VERSION_ITEM, List.of(bomComponentDetails));
ProjectIssueModel projectIssueModel = Mockito.mock(ProjectIssueModel.class);
ProjectIssueSearchResult<String> projectIssueSearchResult = new ProjectIssueSearchResult<>(EXISTING_ISSUE_DETAILS, projectIssueModel);
ProjectVersionComponentIssueFinder<String> componentIssueFinder = Mockito.mock(ProjectVersionComponentIssueFinder.class);
Mockito.when(componentIssueFinder.findIssuesByComponent(Mockito.eq(PROVIDER_DETAILS), Mockito.eq(PROJECT_ITEM), Mockito.eq(PROJECT_VERSION_ITEM), Mockito.eq(bomComponentDetails))).thenReturn(List.of(projectIssueSearchResult));
IssueTrackerSearcher<String> searcher = new IssueTrackerSearcher<>(null, null, componentIssueFinder, null, modelTransformer);
List<ActionableIssueSearchResult<String>> foundIssues = searcher.findIssues(projectMessage);
assertEquals(1, foundIssues.size());
assertSearchResult(foundIssues.get(0), projectIssueModel, ItemOperation.UPDATE);
}
use of com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails in project hub-alert by blackducksoftware.
the class ProjectMessageToIssueModelTransformerTest method convertToIssueModelsForVulnerabilitiesTest.
@Test
public void convertToIssueModelsForVulnerabilitiesTest() {
LinkableItem vulnerabilityItem0 = createVulnerabilityItem("CVE-000");
LinkableItem vulnerabilityItem7 = createVulnerabilityItem("CVE-007");
ComponentConcern vulnConcern0 = ComponentConcern.vulnerability(ItemOperation.ADD, vulnerabilityItem0.getValue(), ComponentConcernSeverity.CRITICAL, vulnerabilityItem0.getUrl().orElse(null));
ComponentConcern vulnConcern7 = ComponentConcern.vulnerability(ItemOperation.DELETE, vulnerabilityItem7.getValue(), ComponentConcernSeverity.MINOR_MEDIUM, vulnerabilityItem7.getUrl().orElse(null));
BomComponentDetails bomComponentDetails = createBomComponentDetails(List.of(vulnConcern0, ComponentConcern.vulnerability(ItemOperation.UPDATE, VULNERABILITY_2.getValue(), ComponentConcernSeverity.MINOR_MEDIUM, VULNERABILITY_2.getUrl().orElse(null)), vulnConcern7));
ProjectMessage projectMessage = ProjectMessage.componentConcern(PROVIDER_DETAILS, PROJECT, PROJECT_VERSION, List.of(bomComponentDetails));
ProjectMessageToIssueModelTransformer modelTransformer = new ProjectMessageToIssueModelTransformer();
List<ProjectIssueModel> vulnerabilityIssueModels = modelTransformer.convertToIssueModels(projectMessage);
assertEquals(1, vulnerabilityIssueModels.size());
ProjectIssueModel policyIssueModel = vulnerabilityIssueModels.get(0);
assertRequiredDetails(policyIssueModel);
Optional<IssueVulnerabilityDetails> optionalIssueVulnerabilityDetails = policyIssueModel.getVulnerabilityDetails();
assertTrue(optionalIssueVulnerabilityDetails.isPresent(), "Expected vulnerability details to be present");
IssueVulnerabilityDetails issueVulnerabilityDetails = optionalIssueVulnerabilityDetails.get();
assertEquals(1, issueVulnerabilityDetails.getVulnerabilitiesAdded().size());
assertEquals(1, issueVulnerabilityDetails.getVulnerabilitiesUpdated().size());
assertEquals(1, issueVulnerabilityDetails.getVulnerabilitiesDeleted().size());
}
use of com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails in project hub-alert by blackducksoftware.
the class ProjectMessageSummarizer method constructMessageDetails.
private List<LinkableItem> constructMessageDetails(ProjectMessage projectMessage) {
List<LinkableItem> details = new LinkedList<>();
details.add(projectMessage.getProject());
projectMessage.getProjectVersion().ifPresent(details::add);
Map<ComponentConcernSummaryGrouping, Integer> groupedConcernCounts = new LinkedHashMap<>();
for (BomComponentDetails bomComponent : projectMessage.getBomComponents()) {
for (ComponentConcern concern : bomComponent.getComponentConcerns()) {
ComponentConcernSummaryGrouping concernKey = new ComponentConcernSummaryGrouping(concern.getType(), concern.getOperation(), concern.getSeverity());
int currentCount = groupedConcernCounts.getOrDefault(concernKey, 0);
Number concernNumericValue = concern.getNumericValue();
int concernCount = (concernNumericValue != null) ? concernNumericValue.intValue() : 1;
groupedConcernCounts.put(concernKey, currentCount + concernCount);
}
}
Map<ComponentConcernSummaryGrouping, Integer> sortedGroupedConcernCountsBySeverity = groupedConcernCounts.entrySet().stream().sorted(Map.Entry.comparingByKey(ComponentConcernSummaryGrouping.getComparator())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, // Merge operation is equivalent to Map::putIfAbsent
(old, newIgnored) -> old, LinkedHashMap::new));
for (Map.Entry<ComponentConcernSummaryGrouping, Integer> groupedConcernCount : sortedGroupedConcernCountsBySeverity.entrySet()) {
ComponentConcernSummaryGrouping concernGrouping = groupedConcernCount.getKey();
String severityLabel = ComponentConcernType.POLICY.equals(concernGrouping.type) ? concernGrouping.severity.getPolicyLabel() : concernGrouping.severity.getVulnerabilityLabel();
String stateTypeString = convertToUppercasePlural(concernGrouping.type);
String stateAdjective = convertToAdjective(concernGrouping.type, concernGrouping.operation);
String label = String.format("(%s) %s %s count", severityLabel, stateTypeString, stateAdjective);
LinkableItem concernDetail = new LinkableItem(label, groupedConcernCount.getValue().toString());
concernDetail.setNumericValueFlag(true);
details.add(concernDetail);
}
return details;
}
Aggregations