Skip to content

Commit

Permalink
Merge pull request #3305 from nscuro/issue-3296
Browse files Browse the repository at this point in the history
Fix notifications not being sent for child projects where `active` is `null`
  • Loading branch information
nscuro authored Dec 15, 2023
2 parents 8de3533 + c20354b commit f12c028
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ private boolean checkIfChildrenAreAffected(Project parent, UUID uuid) {
return false;
}
for (Project child : parent.getChildren()) {
if ((child.getUuid().equals(uuid) && Boolean.TRUE.equals(child.isActive())) || isChild) {
final boolean isChildActive = child.isActive() == null || child.isActive();
if ((child.getUuid().equals(uuid) && isChildActive) || isChild) {
return true;
}
isChild = checkIfChildrenAreAffected(child, uuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,42 @@ public void testAffectedInactiveChild() {
Assert.assertEquals(0, rules.size());
}


@Test
public void testAffectedActiveNullChild() {
NotificationPublisher publisher = createSlackPublisher();
// Creates a new rule and defines when the rule should be triggered (notifyOn)
NotificationRule rule = qm.createNotificationRule("Matching Test Rule", NotificationScope.PORTFOLIO, NotificationLevel.INFORMATIONAL, publisher);
Set<NotificationGroup> notifyOn = new HashSet<>();
notifyOn.add(NotificationGroup.NEW_VULNERABILITY);
rule.setNotifyOn(notifyOn);
// Creates a project which will later be matched on
List<Project> projects = new ArrayList<>();
Project grandParent = qm.createProject("Test Project Grandparent", null, "1.0", null, null, null, true, false);
Project parent = qm.createProject("Test Project Parent", null, "1.0", null, grandParent, null, true, false);
Project child = qm.createProject("Test Project Child", null, "1.0", null, parent, null, true, false);
Project grandChild = qm.createProject("Test Project Grandchild", null, "1.0", null, child, null, true, false);
grandChild.setActive(null); // https://github.com/DependencyTrack/dependency-track/issues/3296
projects.add(grandParent);
rule.setProjects(projects);
// Creates a new component
Component component = new Component();
component.setProject(grandChild);
// Creates a new notification
Notification notification = new Notification();
notification.setScope(NotificationScope.PORTFOLIO.name());
notification.setGroup(NotificationGroup.NEW_VULNERABILITY.name());
notification.setLevel(NotificationLevel.INFORMATIONAL);
// Notification should be limited to only specific projects - Set the projects which are affected by the notification event
Set<Project> affectedProjects = new HashSet<>();
affectedProjects.add(grandChild);
NewVulnerabilityIdentified subject = new NewVulnerabilityIdentified(new Vulnerability(), component, affectedProjects, null);
notification.setSubject(subject);
// Ok, let's test this
NotificationRouter router = new NotificationRouter();
List<NotificationRule> rules = router.resolveRules(PublishContext.from(notification), notification);
Assert.assertTrue(rule.isNotifyChildren());
Assert.assertEquals(1, rules.size());
}

private NotificationPublisher createSlackPublisher() {
return qm.createNotificationPublisher(
Expand Down

0 comments on commit f12c028

Please sign in to comment.