aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-web/src/test/java/at/gv
diff options
context:
space:
mode:
authorThomas <>2023-01-09 17:33:26 +0100
committerThomas <>2023-01-09 17:33:26 +0100
commitbf0200054b663dad9f04af4126c5a31f80b8003a (patch)
treefc76496d4a0149a54e8cffdc0210334cd58d2c51 /pdf-as-web/src/test/java/at/gv
parente69ba716ebae7307645ff9c640967d58ef48b9f4 (diff)
downloadpdf-as-4-bf0200054b663dad9f04af4126c5a31f80b8003a.tar.gz
pdf-as-4-bf0200054b663dad9f04af4126c5a31f80b8003a.tar.bz2
pdf-as-4-bf0200054b663dad9f04af4126c5a31f80b8003a.zip
test(web): add very simple start-up and signing test
Diffstat (limited to 'pdf-as-web/src/test/java/at/gv')
-rw-r--r--pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/SimpleSignServletTest.java118
1 files changed, 118 insertions, 0 deletions
diff --git a/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/SimpleSignServletTest.java b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/SimpleSignServletTest.java
new file mode 100644
index 00000000..7c020b17
--- /dev/null
+++ b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/SimpleSignServletTest.java
@@ -0,0 +1,118 @@
+package at.gv.egiz.pdfas.web.test;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Enumeration;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.io.IOUtils;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.BlockJUnit4ClassRunner;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+import at.gv.egiz.pdfas.web.filter.UserAgentFilter;
+import at.gv.egiz.pdfas.web.servlets.ExternSignServlet;
+import at.gv.egiz.pdfas.web.stats.StatisticEvent;
+import at.gv.egiz.pdfas.web.stats.StatisticEvent.Operation;
+import at.gv.egiz.pdfas.web.stats.StatisticEvent.Source;
+
+//@Ignore
+@RunWith(BlockJUnit4ClassRunner.class)
+public class SimpleSignServletTest {
+
+
+ @BeforeClass
+ public static void classInitializer() throws IOException {
+ final String current = new java.io.File(".").getCanonicalPath();
+ System.setProperty("pdf-as-web.conf",
+ current + "/src/test/resources/config/pdfas/pdf-as-web.properties");
+
+ }
+
+
+ @Test
+ public void sigBlockParameterTest() throws NoSuchMethodException, SecurityException, IllegalAccessException,
+ IllegalArgumentException, InvocationTargetException, IOException, ServletException {
+
+ byte[] pdf = IOUtils.toByteArray(SimpleSignServletTest.class.getResourceAsStream("/data/enc_own.pdf"));
+ MockHttpServletRequest httpReq = new MockHttpServletRequest("POST", "https://localhost/pdfas");
+ MockHttpServletResponse httpResp = new MockHttpServletResponse();
+ httpReq.setAttribute("REQ_DATA_URL", true);
+ httpReq.setAttribute("connector", "jks");
+
+ httpReq.setAttribute("sbp:schule", "Güssing");
+
+
+
+ // perform operation
+ performTest(httpReq, httpResp, pdf);
+
+
+ //validate state
+ assertNotNull("httpResp", httpResp);
+ assertNotNull("no dataUrl redirect", httpResp.getHeader("Location"));
+
+ }
+
+
+ private void performTest(HttpServletRequest httpReq, HttpServletResponse httpResp, byte[] pdf) throws NoSuchMethodException,
+ SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ServletException {
+ ExternSignServlet servlet = new ExternSignServlet();
+ ServletConfig servletConfig = buildServletConfig();
+ servlet.init(servletConfig);
+
+ Method method = servlet.getClass().getDeclaredMethod("doSignature",
+ HttpServletRequest.class, HttpServletResponse.class, byte[].class, StatisticEvent.class);
+ method.setAccessible(true);
+ StatisticEvent statisticEvent = new StatisticEvent();
+ statisticEvent.setStartNow();
+ statisticEvent.setSource(Source.WEB);
+ statisticEvent.setOperation(Operation.SIGN);
+ statisticEvent.setUserAgent(UserAgentFilter.getUserAgent());
+
+ method.invoke(servlet, httpReq, httpResp, pdf, statisticEvent);
+
+ }
+
+
+ private ServletConfig buildServletConfig() {
+
+ return new ServletConfig() {
+
+ private ServletContext servletContext = null;
+
+ @Override
+ public String getServletName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public ServletContext getServletContext() {
+ return servletContext;
+ }
+
+ @Override
+ public Enumeration<String> getInitParameterNames() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getInitParameter(String name) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+ }
+}