diff --git a/src/test/java/org/dependencytrack/notification/publisher/AbstractPublisherTest.java b/src/test/java/org/dependencytrack/notification/publisher/AbstractPublisherTest.java index 1f46b1b45f..cba787320c 100644 --- a/src/test/java/org/dependencytrack/notification/publisher/AbstractPublisherTest.java +++ b/src/test/java/org/dependencytrack/notification/publisher/AbstractPublisherTest.java @@ -215,6 +215,20 @@ public void testInformWithProjectAuditChangeNotification() { .isThrownBy(() -> publisherInstance.inform(PublishContext.from(notification), notification, createConfig())); } + @Test + public void testInformWithEscapedData() { + final var notification = new Notification() + .scope(NotificationScope.SYSTEM) + .group(NotificationGroup.ANALYZER) + .title(NotificationConstants.Title.NOTIFICATION_TEST) + .content("! \" § $ % & / ( ) = ? \\ ' * Ö Ü Ä ®️") + .level(NotificationLevel.ERROR) + .timestamp(LocalDateTime.ofEpochSecond(66666, 666, ZoneOffset.UTC)); + + assertThatNoException() + .isThrownBy(() -> publisherInstance.inform(PublishContext.from(notification), notification, createConfig())); + } + private static Component createComponent(final Project project) { final var component = new Component(); component.setProject(project); diff --git a/src/test/java/org/dependencytrack/notification/publisher/SendMailPublisherTest.java b/src/test/java/org/dependencytrack/notification/publisher/SendMailPublisherTest.java index 192578f1af..1388ac4540 100644 --- a/src/test/java/org/dependencytrack/notification/publisher/SendMailPublisherTest.java +++ b/src/test/java/org/dependencytrack/notification/publisher/SendMailPublisherTest.java @@ -395,6 +395,37 @@ public void testInformWithProjectAuditChangeNotification() { }); } + @Override + public void testInformWithEscapedData() { + super.testInformWithEscapedData(); + + assertThat(greenMail.getReceivedMessages()).satisfiesExactly(message -> { + assertThat(message.getSubject()).isEqualTo("[Dependency-Track] Notification Test"); + assertThat(message.getContent()).isInstanceOf(MimeMultipart.class); + final MimeMultipart content = (MimeMultipart) message.getContent(); + assertThat(content.getCount()).isEqualTo(1); + assertThat(content.getBodyPart(0)).isInstanceOf(MimeBodyPart.class); + assertThat((String) content.getBodyPart(0).getContent()).isEqualToIgnoringNewLines(""" + Notification Test + + -------------------------------------------------------------------------------- + + Level: ERROR + Scope: SYSTEM + Group: ANALYZER + + -------------------------------------------------------------------------------- + + ! " § $ % & / ( ) = ? \\ ' * Ö Ü Ä ®️ + + -------------------------------------------------------------------------------- + + 1970-01-01T18:31:06.000000666 + """); + }); + + } + @Override JsonObjectBuilder extraConfig() { return super.extraConfig()