Search in sources :

Example 1 with ProjectVersionComponentVersionView

use of com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView in project hub-alert by blackducksoftware.

the class ComponentUnknownVersionNotificationSerializationTest method testNotificationSerialization.

@Test
@Ignore
@Disabled
public void testNotificationSerialization() throws IntegrationException, InterruptedException {
    LocalDateTime searchStartTime = LocalDateTime.now().minusMinutes(1);
    AlertRequestUtility alertRequestUtility = IntegrationPerformanceTestRunner.createAlertRequestUtility(webApplicationContext);
    BlackDuckProviderService blackDuckProviderService = new BlackDuckProviderService(alertRequestUtility, gson);
    configureJob(alertRequestUtility, blackDuckProviderService);
    ExternalId externalId = new ExternalId(Forge.MAVEN);
    externalId.setGroup("commons-fileupload");
    externalId.setName("commons-fileupload");
    Predicate<ProjectVersionComponentVersionView> componentFilter = (component) -> component.getComponentName().equals("Apache Commons FileUpload");
    blackDuckProviderService.triggerBlackDuckNotification(() -> externalId, componentFilter);
    try {
        WaitJobConfig waitJobConfig = new WaitJobConfig(intLogger, "notification serialization test notification wait", 300, searchStartTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(), 20);
        NotificationReceivedWaitJobTask notificationWaitJobTask = new NotificationReceivedWaitJobTask(notificationAccessor, searchStartTime, "Apache Commons FileUpload", null, NotificationType.COMPONENT_UNKNOWN_VERSION);
        WaitJob<Boolean> waitForNotificationToBeProcessed = WaitJob.createSimpleWait(waitJobConfig, notificationWaitJobTask);
        boolean isComplete = waitForNotificationToBeProcessed.waitFor();
        if (isComplete) {
            String notificationContent = notificationWaitJobTask.getNotificationContent().orElseThrow(() -> new IllegalStateException("Expected notification is missing."));
            BlackDuckResponseResolver resolver = blackDuckProviderService.getBlackDuckServicesFactory().getBlackDuckResponseResolver();
            ComponentUnknownVersionNotificationView notificationView = resolver.resolve(notificationContent, ComponentUnknownVersionNotificationView.class);
            assertNotNull(notificationView.getContent());
            assertTrue(StringUtils.isNotBlank(notificationView.getContent().getComponentName()));
            BlackDuckApiClient apiClient = blackDuckProviderService.getBlackDuckServicesFactory().getBlackDuckApiClient();
            Optional<HttpUrl> componentUrl = HttpUrl.createSafely(notificationView.getContent().getBomComponent());
            if (componentUrl.isPresent()) {
                apiClient.delete(componentUrl.get());
            }
        }
    } catch (InterruptedException ex) {
    // if a timeout happens that's ok we are trying to ensure deserialization is correct.
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) IntegrationException(com.synopsys.integration.exception.IntegrationException) DescriptorMocker(com.synopsys.integration.alert.util.DescriptorMocker) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) FrequencyType(com.synopsys.integration.alert.common.enumeration.FrequencyType) BlackDuckResponseResolver(com.synopsys.integration.blackduck.http.transform.subclass.BlackDuckResponseResolver) Disabled(org.junit.jupiter.api.Disabled) StringUtils(org.apache.commons.lang3.StringUtils) TestTags(com.synopsys.integration.alert.test.common.TestTags) HttpUrl(com.synopsys.integration.rest.HttpUrl) BeforeAll(org.junit.jupiter.api.BeforeAll) Gson(com.google.gson.Gson) Map(java.util.Map) Tag(org.junit.jupiter.api.Tag) TestPropertyKey(com.synopsys.integration.alert.test.common.TestPropertyKey) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) WebAppConfiguration(org.springframework.test.context.web.WebAppConfiguration) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) Predicate(java.util.function.Predicate) WebApplicationContext(org.springframework.web.context.WebApplicationContext) TestPropertySource(org.springframework.test.context.TestPropertySource) IntegrationPerformanceTestRunner(com.synopsys.integration.alert.performance.utility.IntegrationPerformanceTestRunner) ApplicationConfiguration(com.synopsys.integration.alert.configuration.ApplicationConfiguration) NotificationType(com.synopsys.integration.blackduck.api.manual.enumeration.NotificationType) ZoneId(java.time.ZoneId) WaitJob(com.synopsys.integration.wait.WaitJob) Test(org.junit.jupiter.api.Test) SlackDescriptor(com.synopsys.integration.alert.channel.slack.descriptor.SlackDescriptor) List(java.util.List) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) DatabaseDataSource(com.synopsys.integration.alert.database.DatabaseDataSource) ChannelKeys(com.synopsys.integration.alert.descriptor.api.model.ChannelKeys) TestProperties(com.synopsys.integration.alert.test.common.TestProperties) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) WaitJobConfig(com.synopsys.integration.wait.WaitJobConfig) Forge(com.synopsys.integration.bdio.model.Forge) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) IntLogger(com.synopsys.integration.log.IntLogger) AlertRequestUtility(com.synopsys.integration.alert.performance.utility.AlertRequestUtility) BlackDuckProviderService(com.synopsys.integration.alert.performance.utility.BlackDuckProviderService) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) ConfigurationManager(com.synopsys.integration.alert.performance.utility.ConfigurationManager) ChannelDescriptor(com.synopsys.integration.alert.common.descriptor.ChannelDescriptor) NotificationAccessor(com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor) Application(com.synopsys.integration.alert.Application) ComponentUnknownVersionNotificationView(com.synopsys.integration.blackduck.api.manual.view.ComponentUnknownVersionNotificationView) Ignore(org.junit.Ignore) ContextConfiguration(org.springframework.test.context.ContextConfiguration) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) BlackDuckResponseResolver(com.synopsys.integration.blackduck.http.transform.subclass.BlackDuckResponseResolver) AlertRequestUtility(com.synopsys.integration.alert.performance.utility.AlertRequestUtility) BlackDuckProviderService(com.synopsys.integration.alert.performance.utility.BlackDuckProviderService) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) HttpUrl(com.synopsys.integration.rest.HttpUrl) WaitJobConfig(com.synopsys.integration.wait.WaitJobConfig) ComponentUnknownVersionNotificationView(com.synopsys.integration.blackduck.api.manual.view.ComponentUnknownVersionNotificationView) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) Ignore(org.junit.Ignore) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Disabled(org.junit.jupiter.api.Disabled)

