Search in sources :

Example 11 with ProjectIssueModel

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

the class ProjectIssueModelConverterTest method toIssueCommentModelWithVulnerabilitySeverityTest.

@Test
public void toIssueCommentModelWithVulnerabilitySeverityTest() {
    IssueVulnerabilityModel vuln1 = createIssueVulnerability(ComponentConcernSeverity.MAJOR_HIGH, "CVE-13579", "https://a-url");
    IssueVulnerabilityDetails vulnerabilityDetails = new IssueVulnerabilityDetails(false, List.of(), List.of(vuln1), List.of());
    ComponentVulnerabilities componentVulnerabilities = new ComponentVulnerabilities(List.of(new LinkableItem("VulnerabilityCritical", "CVE-004")), List.of(new LinkableItem("VulnerabilityHigh", "CVE-005")), List.of(new LinkableItem("VulnerabilityMedium", "CVE-006")), List.of(new LinkableItem("VulnerabilityLow", "CVE-007")));
    AbstractBomComponentDetails vulnerableBomComponentDetails = createBomComponentDetailsWithComponentVulnerabilities(componentVulnerabilities);
    IssueBomComponentDetails issueBomComponentDetails = IssueBomComponentDetails.fromBomComponentDetails(vulnerableBomComponentDetails);
    ProjectIssueModel projectIssueModel = ProjectIssueModel.vulnerability(PROVIDER_DETAILS, PROJECT_ITEM, PROJECT_VERSION_ITEM, issueBomComponentDetails, vulnerabilityDetails);
    MockIssueTrackerMessageFormatter formatter = MockIssueTrackerMessageFormatter.withIntegerMaxValueLength();
    ProjectIssueModelConverter converter = new ProjectIssueModelConverter(formatter);
    IssueCommentModel<String> issueCommentModel = converter.toIssueCommentModel(EXISTING_ISSUE_DETAILS, projectIssueModel);
    assertEquals(1, issueCommentModel.getComments().size());
    String comments = issueCommentModel.getComments().get(0);
    assertTrue(comments.contains(ComponentConcernSeverity.CRITICAL.getVulnerabilityLabel()), "Expected highest vulnerability severity in the comment to be CRITICAL");
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) IssueBomComponentDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails) AbstractBomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.AbstractBomComponentDetails) IssueVulnerabilityModel(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityModel) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) ComponentVulnerabilities(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentVulnerabilities) MockIssueTrackerMessageFormatter(com.synopsys.integration.alert.api.channel.issue.convert.mock.MockIssueTrackerMessageFormatter) Test(org.junit.jupiter.api.Test)

Example 12 with ProjectIssueModel

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

the class ProjectIssueModelConverterTest method toIssueCommentModelTest.

@Test
public void toIssueCommentModelTest() {
    ProjectIssueModel projectIssueModel = ProjectIssueModel.bom(PROVIDER_DETAILS, PROJECT_ITEM, PROJECT_VERSION_ITEM, ISSUE_BOM_COMPONENT_DETAILS);
    MockIssueTrackerMessageFormatter formatter = MockIssueTrackerMessageFormatter.withIntegerMaxValueLength();
    ProjectIssueModelConverter converter = new ProjectIssueModelConverter(formatter);
    IssueCommentModel<String> issueCommentModel = converter.toIssueCommentModel(EXISTING_ISSUE_DETAILS, projectIssueModel);
    assertEquals(EXISTING_ISSUE_DETAILS, issueCommentModel.getExistingIssueDetails());
    assertEquals(projectIssueModel, issueCommentModel.getSource().orElse(null));
    assertTrue(issueCommentModel.getComments().size() > 0, "Expected non-zero number of comments");
}
Also used : ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) MockIssueTrackerMessageFormatter(com.synopsys.integration.alert.api.channel.issue.convert.mock.MockIssueTrackerMessageFormatter) Test(org.junit.jupiter.api.Test)

Example 13 with ProjectIssueModel

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

the class IssueCategoryRetrieverTest method retrieveIssueCategoryFromProjectIssueModel_PolicyTest.

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

Example 14 with ProjectIssueModel

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

the class ProjectMessageToIssueModelTransformerTest method convertToIssueModelsForPolicyTest.

