Search in sources :

Example 11 with IssueVulnerabilityDetails

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

Example 12 with IssueVulnerabilityDetails

use of com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails 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 13 with IssueVulnerabilityDetails

use of com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails in project hub-alert by blackducksoftware.

the class IssueTrackerSearcher method findIssueByProjectIssueModel.

private ActionableIssueSearchResult<T> findIssueByProjectIssueModel(ProjectIssueModel projectIssueModel) throws AlertException {
    ExistingIssueDetails<T> existingIssue = null;
    ItemOperation searchResultOperation = ItemOperation.UPDATE;
    List<ExistingIssueDetails<T>> existingIssues = exactIssueFinder.findExistingIssuesByProjectIssueModel(projectIssueModel);
    int foundIssuesCount = existingIssues.size();
    if (foundIssuesCount == 1) {
        existingIssue = existingIssues.get(0);
        Optional<ItemOperation> policyOperation = projectIssueModel.getPolicyDetails().map(IssuePolicyDetails::getOperation);
        Optional<IssueVulnerabilityDetails> optionalVulnerabilityDetails = projectIssueModel.getVulnerabilityDetails();
        Optional<ItemOperation> componentUnknownOperation = projectIssueModel.getComponentUnknownVersionDetails().map(IssueComponentUnknownVersionDetails::getItemOperation);
        if (policyOperation.isPresent()) {
            searchResultOperation = policyOperation.get();
        } else if (optionalVulnerabilityDetails.isPresent()) {
            IssueVulnerabilityDetails issueVulnerabilityDetails = optionalVulnerabilityDetails.get();
            searchResultOperation = findVulnerabilitySearchResultOperation(existingIssue, issueVulnerabilityDetails);
        } else if (componentUnknownOperation.isPresent()) {
            searchResultOperation = componentUnknownOperation.get();
        }
    } else if (foundIssuesCount > 1) {
        Set<String> issueKeys = existingIssues.stream().map(ExistingIssueDetails::getIssueKey).collect(Collectors.toSet());
        String issueKeyString = StringUtils.join(issueKeys, ", ");
        throw new AlertException("Expected to find a unique issue, but more than one was found. " + issueKeyString);
    } else {
        searchResultOperation = ItemOperation.ADD;
    }
    return new ActionableIssueSearchResult<>(existingIssue, projectIssueModel, searchResultOperation);
}
Also used : IssueComponentUnknownVersionDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails) Set(java.util.Set) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) ItemOperation(com.synopsys.integration.alert.common.enumeration.ItemOperation) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 14 with IssueVulnerabilityDetails

use of com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails in project hub-alert by blackducksoftware.

the class IssueCategoryRetrieverTest method retrieveIssueCategoryFromProjectIssueModel_VulnerabilityTest.

@Test
public void retrieveIssueCategoryFromProjectIssueModel_VulnerabilityTest() {
    IssueVulnerabilityDetails issueVulnerabilityDetails = Mockito.mock(IssueVulnerabilityDetails.class);
    ProjectIssueModel projectIssueModel = Mockito.mock(ProjectIssueModel.class);
    Mockito.when(projectIssueModel.getPolicyDetails()).thenReturn(Optional.empty());
    Mockito.when(projectIssueModel.getVulnerabilityDetails()).thenReturn(Optional.of(issueVulnerabilityDetails));
    IssueCategoryRetriever issueCategoryRetriever = new IssueCategoryRetriever();
    IssueCategory issueCategory = issueCategoryRetriever.retrieveIssueCategoryFromProjectIssueModel(projectIssueModel);
    assertEquals(IssueCategory.VULNERABILITY, issueCategory);
}
Also used : IssueCategory(com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueCategory) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) Test(org.junit.jupiter.api.Test)

Aggregations

IssueVulnerabilityDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails)14 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)10 IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)8 Test (org.junit.jupiter.api.Test)8 IssuePolicyDetails (com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)6 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)6 IssueVulnerabilityModel (com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityModel)5 ComponentVulnerabilities (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentVulnerabilities)5 IssueComponentUnknownVersionDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails)4 IssueCreationModel (com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel)4 ItemOperation (com.synopsys.integration.alert.common.enumeration.ItemOperation)4 MockIssueTrackerMessageFormatter (com.synopsys.integration.alert.api.channel.issue.convert.mock.MockIssueTrackerMessageFormatter)3 AbstractBomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.AbstractBomComponentDetails)3 ExistingIssueDetails (com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails)2 IssueCategory (com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueCategory)2 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)2 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)2 ComponentConcern (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern)2 ComponentConcernType (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType)2 ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)2