Search in sources :

Example 36 with ProjectMessage

use of com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage 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());
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) ComponentConcern(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) Test(org.junit.jupiter.api.Test)

Example 37 with ProjectMessage

use of com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage in project hub-alert by blackducksoftware.

the class IssueTrackerSearcherTest method findIssuesProjectBomDeleted.

@Test
public void findIssuesProjectBomDeleted() throws AlertException {
    ProjectMessage projectMessage = ProjectMessage.projectStatusInfo(PROVIDER_DETAILS, PROJECT_ITEM, ProjectOperation.DELETE);
    ProjectIssueModel projectIssueModel = Mockito.mock(ProjectIssueModel.class);
    ProjectIssueSearchResult<String> projectIssueSearchResult = new ProjectIssueSearchResult<>(EXISTING_ISSUE_DETAILS, projectIssueModel);
    ProjectIssueFinder<String> projectIssueFinder = Mockito.mock(ProjectIssueFinder.class);
    Mockito.when(projectIssueFinder.findProjectIssues(Mockito.eq(PROVIDER_DETAILS), Mockito.eq(PROJECT_ITEM))).thenReturn(List.of(projectIssueSearchResult));
    IssueTrackerSearcher<String> searcher = new IssueTrackerSearcher<>(projectIssueFinder, null, null, null, modelTransformer);
    List<ActionableIssueSearchResult<String>> foundIssues = searcher.findIssues(projectMessage);
    assertEquals(1, foundIssues.size());
    assertSearchResult(foundIssues.get(0), projectIssueModel, ItemOperation.DELETE);
}
Also used : ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) Test(org.junit.jupiter.api.Test)

Example 38 with ProjectMessage

use of com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage in project hub-alert by blackducksoftware.

the class IssueTrackerProcessorTest method processMessagesTest.

@Test
public void processMessagesTest() throws AlertException {
    IssueTrackerModelExtractor<String> extractor = Mockito.mock(IssueTrackerModelExtractor.class);
    IssueTrackerModelHolder<String> simpleMessageResponses = new IssueTrackerModelHolder<>(List.of(), List.of(), List.of());
    Mockito.when(extractor.extractSimpleMessageIssueModels(Mockito.anyList(), Mockito.any())).thenReturn(simpleMessageResponses);
    IssueTrackerIssueResponseModel<String> response1 = Mockito.mock(IssueTrackerIssueResponseModel.class);
    IssueTrackerIssueResponseModel<String> response2 = Mockito.mock(IssueTrackerIssueResponseModel.class);
    IssueTrackerIssueResponseModel<String> response3 = Mockito.mock(IssueTrackerIssueResponseModel.class);
    List<IssueTrackerIssueResponseModel<String>> simpleMessageResponse = List.of(response1, response2, response3);
    IssueTrackerIssueResponseModel<String> response4 = Mockito.mock(IssueTrackerIssueResponseModel.class);
    IssueTrackerIssueResponseModel<String> response5 = Mockito.mock(IssueTrackerIssueResponseModel.class);
    List<IssueTrackerIssueResponseModel<String>> projectMessageResponses = List.of(response4, response5);
    IssueTrackerMessageSender<String> sender = Mockito.mock(IssueTrackerMessageSender.class);
    Mockito.when(sender.sendMessages(Mockito.any())).thenReturn(simpleMessageResponse, projectMessageResponses);
    IssueTrackerProcessor<String> processor = new IssueTrackerProcessor<>(extractor, sender);
    ProjectMessage projectMessage = Mockito.mock(ProjectMessage.class);
    ProviderMessageHolder providerMessageHolder = new ProviderMessageHolder(List.of(projectMessage), List.of());
    IssueTrackerResponse<String> issueTrackerResponse = processor.processMessages(providerMessageHolder, "jobName");
    assertEquals(simpleMessageResponse.size() + projectMessageResponses.size(), issueTrackerResponse.getUpdatedIssues().size());
}
Also used : IssueTrackerIssueResponseModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) IssueTrackerModelHolder(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder) Test(org.junit.jupiter.api.Test)

Example 39 with ProjectMessage

use of com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage 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;
}
Also used : ComponentConcernType(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType) MessageReason(com.synopsys.integration.alert.processor.api.extract.model.project.MessageReason) ComponentConcernSeverity(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernSeverity) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) Collectors(java.util.stream.Collectors) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) LinkedHashMap(java.util.LinkedHashMap) ProcessedProviderMessage(com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessage) List(java.util.List) Component(org.springframework.stereotype.Component) Pair(org.apache.commons.lang3.tuple.Pair) ComponentConcern(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern) ProjectOperation(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectOperation) Map(java.util.Map) ItemOperation(com.synopsys.integration.alert.common.enumeration.ItemOperation) Optional(java.util.Optional) SimpleMessage(com.synopsys.integration.alert.processor.api.extract.model.SimpleMessage) Comparator(java.util.Comparator) LinkedList(java.util.LinkedList) AlertSerializableModel(com.synopsys.integration.alert.api.common.model.AlertSerializableModel) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ComponentConcern(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)

Example 40 with ProjectMessage

use of com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage in project hub-alert by blackducksoftware.

the class ProjectMessageSummarizer method summarize.

public ProcessedProviderMessage<SimpleMessage> summarize(ProcessedProviderMessage<ProjectMessage> digestedProjectMessage) {
    ProjectMessage projectMessage = digestedProjectMessage.getProviderMessage();
    Pair<String, String> summaryAndDescription = constructSummaryAndDescription(projectMessage);
    List<LinkableItem> details = constructMessageDetails(projectMessage);
    SimpleMessage derivedSimpleMessage = SimpleMessage.derived(summaryAndDescription.getLeft(), summaryAndDescription.getRight(), details, projectMessage);
    return new ProcessedProviderMessage<>(digestedProjectMessage.getNotificationIds(), derivedSimpleMessage);
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) ProcessedProviderMessage(com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessage) SimpleMessage(com.synopsys.integration.alert.processor.api.extract.model.SimpleMessage)

Aggregations

ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)45 Test (org.junit.jupiter.api.Test)32 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)22 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)14 ProcessedProviderMessage (com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessage)13 ProjectOperation (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectOperation)13 SimpleMessage (com.synopsys.integration.alert.processor.api.extract.model.SimpleMessage)12 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)11 ComponentConcern (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern)9 ProviderMessageHolder (com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder)7 IssuePolicyDetails (com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)6 ProviderDetails (com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails)5 IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)4 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)4 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)4 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)4 LinkedList (java.util.LinkedList)4 MockIssueTrackerMessageFormatter (com.synopsys.integration.alert.api.channel.issue.convert.mock.MockIssueTrackerMessageFormatter)3 IssueVulnerabilityDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails)3 ActionableIssueSearchResult (com.synopsys.integration.alert.api.channel.issue.search.ActionableIssueSearchResult)3