Search in sources :

Example 6 with VulnerabilityUniqueProjectNotificationContent

use of com.synopsys.integration.alert.provider.blackduck.processor.model.VulnerabilityUniqueProjectNotificationContent in project hub-alert by blackducksoftware.

the class JobNotificationMapperTestIT method testProjectJob.

private void testProjectJob() {
    JobNotificationMapper defaultJobNotificationExtractor = new JobNotificationMapper(processingJobAccessor);
    List<DetailedNotificationContent> notificationWrappers = createNotificationWrappers();
    StatefulAlertPage<FilteredJobNotificationWrapper, RuntimeException> pageMappedNotifications = defaultJobNotificationExtractor.mapJobsToNotifications(notificationWrappers, List.of(FrequencyType.REAL_TIME));
    List<FilteredJobNotificationWrapper> filteredJobNotificationWrappers = pageMappedNotifications.getCurrentModels();
    assertEquals(1, filteredJobNotificationWrappers.size());
    List<NotificationContentWrapper> filterableNotificationWrappers = filteredJobNotificationWrappers.get(0).getJobNotifications();
    assertEquals(1, filterableNotificationWrappers.size());
    NotificationContentWrapper filterableNotificationWrapper = filterableNotificationWrappers.get(0);
    assertEquals(NotificationType.VULNERABILITY.name(), filterableNotificationWrapper.extractNotificationType());
    VulnerabilityUniqueProjectNotificationContent vulnerabilityUniqueProjectNotificationContent = (VulnerabilityUniqueProjectNotificationContent) filterableNotificationWrapper.getNotificationContent();
    assertEquals(PROJECT_NAME_1, vulnerabilityUniqueProjectNotificationContent.getAffectedProjectVersion().getProjectName());
}
Also used : DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) VulnerabilityUniqueProjectNotificationContent(com.synopsys.integration.alert.provider.blackduck.processor.model.VulnerabilityUniqueProjectNotificationContent)

Example 7 with VulnerabilityUniqueProjectNotificationContent

use of com.synopsys.integration.alert.provider.blackduck.processor.model.VulnerabilityUniqueProjectNotificationContent in project hub-alert by blackducksoftware.

the class VulnerabilityNotificationMessageExtractorTest method createBomComponentDetailsTest.

@Test
public void createBomComponentDetailsTest() throws IntegrationException {
    BlackDuckServicesFactory blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
    BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
    Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
    ProjectVersionComponentVersionView projectVersionComponentVersionView = createProjectVersionComponentVersionView(true);
    Mockito.when(blackDuckApiClient.getResponse(Mockito.any(), Mockito.eq(ProjectVersionComponentVersionView.class))).thenReturn(projectVersionComponentVersionView);
    ComponentVersionUpgradeGuidanceView componentVersionUpgradeGuidanceView = createComponentVersionUpgradeGuidanceView();
    // A UrlSingleResponse is needed to Mock the blackDuckApiClient in BlackDuckMessageComponentVersionUpgradeGuidanceService::requestUpgradeGuidanceItems
    UrlSingleResponse<ComponentVersionUpgradeGuidanceView> urlSingleResponse = new UrlSingleResponse<>(new HttpUrl(UPGRADE_GUIDANCE_URL), ComponentVersionUpgradeGuidanceView.class);
    Mockito.when(blackDuckApiClient.getResponse(Mockito.eq(urlSingleResponse))).thenReturn(componentVersionUpgradeGuidanceView);
    VulnerabilityUniqueProjectNotificationContent notificationContent = createVulnerabilityUniqueProjectNotificationContent();
    List<BomComponentDetails> bomComponentDetailsList = extractor.createBomComponentDetails(notificationContent, blackDuckServicesFactory);
    assertEquals(1, bomComponentDetailsList.size());
    BomComponentDetails testBomComponentDetails = bomComponentDetailsList.get(0);
    assertEquals(COMPONENT, testBomComponentDetails.getComponent());
    assertTrue(testBomComponentDetails.getComponentVersion().isPresent());
    assertEquals(COMPONENT_VERSION.getValue(), testBomComponentDetails.getComponentVersion().get().getValue());
    assertEquals(LICENSE_DISPLAY, testBomComponentDetails.getLicense().getValue());
    assertEquals(UsageType.DYNAMICALLY_LINKED.prettyPrint(), testBomComponentDetails.getUsage());
    assertTrue(testBomComponentDetails.getAdditionalAttributes().isEmpty());
    assertTrue(testBomComponentDetails.getRelevantPolicies().isEmpty());
    assertNotNull(testBomComponentDetails.getComponentVulnerabilities());
    assertEquals(3, testBomComponentDetails.getComponentConcerns().size());
    ComponentUpgradeGuidance componentUpgradeGuidance = testBomComponentDetails.getComponentUpgradeGuidance();
    assertTrue(componentUpgradeGuidance.getLongTermUpgradeGuidance().isPresent());
    assertTrue(componentUpgradeGuidance.getShortTermUpgradeGuidance().isPresent());
}
Also used : UrlSingleResponse(com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse) ComponentUpgradeGuidance(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) VulnerabilityUniqueProjectNotificationContent(com.synopsys.integration.alert.provider.blackduck.processor.model.VulnerabilityUniqueProjectNotificationContent) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ComponentVersionUpgradeGuidanceView(com.synopsys.integration.blackduck.api.generated.response.ComponentVersionUpgradeGuidanceView) HttpUrl(com.synopsys.integration.rest.HttpUrl) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) Test(org.junit.jupiter.api.Test)

