Search in sources :

Example 6 with ProjectIssueModel

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

the class IssueTrackerModelExtractorTest method extractProjectMessageIssueModelsCommentTest.

@Test
public void extractProjectMessageIssueModelsCommentTest() throws AlertException {
    ProjectMessage projectMessage = Mockito.mock(ProjectMessage.class);
    ExistingIssueDetails<String> existingIssueDetails = new ExistingIssueDetails<>("issue-id", "issue-key", "issue summary", "https://ui-link", IssueStatus.UNKNOWN, IssueCategory.POLICY);
    IssuePolicyDetails policyDetails = new IssuePolicyDetails("A policy", ItemOperation.UPDATE, ComponentConcernSeverity.UNSPECIFIED_UNKNOWN);
    ProjectIssueModel projectIssueModel = ProjectIssueModel.policy(PROVIDER_DETAILS, PROJECT, PROJECT_VERSION, ISSUE_BOM_COMPONENT_DETAILS, policyDetails);
    ActionableIssueSearchResult<String> searchResult = new ActionableIssueSearchResult<>(existingIssueDetails, projectIssueModel, ItemOperation.UPDATE);
    MockIssueTrackerMessageFormatter formatter = MockIssueTrackerMessageFormatter.withIntegerMaxValueLength();
    IssueTrackerSearcher<String> searcher = Mockito.mock(IssueTrackerSearcher.class);
    Mockito.when(searcher.findIssues(Mockito.eq(projectMessage))).thenReturn(List.of(searchResult));
    IssueTrackerModelExtractor<String> extractor = new IssueTrackerModelExtractor<>(formatter, searcher);
    IssueTrackerModelHolder<String> modelHolder = extractor.extractProjectMessageIssueModels(projectMessage, "jobName");
    assertEquals(0, modelHolder.getIssueCreationModels().size());
    assertEquals(0, modelHolder.getIssueTransitionModels().size());
    assertEquals(1, modelHolder.getIssueCommentModels().size());
}
Also used : ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) MockIssueTrackerMessageFormatter(com.synopsys.integration.alert.api.channel.issue.convert.mock.MockIssueTrackerMessageFormatter) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) ActionableIssueSearchResult(com.synopsys.integration.alert.api.channel.issue.search.ActionableIssueSearchResult) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) Test(org.junit.jupiter.api.Test)

Example 7 with ProjectIssueModel

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

the class IssueTrackerCallbackInfoCreatorTest method createCallbackInfoWithProjectVersionUrlTest.

@Test
public void createCallbackInfoWithProjectVersionUrlTest() {
    LinkableItem projectVersionWithUrl = new LinkableItem("Project Version", "A Project Version", "https://project-version-url");
    ProjectIssueModel projectIssueModel = ProjectIssueModel.bom(PROVIDER_DETAILS, TEST_ITEM, projectVersionWithUrl, ISSUE_BOM_COMPONENT_DETAILS);
    IssueTrackerCallbackInfoCreator callbackInfoCreator = new IssueTrackerCallbackInfoCreator();
    Optional<IssueTrackerCallbackInfo> optionalCallbackInfo = callbackInfoCreator.createCallbackInfo(projectIssueModel);
    assertTrue(optionalCallbackInfo.isPresent(), "Expected a callback info to be present because a project-version url was present");
    IssueTrackerCallbackInfo callbackInfo = optionalCallbackInfo.get();
    assertEquals(PROVIDER_DETAILS.getProviderConfigId(), callbackInfo.getProviderConfigId());
    assertEquals(BOM_COMPONENT_DETAILS.getBlackDuckIssuesUrl(), callbackInfo.getCallbackUrl());
    assertEquals(projectVersionWithUrl.getUrl().orElse(null), callbackInfo.getBlackDuckProjectVersionUrl());
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssueTrackerCallbackInfo(com.synopsys.integration.alert.common.channel.issuetracker.message.IssueTrackerCallbackInfo) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) Test(org.junit.jupiter.api.Test)

Example 8 with ProjectIssueModel

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

the class ProjectIssueModelConverterTest method toIssueCommentModelWithEmptyVulnerabilitySeverityTest.

@Test
public void toIssueCommentModelWithEmptyVulnerabilitySeverityTest() {
    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(), List.of(), List.of(), List.of());
    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("None"), "Expected missing vulnerability severity to return Severity Status: None");
}
Also used : 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 9 with ProjectIssueModel

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

the class ProjectIssueModelConverterTest method toIssueCreationModelVulnerabilityTest.

@Test
public void toIssueCreationModelVulnerabilityTest() {
    IssueVulnerabilityModel vuln1 = createIssueVulnerability(ComponentConcernSeverity.MAJOR_HIGH, "CVE-13579", "https://a-url");
    IssueVulnerabilityModel vuln2 = createIssueVulnerability(ComponentConcernSeverity.MAJOR_HIGH, "CVE-24680", "https://a-url");
    IssueVulnerabilityModel vuln3 = createIssueVulnerability(ComponentConcernSeverity.MAJOR_HIGH, "CVE-235711", "https://a-url");
    IssueVulnerabilityModel vuln4 = createIssueVulnerability(ComponentConcernSeverity.MAJOR_HIGH, "CVE-112358", "https://a-url");
    IssueVulnerabilityDetails vulnerabilityDetails = new IssueVulnerabilityDetails(false, List.of(), List.of(vuln1), List.of(vuln2, vuln3, vuln4));
    ProjectIssueModel projectIssueModel = ProjectIssueModel.vulnerability(PROVIDER_DETAILS, PROJECT_ITEM, PROJECT_VERSION_ITEM, ISSUE_BOM_COMPONENT_DETAILS, vulnerabilityDetails);
    IssueCreationModel issueCreationModel = basicIssueCreationModelTest(projectIssueModel);
    assertTrue(issueCreationModel.getTitle().contains(vuln1.getVulnerability().getLabel()), "Expected vulnerability label to be present in the title");
}
Also used : IssueCreationModel(com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) IssueVulnerabilityModel(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityModel) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) Test(org.junit.jupiter.api.Test)

Example 10 with ProjectIssueModel

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

the class ProjectIssueModelConverterTest method toIssueCreationModelWithVulnerabilitySeverityTest.

@Test
public void toIssueCreationModelWithVulnerabilitySeverityTest() {
    MockIssueTrackerMessageFormatter formatter = MockIssueTrackerMessageFormatter.withIntegerMaxValueLength();
    ProjectIssueModelConverter converter = new ProjectIssueModelConverter(formatter);
    IssueVulnerabilityModel vuln = createIssueVulnerability(ComponentConcernSeverity.MAJOR_HIGH, "CVE-13579", "https://a-url");
    IssueVulnerabilityDetails vulnerabilityDetails = new IssueVulnerabilityDetails(false, List.of(), List.of(vuln), 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);
    IssueCreationModel issueCreationModel = converter.toIssueCreationModel(projectIssueModel, "jobName");
    assertTrue(issueCreationModel.getDescription().contains(ComponentConcernSeverity.CRITICAL.getVulnerabilityLabel()), "Expected highest vulnerability severity in the description to be CRITICAL");
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IssueCreationModel(com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel) 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) MockIssueTrackerMessageFormatter(com.synopsys.integration.alert.api.channel.issue.convert.mock.MockIssueTrackerMessageFormatter) ComponentVulnerabilities(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentVulnerabilities) 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