@Test
public void convertToIssueModelsForPolicyTest() {
    ComponentConcern policyConcern = ComponentConcern.policy(ItemOperation.ADD, COMPONENT_POLICY_1.getPolicyName(), "https://policy");
    BomComponentDetails bomComponentDetails = createBomComponentDetails(policyConcern);
    ProjectMessage projectMessage = ProjectMessage.componentConcern(PROVIDER_DETAILS, PROJECT, PROJECT_VERSION, List.of(bomComponentDetails));
    ProjectMessageToIssueModelTransformer modelTransformer = new ProjectMessageToIssueModelTransformer();
    List<ProjectIssueModel> policyIssueModels = modelTransformer.convertToIssueModels(projectMessage);
    assertEquals(1, policyIssueModels.size());
    ProjectIssueModel policyIssueModel = policyIssueModels.get(0);
    assertRequiredDetails(policyIssueModel);
    Optional<IssuePolicyDetails> optionalPolicyDetails = policyIssueModel.getPolicyDetails();
    assertTrue(optionalPolicyDetails.isPresent(), "Expected policy details to be present");
    IssuePolicyDetails policyDetails = optionalPolicyDetails.get();
    assertEquals(policyConcern.getName(), policyDetails.getName());
    assertEquals(policyConcern.getOperation(), policyDetails.getOperation());
    assertEquals(policyConcern.getSeverity(), policyDetails.getSeverity());
}
Also used : ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) 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 15 with ProjectIssueModel

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

the class ProjectMessageToIssueModelTransformerTest method convertToIssueModelsForComponentUnknownVersionTest.

@Test
public void convertToIssueModelsForComponentUnknownVersionTest() {
    ComponentConcern unknownComponentConcern = ComponentConcern.unknownComponentVersion(ItemOperation.ADD, "Component01", ComponentConcernSeverity.MAJOR_HIGH, 2, "https://synopsys.com");
    BomComponentDetails bomComponentDetails = createBomComponentDetails(unknownComponentConcern);
    ProjectMessage projectMessage = ProjectMessage.componentConcern(PROVIDER_DETAILS, PROJECT, PROJECT_VERSION, List.of(bomComponentDetails));
    ProjectMessageToIssueModelTransformer modelTransformer = new ProjectMessageToIssueModelTransformer();
    List<ProjectIssueModel> policyIssueModels = modelTransformer.convertToIssueModels(projectMessage);
    assertEquals(1, policyIssueModels.size());
    ProjectIssueModel unknownVersionIssueModel = policyIssueModels.get(0);
    assertRequiredDetails(unknownVersionIssueModel);
    Optional<IssueComponentUnknownVersionDetails> optionalDetails = unknownVersionIssueModel.getComponentUnknownVersionDetails();
    assertTrue(optionalDetails.isPresent(), "Expected unknown component details to be present");
    IssueComponentUnknownVersionDetails details = optionalDetails.get();
    assertEquals(ItemOperation.ADD, details.getItemOperation());
    assertEquals(1, details.getEstimatedRiskModelList().size());
    IssueEstimatedRiskModel estimatedRiskModel = details.getEstimatedRiskModelList().get(0);
    assertEquals(ComponentConcernSeverity.MAJOR_HIGH, estimatedRiskModel.getSeverity());
    assertEquals("Component01", estimatedRiskModel.getName());
    assertEquals(2, estimatedRiskModel.getCount());
    assertTrue(estimatedRiskModel.getComponentVersionUrl().isPresent());
}
Also used : IssueComponentUnknownVersionDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) IssueEstimatedRiskModel(com.synopsys.integration.alert.api.channel.issue.model.IssueEstimatedRiskModel) 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)

Aggregations

ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)47 Test (org.junit.jupiter.api.Test)29 IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)19 IssuePolicyDetails (com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)17 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)16 IssueVulnerabilityDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails)12 ExistingIssueDetails (com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails)11 ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)11 IssueCreationModel (com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel)10 MockIssueTrackerMessageFormatter (com.synopsys.integration.alert.api.channel.issue.convert.mock.MockIssueTrackerMessageFormatter)8 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)8 ProviderDetails (com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails)6 ComponentVulnerabilities (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentVulnerabilities)6 IssueComponentUnknownVersionDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails)5 ComponentConcernType (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcernType)5 LinkedList (java.util.LinkedList)5 Optional (java.util.Optional)5 IssueVulnerabilityModel (com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityModel)4 ProjectIssueSearchResult (com.synopsys.integration.alert.api.channel.issue.search.ProjectIssueSearchResult)4 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)4