Example 8 with VulnerabilityUniqueProjectNotificationContent

use of com.synopsys.integration.alert.provider.blackduck.processor.model.VulnerabilityUniqueProjectNotificationContent in project hub-alert by blackducksoftware.

the class VulnerabilityNotificationMessageExtractorTest method createVulnerabilityUniqueProjectNotificationContent.

private VulnerabilityUniqueProjectNotificationContent createVulnerabilityUniqueProjectNotificationContent() {
    AffectedProjectVersion affectedProjectVersion = new AffectedProjectVersion();
    affectedProjectVersion.setProjectName(PROJECT);
    affectedProjectVersion.setProjectVersionName(PROJECT_VERSION);
    affectedProjectVersion.setProjectVersion(PROJECT_VERSION_URL);
    affectedProjectVersion.setComponentIssueUrl(COMPONENT_URL);
    affectedProjectVersion.setBomComponent(COMPONENT_URL);
    VulnerabilitySourceQualifiedId vulnerabilityNew = new VulnerabilitySourceQualifiedId();
    vulnerabilityNew.setSeverity(VulnerabilitySeverityType.CRITICAL.name());
    vulnerabilityNew.setVulnerability(VULNERABILITY_URL);
    VulnerabilitySourceQualifiedId vulnerabilityUpdated = new VulnerabilitySourceQualifiedId();
    vulnerabilityUpdated.setVulnerability(VULNERABILITY_URL);
    VulnerabilitySourceQualifiedId vulnerabilityDeleted = new VulnerabilitySourceQualifiedId();
    vulnerabilityDeleted.setSeverity(VulnerabilitySeverityType.LOW.name());
    vulnerabilityDeleted.setVulnerability(VULNERABILITY_URL);
    VulnerabilityNotificationContent vulnerabilityNotificationContent = new VulnerabilityNotificationContent();
    vulnerabilityNotificationContent.setAffectedProjectVersions(List.of(affectedProjectVersion));
    vulnerabilityNotificationContent.setComponentName(COMPONENT.getValue());
    vulnerabilityNotificationContent.setVersionName(COMPONENT_VERSION.getValue());
    vulnerabilityNotificationContent.setNewVulnerabilityCount(1);
    vulnerabilityNotificationContent.setNewVulnerabilityIds(List.of(vulnerabilityNew));
    vulnerabilityNotificationContent.setUpdatedVulnerabilityCount(1);
    vulnerabilityNotificationContent.setUpdatedVulnerabilityIds(List.of(vulnerabilityUpdated));
    vulnerabilityNotificationContent.setDeletedVulnerabilityCount(1);
    vulnerabilityNotificationContent.setDeletedVulnerabilityIds(List.of(vulnerabilityDeleted));
    VulnerabilityUniqueProjectNotificationContent notificationContent = new VulnerabilityUniqueProjectNotificationContent(vulnerabilityNotificationContent, affectedProjectVersion);
    notificationContent.setComponentVersion(COMPONENT_VERSION_URL);
    return notificationContent;
}
Also used : VulnerabilitySourceQualifiedId(com.synopsys.integration.blackduck.api.manual.component.VulnerabilitySourceQualifiedId) AffectedProjectVersion(com.synopsys.integration.blackduck.api.manual.component.AffectedProjectVersion) VulnerabilityNotificationContent(com.synopsys.integration.blackduck.api.manual.component.VulnerabilityNotificationContent) VulnerabilityUniqueProjectNotificationContent(com.synopsys.integration.alert.provider.blackduck.processor.model.VulnerabilityUniqueProjectNotificationContent)

