Skip to content

Commit

Permalink
Fix failing tests (they relied on a bug fixed in these changes)
Browse files Browse the repository at this point in the history
Signed-off-by: Ralf King <[email protected]>
  • Loading branch information
rkg-mm committed Sep 28, 2024
1 parent 6063384 commit 6428a8f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")));
Expand Down

0 comments on commit 6428a8f

Please sign in to comment.