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");
}
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");
}
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);
}
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());
}
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());
}
Aggregations