From 6428a8f01ef47a2662e1b1c936ba90027204abe8 Mon Sep 17 00:00:00 2001 From: Ralf King Date: Sat, 28 Sep 2024 23:01:11 +0200 Subject: [PATCH] Fix failing tests (they relied on a bug fixed in these changes) Signed-off-by: Ralf King --- .../policy/PolicyEngineTest.java | 8 +++++-- .../tasks/scanners/TrivyAnalysisTaskTest.java | 21 ++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/test/java/org/dependencytrack/policy/PolicyEngineTest.java b/src/test/java/org/dependencytrack/policy/PolicyEngineTest.java index d3c7f7363d..75cb8a068f 100644 --- a/src/test/java/org/dependencytrack/policy/PolicyEngineTest.java +++ b/src/test/java/org/dependencytrack/policy/PolicyEngineTest.java @@ -388,13 +388,17 @@ public void notificationTest() { // Evaluate policies and ensure that a notification has been sent. final var policyEngine = new PolicyEngine(); assertThat(policyEngine.evaluate(List.of(component))).hasSize(1); - assertThat(NOTIFICATIONS).hasSize(1); + assertThat(NOTIFICATIONS).hasSize(2); // Create an additional policy condition that matches on the exact version of the component, // and re-evaluate policies. Ensure that only one notification per newly violated condition was sent. final var policyConditionB = qm.createPolicyCondition(policy, Subject.VERSION, PolicyCondition.Operator.NUMERIC_EQUAL, "1.2.3"); assertThat(policyEngine.evaluate(List.of(component))).hasSize(2); assertThat(NOTIFICATIONS).satisfiesExactly( + notification -> { + assertThat(notification.getScope()).isEqualTo(NotificationScope.PORTFOLIO.name()); + assertThat(notification.getGroup()).isEqualTo(NotificationGroup.PROJECT_CREATED.name()); + }, notification -> { assertThat(notification.getScope()).isEqualTo(NotificationScope.PORTFOLIO.name()); assertThat(notification.getGroup()).isEqualTo(NotificationGroup.POLICY_VIOLATION.name()); @@ -420,7 +424,7 @@ public void notificationTest() { // Delete a policy condition and re-evaluate policies again. No new notifications should be sent. qm.deletePolicyCondition(policyConditionA); assertThat(policyEngine.evaluate(List.of(component))).hasSize(1); - assertThat(NOTIFICATIONS).hasSize(2); + assertThat(NOTIFICATIONS).hasSize(3); } @Test diff --git a/src/test/java/org/dependencytrack/tasks/scanners/TrivyAnalysisTaskTest.java b/src/test/java/org/dependencytrack/tasks/scanners/TrivyAnalysisTaskTest.java index 9138cd1eac..fe29c545f5 100644 --- a/src/test/java/org/dependencytrack/tasks/scanners/TrivyAnalysisTaskTest.java +++ b/src/test/java/org/dependencytrack/tasks/scanners/TrivyAnalysisTaskTest.java @@ -38,6 +38,7 @@ import org.dependencytrack.model.Severity; import org.dependencytrack.model.Vulnerability; import org.dependencytrack.notification.NotificationGroup; +import org.dependencytrack.notification.NotificationScope; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -413,13 +414,19 @@ public void testAnalyzeWithConnectionError() { assertThat(qm.getCount(ComponentAnalysisCache.class)).isZero(); - assertThat(NOTIFICATIONS).satisfiesExactly(notification -> { - assertThat(notification.getGroup()).isEqualTo(NotificationGroup.ANALYZER.name()); - assertThat(notification.getLevel()).isEqualTo(NotificationLevel.ERROR); - assertThat(notification.getContent()).isEqualTo(""" - An error occurred while communicating with a vulnerability intelligence source. \ - Check log for details. Connection reset"""); - }); + assertThat(NOTIFICATIONS).satisfiesExactly( + notification -> { + assertThat(notification.getScope()).isEqualTo(NotificationScope.PORTFOLIO.name()); + assertThat(notification.getGroup()).isEqualTo(NotificationGroup.PROJECT_CREATED.name()); + }, + notification -> { + assertThat(notification.getGroup()).isEqualTo(NotificationGroup.ANALYZER.name()); + assertThat(notification.getLevel()).isEqualTo(NotificationLevel.ERROR); + assertThat(notification.getContent()).isEqualTo(""" + An error occurred while communicating with a vulnerability intelligence source. \ + Check log for details. Connection reset"""); + } + ); wireMock.verify(exactly(1), postRequestedFor(urlPathEqualTo("/twirp/trivy.cache.v1.Cache/PutBlob"))); wireMock.verify(exactly(0), postRequestedFor(urlPathEqualTo("/twirp/trivy.scanner.v1.Scanner/Scan")));