Example 9 with VulnerabilityUniqueProjectNotificationContent

use of com.synopsys.integration.alert.provider.blackduck.processor.model.VulnerabilityUniqueProjectNotificationContent in project hub-alert by blackducksoftware.

the class JobNotificationMapperTestIT method createVulnerabilityUniqueProjectNotificationContent.

private VulnerabilityUniqueProjectNotificationContent createVulnerabilityUniqueProjectNotificationContent(String projectName) {
    AffectedProjectVersion affectedProjectVersion = new AffectedProjectVersion();
    affectedProjectVersion.setProjectName(projectName);
    return new VulnerabilityUniqueProjectNotificationContent(new VulnerabilityNotificationContent(), affectedProjectVersion);
}
Also used : AffectedProjectVersion(com.synopsys.integration.blackduck.api.manual.component.AffectedProjectVersion) VulnerabilityUniqueProjectNotificationContent(com.synopsys.integration.alert.provider.blackduck.processor.model.VulnerabilityUniqueProjectNotificationContent) VulnerabilityNotificationContent(com.synopsys.integration.blackduck.api.manual.component.VulnerabilityNotificationContent)

Example 10 with VulnerabilityUniqueProjectNotificationContent

use of com.synopsys.integration.alert.provider.blackduck.processor.model.VulnerabilityUniqueProjectNotificationContent in project hub-alert by blackducksoftware.

the class ProcessingJobAccessorTestIT method createVulnerabilityUniqueProjectNotificationContent.

private VulnerabilityUniqueProjectNotificationContent createVulnerabilityUniqueProjectNotificationContent(String projectName) {
    AffectedProjectVersion affectedProjectVersion = new AffectedProjectVersion();
    affectedProjectVersion.setProjectName(projectName);
    return new VulnerabilityUniqueProjectNotificationContent(new VulnerabilityNotificationContent(), affectedProjectVersion);
}
Also used : AffectedProjectVersion(com.synopsys.integration.blackduck.api.manual.component.AffectedProjectVersion) VulnerabilityUniqueProjectNotificationContent(com.synopsys.integration.alert.provider.blackduck.processor.model.VulnerabilityUniqueProjectNotificationContent) VulnerabilityNotificationContent(com.synopsys.integration.blackduck.api.manual.component.VulnerabilityNotificationContent)

Aggregations

VulnerabilityUniqueProjectNotificationContent (com.synopsys.integration.alert.provider.blackduck.processor.model.VulnerabilityUniqueProjectNotificationContent)11 Test (org.junit.jupiter.api.Test)6 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)5 ComponentUpgradeGuidance (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance)5 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)5 VulnerabilityNotificationContent (com.synopsys.integration.blackduck.api.manual.component.VulnerabilityNotificationContent)5 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)5 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)5 HttpUrl (com.synopsys.integration.rest.HttpUrl)5 UrlSingleResponse (com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse)4 ComponentVersionUpgradeGuidanceView (com.synopsys.integration.blackduck.api.generated.response.ComponentVersionUpgradeGuidanceView)4 AffectedProjectVersion (com.synopsys.integration.blackduck.api.manual.component.AffectedProjectVersion)4 ComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView)3 VulnerabilitySourceQualifiedId (com.synopsys.integration.blackduck.api.manual.component.VulnerabilitySourceQualifiedId)3 IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)3 DetailedNotificationContent (com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent)2 VulnerabilityNotificationView (com.synopsys.integration.blackduck.api.manual.view.VulnerabilityNotificationView)2 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)1 NotificationDetailExtractor (com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractor)1 VulnerabilitySeverityType (com.synopsys.integration.blackduck.api.generated.enumeration.VulnerabilitySeverityType)1