diff options
| author | Jakob Heher <jakob.heher@iaik.tugraz.at> | 2026-06-09 16:06:32 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-06-09 16:06:32 +0200 |
| commit | 68165ce0bb979891fbbb6db7eb3d58c31aa1223a (patch) | |
| tree | 289148f9a1bfc502c3d8fff9e7fd1ebaaf4158b3 /pdf-as-web/src/test | |
| parent | fc8a4ad6228632636003c65ec6c005eff5cd03d6 (diff) | |
| download | pdf-as-4-68165ce0bb979891fbbb6db7eb3d58c31aa1223a.tar.gz pdf-as-4-68165ce0bb979891fbbb6db7eb3d58c31aa1223a.tar.bz2 pdf-as-4-68165ce0bb979891fbbb6db7eb3d58c31aa1223a.zip | |
fix ExceptionCatchFilter consuming multipart bodies incorrectly (#92)
Diffstat (limited to 'pdf-as-web/src/test')
| -rw-r--r-- | pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/RealTomcatTests.java | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/RealTomcatTests.java b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/RealTomcatTests.java new file mode 100644 index 00000000..534df72c --- /dev/null +++ b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/RealTomcatTests.java @@ -0,0 +1,63 @@ +package at.gv.egiz.pdfas.web.test; + +import lombok.SneakyThrows; +import lombok.val; +import org.apache.commons.io.IOUtils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.server.LocalServerPort; + +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.nio.charset.StandardCharsets; +import java.util.List; + +import static org.junit.Assert.*; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class RealTomcatTests { + @LocalServerPort int port; + + @BeforeAll + @SneakyThrows + public static void classInitializer() { + final String current = new java.io.File(".").getCanonicalPath(); + System.setProperty("pdf-as-web.conf", + current + "/src/test/resources/config/pdfas/pdf-as-web.properties"); + } + + @BeforeAll + public static void jceWorkaround() { + System.setProperty("javax.net.ssl.trustStoreType", "JKS"); + } + + @Test + @SneakyThrows + public void fileErrorOnNoDocument() { + byte[] pdf = IOUtils.toByteArray(RealTomcatTests.class.getResourceAsStream("/data/enc_own.pdf")); + val boundary = "----TEST"; + val prefix = ( + "--"+boundary+"\r\nContent-Disposition: form-data; name=\"source\"\r\n\r\ninternal\r\n"+ + "--"+boundary+"\r\nContent-Disposition: form-data; name=\"connector\"\r\n\r\nmobilebku\r\n"+ + "--"+boundary+"\r\nContent-Disposition: form-data; name=\"pdf-file\"; filename=\"\"\r\nContent-Type: application/pdf\r\n\r\n" + ).getBytes(StandardCharsets.UTF_8); + val suffix = ( + "\r\n--"+boundary+"--\r\n" + ).getBytes(StandardCharsets.UTF_8); + val multipartBody = List.of(prefix, pdf, suffix); + + val client = HttpClient.newBuilder().followRedirects(HttpClient.Redirect.NEVER).build(); + val request = HttpRequest.newBuilder() + .uri(URI.create("http://localhost:"+port+"/Sign")) + .header("Content-Type", "multipart/form-data; boundary="+boundary) + .POST(HttpRequest.BodyPublishers.ofByteArrays(multipartBody)) + .build(); + + val response = client.send(request, HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8)); + assertEquals(200, response.statusCode()); + assertTrue("Should contain redirect to a-trust", response.body().contains("https-security-layer-request")); + } +} |