Example 2 with ProjectVersionComponentVersionView

use of com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView in project hub-alert by blackducksoftware.

the class RuleViolationNotificationMessageExtractorTest method createProjectVersionComponentVersionView.

private ProjectVersionComponentVersionView createProjectVersionComponentVersionView() throws IntegrationException {
    ProjectVersionComponentVersionView projectVersionComponentVersionView = new ProjectVersionComponentVersionView();
    projectVersionComponentVersionView.setComponentName(COMPONENT.getValue());
    projectVersionComponentVersionView.setComponentVersion(COMPONENT_VERSION_URL);
    projectVersionComponentVersionView.setComponentVersionName(COMPONENT_VERSION.getValue());
    projectVersionComponentVersionView.setPolicyStatus(ProjectVersionComponentPolicyStatusType.IN_VIOLATION);
    projectVersionComponentVersionView.setUsages(List.of(UsageType.DYNAMICALLY_LINKED));
    ProjectVersionComponentVersionLicensesView projectVersionComponentVersionLicensesView = new ProjectVersionComponentVersionLicensesView();
    projectVersionComponentVersionLicensesView.setLicense("http://licenseLink");
    projectVersionComponentVersionLicensesView.setLicenseDisplay(LICENSE_DISPLAY);
    projectVersionComponentVersionView.setLicenses(List.of(projectVersionComponentVersionLicensesView));
    ResourceLink resourceLink = new ResourceLink();
    resourceLink.setHref(new HttpUrl("https://someHref"));
    resourceLink.setRel("policy-rules");
    ResourceMetadata meta = new ResourceMetadata();
    meta.setHref(new HttpUrl("https://someUrl"));
    meta.setLinks(List.of(resourceLink));
    projectVersionComponentVersionView.setMeta(meta);
    return projectVersionComponentVersionView;
}
Also used : ProjectVersionComponentVersionLicensesView(com.synopsys.integration.blackduck.api.generated.component.ProjectVersionComponentVersionLicensesView) ResourceLink(com.synopsys.integration.blackduck.api.core.ResourceLink) ResourceMetadata(com.synopsys.integration.blackduck.api.core.ResourceMetadata) HttpUrl(com.synopsys.integration.rest.HttpUrl) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)

Example 3 with ProjectVersionComponentVersionView

use of com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView in project hub-alert by blackducksoftware.

