diff --git a/src/main/java/org/dependencytrack/resources/v1/NotificationPublisherResource.java b/src/main/java/org/dependencytrack/resources/v1/NotificationPublisherResource.java index da1dc8aa6..906157953 100644 --- a/src/main/java/org/dependencytrack/resources/v1/NotificationPublisherResource.java +++ b/src/main/java/org/dependencytrack/resources/v1/NotificationPublisherResource.java @@ -283,14 +283,18 @@ public Response restoreDefaultTemplates() { ) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Test notification dispatched successfully"), - @ApiResponse(responseCode = "401", description = "Unauthorized") + @ApiResponse(responseCode = "401", description = "Unauthorized"), + @ApiResponse(responseCode = "404", description = "Notification rule not found") }) @PermissionRequired(Permissions.Constants.SYSTEM_CONFIGURATION) - public Response testSlackPublisherConfig( + public Response testNotificationRule( @Parameter(description = "The UUID of the rule to test", schema = @Schema(type = "string", format = "uuid"), required = true) @PathParam("uuid") @ValidUuid String ruleUuid) { try (QueryManager qm = new QueryManager()) { NotificationRule rule = qm.getObjectByUuid(NotificationRule.class, ruleUuid); + if (rule == null) { + return Response.status(Response.Status.NOT_FOUND).build(); + } final KafkaEventDispatcher eventDispatcher = new KafkaEventDispatcher(); for(NotificationGroup group : rule.getNotifyOn()){ eventDispatcher.dispatchNotification(new Notification() diff --git a/src/test/java/org/dependencytrack/resources/v1/NotificationPublisherResourceTest.java b/src/test/java/org/dependencytrack/resources/v1/NotificationPublisherResourceTest.java index 610bd562a..b0cff0c88 100644 --- a/src/test/java/org/dependencytrack/resources/v1/NotificationPublisherResourceTest.java +++ b/src/test/java/org/dependencytrack/resources/v1/NotificationPublisherResourceTest.java @@ -344,4 +344,12 @@ public void testNotificationRuleTest() { Assert.assertEquals(200, response.getStatus()); assertThat(kafkaMockProducer.history().size()).isEqualTo(11); } + + @Test + public void testNotificationRuleNotFoundTest() { + final Response response = jersey.target(V1_NOTIFICATION_PUBLISHER + "/test/" + UUID.randomUUID()).request() + .header(X_API_KEY, apiKey) + .post(null); + assertThat(response.getStatus()).isEqualTo(404); + } }