Skip to content

Commit

Permalink
Test for escaped Data
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Schauer-Köckeis <[email protected]>
  • Loading branch information
Gepardgame committed Sep 23, 2024
1 parent 81aaa71 commit 014ec6c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 014ec6c

Please sign in to comment.