the class RuleViolationNotificationMessageExtractorTest 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();
    Mockito.when(blackDuckApiClient.getResponse(Mockito.any(), Mockito.eq(ProjectVersionComponentVersionView.class))).thenReturn(projectVersionComponentVersionView);
    ComponentPolicyRulesView componentPolicyRulesView = new ComponentPolicyRulesView();
    ResourceMetadata meta = new ResourceMetadata();
    meta.setHref(new HttpUrl(COMPONENT_POLICY_URL));
    componentPolicyRulesView.setMeta(meta);
    componentPolicyRulesView.setName(COMPONENT_POLICY.getPolicyName());
    componentPolicyRulesView.setSeverity(PolicyRuleSeverityType.BLOCKER);
    componentPolicyRulesView.setPolicyApprovalStatus(ProjectVersionComponentPolicyStatusType.IN_VIOLATION_OVERRIDDEN);
    Mockito.when(blackDuckApiClient.getAllResponses(Mockito.eq(projectVersionComponentVersionView.metaPolicyRulesLink()))).thenReturn(List.of(componentPolicyRulesView));
    PolicyRuleView policyRuleView = new PolicyRuleView();
    policyRuleView.setCategory(PolicyRuleCategoryType.UNCATEGORIZED);
    Mockito.when(blackDuckApiClient.getResponse(Mockito.any(), Mockito.eq(PolicyRuleView.class))).thenReturn(policyRuleView);
    RuleViolationUniquePolicyNotificationContent notificationContent = new RuleViolationUniquePolicyNotificationContent(PROJECT, PROJECT_VERSION, PROJECT_VERSION_URL, COMPONENT_VERSIONS_IN_VIOLATION, List.of(componentVersionStatus), policyInfo);
    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());
    assertEquals(1, testBomComponentDetails.getComponentConcerns().size());
    assertEquals(ItemOperation.ADD, testBomComponentDetails.getComponentConcerns().get(0).getOperation());
    ComponentUpgradeGuidance componentUpgradeGuidance = testBomComponentDetails.getComponentUpgradeGuidance();
    assertFalse(componentUpgradeGuidance.getLongTermUpgradeGuidance().isPresent());
    assertFalse(componentUpgradeGuidance.getShortTermUpgradeGuidance().isPresent());
    assertEquals(1, testBomComponentDetails.getRelevantPolicies().size());
    ComponentPolicy testComponentPolicy = testBomComponentDetails.getRelevantPolicies().get(0);
    assertTrue(testComponentPolicy.getCategory().isPresent());
    assertEquals(PolicyRuleCategoryType.UNCATEGORIZED.toString(), testComponentPolicy.getCategory().get());
}
Also used : ComponentPolicyRulesView(com.synopsys.integration.blackduck.api.generated.view.ComponentPolicyRulesView) ComponentUpgradeGuidance(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance) RuleViolationUniquePolicyNotificationContent(com.synopsys.integration.alert.provider.blackduck.processor.model.RuleViolationUniquePolicyNotificationContent) ComponentPolicy(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentPolicy) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) PolicyRuleView(com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ResourceMetadata(com.synopsys.integration.blackduck.api.core.ResourceMetadata) 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 4 with ProjectVersionComponentVersionView

use of com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView in project hub-alert by blackducksoftware.

the class BlackDuckMessageLinkUtilsTest method createProjectVersionComponentsLinkTest.

@Test
public void createProjectVersionComponentsLinkTest() throws IntegrationException {
    String expectUrl = EXAMPLE_BLACKDUCK_PROJECT_VERSION_URL + BlackDuckMessageLinkUtils.URI_PIECE_COMPONENTS;
    String inputUrl = expectUrl + "/bb9a56d3-8a48-43fd-8db1-5a7529b857f0/versions/9b36b6b4-8221-4071-8685-8c567d68e90e/licenses/7cae335f-1193-421e-92f1-8802b4243e93";
    HttpUrl inputHttpUrl = new HttpUrl(inputUrl);
    ProjectVersionComponentVersionView bomComponent = Mockito.mock(ProjectVersionComponentVersionView.class);
    Mockito.when(bomComponent.getHref()).thenReturn(inputHttpUrl);
    String projectVersionComponentsLink = BlackDuckMessageLinkUtils.createProjectVersionComponentsLink(bomComponent);
    assertEquals(expectUrl, projectVersionComponentsLink);
}
Also used : HttpUrl(com.synopsys.integration.rest.HttpUrl) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) Test(org.junit.jupiter.api.Test)

Example 5 with ProjectVersionComponentVersionView

use of com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView in project hub-alert by blackducksoftware.

the class VulnerabilityNotificationMessageExtractorTest method createProjectVersionComponentVersionView.

