use of com.synopsys.integration.blackduck.api.manual.component.VulnerabilityNotificationContent in project hub-alert by blackducksoftware.
the class VulnerabilityUniqueProjectNotificationContentTest method getContentFromNotificationContentTest.
@Test
public void getContentFromNotificationContentTest() {
String componentVersionOriginName = "Component Version Origin Name";
String componentVersionOriginId = "Component Version Origin Id";
AffectedProjectVersion affectedProjectVersion = new AffectedProjectVersion();
affectedProjectVersion.setProjectName(PROJECT_NAME);
affectedProjectVersion.setProjectVersionName(PROJECT_VERSION_NAME);
affectedProjectVersion.setProjectVersion(PROJECT_VERSION_URL);
VulnerabilityNotificationContent vulnerabilityNotificationContent = new VulnerabilityNotificationContent();
vulnerabilityNotificationContent.setNewVulnerabilityCount(1);
vulnerabilityNotificationContent.setUpdatedVulnerabilityCount(1);
vulnerabilityNotificationContent.setDeletedVulnerabilityCount(1);
vulnerabilityNotificationContent.setNewVulnerabilityIds(List.of(newVulnerabilityId));
vulnerabilityNotificationContent.setUpdatedVulnerabilityIds(List.of(updatedVulnerabilityId));
vulnerabilityNotificationContent.setDeletedVulnerabilityIds(List.of(deletedVulnerabilityId));
vulnerabilityNotificationContent.setComponentVersion(COMPONENT_VERSION_URL);
vulnerabilityNotificationContent.setComponentName(COMPONENT_NAME);
vulnerabilityNotificationContent.setVersionName(VERSION_NAME);
vulnerabilityNotificationContent.setComponentVersionOriginName(componentVersionOriginName);
vulnerabilityNotificationContent.setAffectedProjectVersions(List.of(affectedProjectVersion));
vulnerabilityNotificationContent.setComponentVersionOriginId(componentVersionOriginId);
VulnerabilityUniqueProjectNotificationContent notificationContent = new VulnerabilityUniqueProjectNotificationContent(vulnerabilityNotificationContent, affectedProjectVersion);
performAssertions(notificationContent, affectedProjectVersion);
}
use of com.synopsys.integration.blackduck.api.manual.component.VulnerabilityNotificationContent in project hub-alert by blackducksoftware.
the class VulnerabilityUniqueProjectNotificationContentTest method getContentTest.
@Test
public void getContentTest() {
AffectedProjectVersion affectedProjectVersion = new AffectedProjectVersion();
affectedProjectVersion.setProjectName(PROJECT_NAME);
affectedProjectVersion.setProjectVersionName(PROJECT_VERSION_NAME);
affectedProjectVersion.setProjectVersion(PROJECT_VERSION_URL);
VulnerabilityNotificationContent vulnerabilityNotificationContent = new VulnerabilityNotificationContent();
VulnerabilityUniqueProjectNotificationContent notificationContent = new VulnerabilityUniqueProjectNotificationContent(vulnerabilityNotificationContent, affectedProjectVersion);
notificationContent.setNewVulnerabilityIds(List.of(newVulnerabilityId));
notificationContent.setUpdatedVulnerabilityIds(List.of(updatedVulnerabilityId));
notificationContent.setDeletedVulnerabilityIds(List.of(deletedVulnerabilityId));
notificationContent.setComponentVersion(COMPONENT_VERSION_URL);
notificationContent.setComponentName(COMPONENT_NAME);
notificationContent.setVersionName(VERSION_NAME);
notificationContent.setAffectedProjectVersion(affectedProjectVersion);
performAssertions(notificationContent, affectedProjectVersion);
}
use of com.synopsys.integration.blackduck.api.manual.component.VulnerabilityNotificationContent in project hub-alert by blackducksoftware.
the class VulnerabilityNotificationDetailExtractor method extractDetailedContent.
@Override
public List<DetailedNotificationContent> extractDetailedContent(AlertNotificationModel alertNotificationModel, VulnerabilityNotificationView notificationView) {
VulnerabilityNotificationContent notificationContent = notificationView.getContent();
List<String> applicableSeverityTypes = new LinkedList<>(getApplicableSeverityTypes(notificationContent));
// Separating this notification to be per project should fix a bug with alerts being sent about unrelated projects
return notificationContent.getAffectedProjectVersions().stream().map(affectedProjectVersion -> new VulnerabilityUniqueProjectNotificationContent(notificationContent, affectedProjectVersion)).map(vulnerabilityUniqueProjectNotificationContent -> DetailedNotificationContent.vulnerability(// This leaves the AlertNotificationModel as the original but modifies the NotificationContent field
alertNotificationModel, vulnerabilityUniqueProjectNotificationContent, vulnerabilityUniqueProjectNotificationContent.getAffectedProjectVersion().getProjectName(), vulnerabilityUniqueProjectNotificationContent.getAffectedProjectVersion().getProjectVersionName(), applicableSeverityTypes)).collect(Collectors.toList());
}
use of com.synopsys.integration.blackduck.api.manual.component.VulnerabilityNotificationContent in project hub-alert by blackducksoftware.
the class VulnerabilityNotificationDetailExtractorTest method verifyExtraction.
@Test
public void verifyExtraction() throws IOException {
VulnerabilityNotificationView vulnerabilityNotificationView = getVulnerabilityNotificationView(VULNERABILITY_COMPLEX_JSON_PATH);
VulnerabilityNotificationContent content = vulnerabilityNotificationView.getContent();
VulnerabilityNotificationDetailExtractor vulnerabilityNotificationDetailExtractor = new VulnerabilityNotificationDetailExtractor();
AlertNotificationModel alertNotificationModel = createAlertNotificationModel();
List<DetailedNotificationContent> filterableNotificationWrappers = vulnerabilityNotificationDetailExtractor.extractDetailedContent(alertNotificationModel, vulnerabilityNotificationView);
assertEquals(3, filterableNotificationWrappers.size());
for (DetailedNotificationContent filterableNotificationWrapper : filterableNotificationWrappers) {
NotificationContentWrapper notificationContentWrapper = filterableNotificationWrapper.getNotificationContentWrapper();
assertEquals(NotificationType.VULNERABILITY.name(), notificationContentWrapper.extractNotificationType());
// The Vuln extractor should return a different object structure
assertNotEquals(content, notificationContentWrapper.getNotificationContent());
assertEquals(3, filterableNotificationWrapper.getVulnerabilitySeverities().size());
assertFalse(filterableNotificationWrapper.getVulnerabilitySeverities().contains(VulnerabilitySeverityType.CRITICAL.name()));
assertTrue(filterableNotificationWrapper.getPolicyName().isEmpty(), "Expected no policy name to be present");
}
}
use of com.synopsys.integration.blackduck.api.manual.component.VulnerabilityNotificationContent in project hub-alert by blackducksoftware.
the class NotificationWaitJobTask method isNotificationForNewVulnerabilities.
private boolean isNotificationForNewVulnerabilities(NotificationConfig notificationConfig) {
JsonObject jsonObject = gson.fromJson(notificationConfig.getContent(), JsonObject.class);
JsonElement content = jsonObject.get("content");
VulnerabilityNotificationContent notification = gson.fromJson(content, VulnerabilityNotificationContent.class);
notification.getNewVulnerabilityCount();
return notification.getNewVulnerabilityCount() > 0;
}
Aggregations