Skip to content

Commit

Permalink
Fix mail template test (#2715)
Browse files Browse the repository at this point in the history
* fixed thymeleaf template test

* formatting

* fix(MailNotifierIntegrationTest): enhanced tests

* fix missing mail notification image in docs

* removed unused import

* fix missing mail notification image in docs

* fix formatting

---------

Co-authored-by: Stephan Köninger <stephan.koeninger@codecentric.de>
  • Loading branch information
ulischulte and SteKoe committed Aug 25, 2023
1 parent 70caf64 commit 6c6a2e8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -522,4 +522,4 @@ To enable https://www.rocket.chat/[Rocket.Chat] notifications you need a persona
| spring.boot.admin.notify.rocketchat.message
| Text to send. SpEL-expressions are supported.
| `+++"*#{instance.registration.name}* (#{instance.id}) is *#{event.statusInfo.status}*"+++`
|===
|===
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package de.codecentric.boot.admin.server.notify;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;

import org.assertj.core.api.WithAssertions;
Expand Down Expand Up @@ -49,19 +48,28 @@ void fileProtocolIsNotAllowed() {
@Test
void httpProtocolIsNotAllowed() {
assertThatThrownBy(() -> {
URL resource = getClass().getClassLoader().getResource(".");
mailNotifier.setTemplate(
"https://raw.githubusercontent.com/codecentric/spring-boot-admin/gh-pages/vulnerable-file.html");
mailNotifier.getBody(new Context());
}).hasCauseInstanceOf(FileNotFoundException.class);
}

@Test
void classpathProtocolIsAllowed() throws IOException {
void classpathProtocolIsAllowed() {
assertThatNoException().isThrownBy(() -> {
mailNotifier.setTemplate("/de/codecentric/boot/admin/server/notify/allowed-file.html");
mailNotifier.getBody(new Context());
});
}

@Test
void callToReflectionUtilsAreNotAllwed() {
assertThatThrownBy(() -> {
mailNotifier.setTemplate("/de/codecentric/boot/admin/server/notify/vulnerable-file.html");
String body = mailNotifier.getBody(new Context());
}).rootCause().hasMessageContaining("error=2, No such file or directory");
mailNotifier.getBody(new Context());
}).rootCause()
.hasMessageContaining(
"Access is forbidden for type 'org.springframework.util.ReflectionUtils' in this expression context.");
}

@EnableAdminServer
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
</head>
<body>

I am fine!

</body>
</html>

0 comments on commit 6c6a2e8

Please sign in to comment.