private ProjectVersionComponentVersionView createProjectVersionComponentVersionView(boolean withOrigin) throws IntegrationException {
    ProjectVersionComponentVersionView projectVersionComponentVersionView = new ProjectVersionComponentVersionView();
    projectVersionComponentVersionView.setComponentName(COMPONENT.getValue());
    projectVersionComponentVersionView.setComponentVersion(COMPONENT_VERSION_URL);
    projectVersionComponentVersionView.setComponentVersionName(COMPONENT_VERSION.getValue());
    projectVersionComponentVersionView.setPolicyStatus(ProjectVersionComponentPolicyStatusType.IN_VIOLATION);
    projectVersionComponentVersionView.setUsages(List.of(UsageType.DYNAMICALLY_LINKED));
    ProjectVersionComponentVersionLicensesView projectVersionComponentVersionLicensesView = new ProjectVersionComponentVersionLicensesView();
    projectVersionComponentVersionLicensesView.setLicense("http://licenseLink");
    projectVersionComponentVersionLicensesView.setLicenseDisplay(LICENSE_DISPLAY);
    projectVersionComponentVersionView.setLicenses(List.of(projectVersionComponentVersionLicensesView));
    ResourceLink resourceLink = new ResourceLink();
    resourceLink.setHref(new HttpUrl("https://policyRulesLink"));
    resourceLink.setRel("policy-rules");
    ResourceMetadata meta = new ResourceMetadata();
    meta.setHref(new HttpUrl("https://bomComponentHref"));
    meta.setLinks(List.of(resourceLink));
    projectVersionComponentVersionView.setMeta(meta);
    ResourceLink resourceLinkUpgradeGuidance = new ResourceLink();
    resourceLinkUpgradeGuidance.setHref(new HttpUrl(UPGRADE_GUIDANCE_URL));
    resourceLinkUpgradeGuidance.setRel("upgrade-guidance");
    ResourceMetadata metaUpgradeGuidance = new ResourceMetadata();
    metaUpgradeGuidance.setHref(new HttpUrl("https://upgradeGuidance"));
    metaUpgradeGuidance.setLinks(List.of(resourceLinkUpgradeGuidance));
    RiskProfileView riskProfileView = new RiskProfileView();
    RiskProfileCountsView riskProfileCountsView = new RiskProfileCountsView();
    riskProfileCountsView.setCount(BigDecimal.ONE);
    riskProfileCountsView.setCountType(RiskPriorityType.HIGH);
    riskProfileView.setCounts(List.of(riskProfileCountsView));
    projectVersionComponentVersionView.setSecurityRiskProfile(riskProfileView);
    if (withOrigin) {
        VersionBomOriginView versionBomOriginView = new VersionBomOriginView();
        versionBomOriginView.setMeta(metaUpgradeGuidance);
        projectVersionComponentVersionView.setOrigins(List.of(versionBomOriginView));
    } else {
        projectVersionComponentVersionView.setOrigins(List.of());
    }
    return projectVersionComponentVersionView;
}
Also used : RiskProfileCountsView(com.synopsys.integration.blackduck.api.generated.component.RiskProfileCountsView) VersionBomOriginView(com.synopsys.integration.blackduck.api.manual.temporary.component.VersionBomOriginView) RiskProfileView(com.synopsys.integration.blackduck.api.generated.view.RiskProfileView) ProjectVersionComponentVersionLicensesView(com.synopsys.integration.blackduck.api.generated.component.ProjectVersionComponentVersionLicensesView) ResourceLink(com.synopsys.integration.blackduck.api.core.ResourceLink) ResourceMetadata(com.synopsys.integration.blackduck.api.core.ResourceMetadata) HttpUrl(com.synopsys.integration.rest.HttpUrl) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)

Aggregations

ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)34 HttpUrl (com.synopsys.integration.rest.HttpUrl)24 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)17 Test (org.junit.jupiter.api.Test)17 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)11 ResourceMetadata (com.synopsys.integration.blackduck.api.core.ResourceMetadata)11 ComponentUpgradeGuidance (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance)9 ProjectVersionComponentVersionLicensesView (com.synopsys.integration.blackduck.api.generated.component.ProjectVersionComponentVersionLicensesView)9 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)9 ResourceLink (com.synopsys.integration.blackduck.api.core.ResourceLink)6 BlackDuckMessageBomComponentDetailsCreator (com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckMessageBomComponentDetailsCreator)5 IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)5 ComponentConcern (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern)4 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)3 ComponentPolicy (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentPolicy)3 ComponentPolicyRulesView (com.synopsys.integration.blackduck.api.generated.view.ComponentPolicyRulesView)3 PolicyRuleView (com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView)3 ArrayList (java.util.ArrayList)3 BlackDuckProviderKey (com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey)2 NotificationExtractorBlackDuckServicesFactoryCache (com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache)2