aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-web/src/test/java
diff options
context:
space:
mode:
authorJakob Heher <jakob.heher@iaik.tugraz.at>2026-04-30 10:21:59 +0200
committerGitHub <noreply@github.com>2026-04-30 10:21:59 +0200
commite2bfdc313c0b6395d272624688b4ed1cba7ce967 (patch)
treeda96c8ed518f18cd3c676605004f5c80daf5570b /pdf-as-web/src/test/java
parent3901740beba6b2673246b1171c12f908f8a359bb (diff)
downloadpdf-as-4-e2bfdc313c0b6395d272624688b4ed1cba7ce967.tar.gz
pdf-as-4-e2bfdc313c0b6395d272624688b4ed1cba7ce967.tar.bz2
pdf-as-4-e2bfdc313c0b6395d272624688b4ed1cba7ce967.zip
Move pdf-as-web.conf to Spring & add MOA timeout (#84)
* move -Dpdf-as-web.conf to spring * add configurable timeout to MOA signing * update workflow trigger
Diffstat (limited to 'pdf-as-web/src/test/java')
-rw-r--r--pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/servlets/SimpleSignServletTest.java (renamed from pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/SimpleSignServletTest.java)88
-rw-r--r--pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/servlets/SimpleVerifyServletTest.java (renamed from pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/SimpleVerifyServletTest.java)118
-rw-r--r--pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/MockMoaSigningTest.java18
-rw-r--r--pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/SimpleWebServiceTest.java53
-rw-r--r--pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/SimpleWebServiceWithoutVerificationTest.java50
5 files changed, 142 insertions, 185 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/servlets/SimpleSignServletTest.java
index 8ab9cfaf..da735c8c 100644
--- 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/servlets/SimpleSignServletTest.java
@@ -1,33 +1,37 @@
-package at.gv.egiz.pdfas.web.test;
+package at.gv.egiz.pdfas.web.servlets;
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 jakarta.servlet.ServletConfig;
-import jakarta.servlet.ServletContext;
+
+import at.gv.egiz.pdfas.web.config.PdfAsWebSpringConfiguration;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
+import lombok.SneakyThrows;
import org.apache.commons.io.IOUtils;
+import org.junit.Before;
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.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
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;
+import org.springframework.mock.web.MockServletConfig;
+import org.springframework.mock.web.MockServletContext;
+import org.springframework.stereotype.Component;
+import org.springframework.test.context.junit4.SpringRunner;
//@Ignore
-@RunWith(BlockJUnit4ClassRunner.class)
+@RunWith(SpringRunner.class)
+@SpringBootTest
public class SimpleSignServletTest {
@@ -38,11 +42,22 @@ public class SimpleSignServletTest {
current + "/src/test/resources/config/pdfas/pdf-as-web.properties");
}
-
-
+
+ @Before
+ @SneakyThrows
+ public void setup() {
+ servlet.init(
+ new MockServletConfig(
+ new MockServletContext("src/main/webapp"),
+ "ExternSignServlet")
+ );
+ }
+
+ @Autowired private ExternSignServlet servlet;
+
@Test
- public void sigBlockParameterTest() throws NoSuchMethodException, SecurityException, IllegalAccessException,
- IllegalArgumentException, InvocationTargetException, IOException, ServletException {
+ @SneakyThrows
+ public void sigBlockParameterTest() {
byte[] pdf = IOUtils.toByteArray(SimpleSignServletTest.class.getResourceAsStream("/data/enc_own.pdf"));
MockHttpServletRequest httpReq = new MockHttpServletRequest("POST", "https://localhost/pdfas");
@@ -64,55 +79,14 @@ public class SimpleSignServletTest {
}
-
- 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);
+ @SneakyThrows
+ private void performTest(HttpServletRequest httpReq, HttpServletResponse httpResp, byte[] pdf) {
StatisticEvent statisticEvent = new StatisticEvent();
statisticEvent.setStartNow();
statisticEvent.setSource(Source.WEB);
statisticEvent.setOperation(Operation.SIGN);
statisticEvent.setUserAgent(UserAgentFilter.getUserAgent());
+ servlet.doSignature(httpReq, httpResp, pdf, statisticEvent);
- 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;
- }
- };
}
}
diff --git a/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/SimpleVerifyServletTest.java b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/servlets/SimpleVerifyServletTest.java
index e0075940..3b5d223c 100644
--- a/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/SimpleVerifyServletTest.java
+++ b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/servlets/SimpleVerifyServletTest.java
@@ -1,4 +1,4 @@
-package at.gv.egiz.pdfas.web.test;
+package at.gv.egiz.pdfas.web.servlets;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -15,12 +15,16 @@ import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
+import lombok.val;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.BlockJUnit4ClassRunner;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
@@ -30,13 +34,16 @@ import at.gv.egiz.pdfas.lib.api.PdfAsFactory;
import at.gv.egiz.pdfas.web.config.WebConfiguration;
import at.gv.egiz.pdfas.web.filter.UserAgentFilter;
import at.gv.egiz.pdfas.web.helper.PdfAsHelper;
-import at.gv.egiz.pdfas.web.servlets.VerifyServlet;
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;
import lombok.SneakyThrows;
+import org.springframework.mock.web.MockServletConfig;
+import org.springframework.mock.web.MockServletContext;
+import org.springframework.test.context.junit4.SpringRunner;
-@RunWith(BlockJUnit4ClassRunner.class)
+@RunWith(SpringRunner.class)
+@SpringBootTest
public class SimpleVerifyServletTest {
@@ -45,56 +52,50 @@ public class SimpleVerifyServletTest {
final String current = new java.io.File(".").getCanonicalPath();
System.setProperty("pdf-as-web.conf",
current + "/src/test/resources/config/pdfas/pdf-as-web.properties");
-
- String webconfig = System.getProperty("pdf-as-web.conf");
-
- if(webconfig == null) {
- throw new RuntimeException("No web configuration provided!");
- }
-
- WebConfiguration.configure(webconfig);
- PdfAsHelper.init();
-
- try {
- PdfAsFactory.validateConfiguration((ISettings)PdfAsHelper.getPdfAsConfig());
-
- } catch (PdfAsSettingsValidationException e) {
- e.printStackTrace();
- }
}
+
+ @Before
+ @SneakyThrows
+ public void setup() {
+ servlet.init(
+ new MockServletConfig(
+ new MockServletContext("src/main/webapp"),
+ "VerifyServlet")
+ );
+ }
+
+
+ @SuppressWarnings("unused") @Autowired private ExternSignServlet dummy; /* ExternSignServlet ctor does web config init */
+ @Autowired private VerifyServlet servlet;
@Test
@SneakyThrows
- public void unsignedPdf() {
- byte[] pdf = IOUtils.toByteArray(SimpleVerifyServletTest.class.getResourceAsStream("/data/enc_own.pdf"));
- executeTest(pdf);
-
+ public void unsignedPdf() {
+ executeTest("/data/enc_own.pdf");
}
- @Test
- @SneakyThrows
- public void unsignedWithSigField() {
- byte[] pdf = IOUtils.toByteArray(SimpleVerifyServletTest.class.getResourceAsStream("/data/placeholder_sigfield_and_qr.pdf"));
- executeTest(pdf);
-
- }
+ @Test
+ @SneakyThrows
+ public void unsignedWithSigField() {
+ executeTest("/data/placeholder_sigfield_and_qr.pdf");
+ }
@Test
- @SneakyThrows
- public void signedPdf() {
- byte[] pdf = IOUtils.toByteArray(SimpleVerifyServletTest.class.getResourceAsStream("/data/dummy-pdf-signed.pdf"));
- executeTest(pdf);
-
- }
+ @SneakyThrows
+ public void signedPdf() {
+ executeTest("/data/dummy-pdf-signed.pdf");
+
+ }
@SneakyThrows
- private MockHttpServletResponse executeTest(byte[] pdf) {
- MockHttpServletRequest httpReq = new MockHttpServletRequest("POST", "https://localhost/pdfas");
- MockHttpServletResponse httpResp = new MockHttpServletResponse();
+ private MockHttpServletResponse executeTest(String pdfResource) {
+ val pdf = IOUtils.toByteArray(SimpleVerifyServletTest.class.getResourceAsStream(pdfResource));
+ MockHttpServletRequest httpReq = new MockHttpServletRequest("POST", "https://localhost/pdfas");
+ MockHttpServletResponse httpResp = new MockHttpServletResponse();
// perform operation
performTest(httpReq, httpResp, pdf);
@@ -110,11 +111,8 @@ public class SimpleVerifyServletTest {
}
- private void performTest(HttpServletRequest httpReq, HttpServletResponse httpResp, byte[] pdf) throws NoSuchMethodException,
- SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ServletException {
- VerifyServlet servlet = new VerifyServlet ();
- ServletConfig servletConfig = buildServletConfig();
- servlet.init(servletConfig);
+ @SneakyThrows
+ private void performTest(HttpServletRequest httpReq, HttpServletResponse httpResp, byte[] pdf) {
Method method = servlet.getClass().getDeclaredMethod("doVerify",
HttpServletRequest.class, HttpServletResponse.class, byte[].class, StatisticEvent.class);
@@ -128,36 +126,4 @@ public class SimpleVerifyServletTest {
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;
- }
- };
- }
}
diff --git a/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/MockMoaSigningTest.java b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/MockMoaSigningTest.java
index 466cfcca..10e87af6 100644
--- a/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/MockMoaSigningTest.java
+++ b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/MockMoaSigningTest.java
@@ -9,6 +9,7 @@ import at.gv.egiz.pdfas.lib.impl.configuration.ConfigurationImpl;
import at.gv.egiz.pdfas.moa.MOAConnector;
import at.gv.egiz.pdfas.sigs.pades.PAdESSignerKeystore;
import at.gv.egiz.pdfas.sigs.pkcs7detached.PKCS7DetachedSigner;
+import at.gv.egiz.pdfas.web.config.PdfAsWebSpringConfiguration;
import at.gv.egiz.pdfas.web.config.WebConfiguration;
import at.gv.egiz.pdfas.web.helper.PdfAsHelper;
import at.gv.egiz.pdfas.web.servlets.ExternSignServlet;
@@ -42,11 +43,8 @@ import java.security.PrivateKey;
import java.util.*;
import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
@RunWith(SpringRunner.class)
@SpringBootTest(properties = {
@@ -57,6 +55,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
public class MockMoaSigningTest {
@Autowired MockMvc mvc;
@Autowired ObjectMapper om;
+ @Autowired PdfAsWebSpringConfiguration config;
static {
try {
@@ -78,7 +77,7 @@ public class MockMoaSigningTest {
targetNamespace = "http://reference.e-government.gv.at/namespace/moa/20020822#",
endpointInterface =
"at.gv.e_government.reference.namespace.moa._20020822_.SignatureCreationPortType")
- static class MockMoa implements AutoCloseable, SignatureCreationPortType {
+ class MockMoa implements AutoCloseable, SignatureCreationPortType {
@SneakyThrows
private static int freePort() {
try (ServerSocket socket = new ServerSocket(0)) {
@@ -100,8 +99,8 @@ public class MockMoaSigningTest {
public final IPlainSigner signer;
@SneakyThrows
- private static Properties getBaseProperties() {
- try (InputStream in = new FileInputStream(System.getProperty(ExternSignServlet.PDF_AS_WEB_CONF))) {
+ private Properties getBaseProperties() {
+ try (InputStream in = new FileInputStream(config.getPdfAsWebConfPath())) {
val props = new Properties();
props.load(in);
return props;
@@ -109,7 +108,7 @@ public class MockMoaSigningTest {
}
@SneakyThrows
- private static void injectProperties(Map<String, String> overlay) {
+ private void injectProperties(Map<String, String> overlay) {
val props = getBaseProperties();
if (overlay != null) overlay.forEach(props::setProperty);
try (val out = new ByteArrayOutputStream()) {
@@ -141,6 +140,7 @@ public class MockMoaSigningTest {
injectProperties(Map.of(
"moal."+keyIdentifier+".enabled", "true",
"moal."+keyIdentifier+".url", endpointURL,
+ "moal."+keyIdentifier+".timeout", "5000",
"moal."+keyIdentifier+".KeyIdentifier", "KG_TEST",
"moal."+keyIdentifier+".Certificate",
"base64:"+Base64.getEncoder().encodeToString(signer.getCertificate(null).getEncoded())
@@ -231,7 +231,7 @@ public class MockMoaSigningTest {
@SneakyThrows
public CreateCMSSignatureResponseType createCMSSignature(CreateCMSSignatureRequest body) throws MOAFault {
// this will cause a timeout
- Thread.sleep(300 * 1000);
+ Thread.sleep(10 * 1000);
throw new RuntimeException("unreachable");
}
}) {
diff --git a/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/SimpleWebServiceTest.java b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/SimpleWebServiceTest.java
index 1d958323..7d81465a 100644
--- a/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/SimpleWebServiceTest.java
+++ b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/SimpleWebServiceTest.java
@@ -4,8 +4,14 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.IOException;
+import java.net.URL;
import java.util.UUID;
+import at.gv.egiz.pdfas.api.ws.PDFASSigning;
+import at.gv.egiz.pdfas.web.servlets.ExternSignServlet;
+import at.gv.egiz.pdfas.web.servlets.SimpleVerifyServletTest;
+import jakarta.xml.ws.Service;
+import lombok.val;
import org.apache.commons.io.IOUtils;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -23,8 +29,15 @@ import at.gv.egiz.pdfas.web.config.WebConfiguration;
import at.gv.egiz.pdfas.web.helper.PdfAsHelper;
import at.gv.egiz.pdfas.web.ws.PDFASSigningImpl;
import lombok.SneakyThrows;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.web.server.LocalServerPort;
+import org.springframework.test.context.junit4.SpringRunner;
-@RunWith(BlockJUnit4ClassRunner.class)
+import javax.xml.namespace.QName;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class SimpleWebServiceTest {
@BeforeClass
@@ -32,28 +45,20 @@ public class SimpleWebServiceTest {
final String current = new java.io.File(".").getCanonicalPath();
System.setProperty("pdf-as-web.conf",
current + "/src/test/resources/config/pdfas/pdf-as-web.properties");
-
- String webconfig = System.getProperty("pdf-as-web.conf");
-
- if(webconfig == null) {
- throw new RuntimeException("No web configuration provided!");
- }
-
- WebConfiguration.configure(webconfig);
- PdfAsHelper.init();
-
- try {
- PdfAsFactory.validateConfiguration((ISettings)PdfAsHelper.getPdfAsConfig());
-
- } catch (PdfAsSettingsValidationException e) {
- e.printStackTrace();
- }
}
+
+ @BeforeClass
+ public static void jceWorkaround() {
+ System.setProperty("javax.net.ssl.trustStoreType", "JKS");
+ }
+
+ @LocalServerPort
+ int port;
@Test
@SneakyThrows
public void sign() {
- byte[] pdf = IOUtils.toByteArray(SimpleVerifyServletTest.class.getResourceAsStream("/data/enc_own.pdf"));
+ byte[] pdf = IOUtils.toByteArray(SimpleVerifyServletTest.class.getResourceAsStream("/data/enc_own.pdf"));
PDFASSignResponse resp = executeTest(pdf);
assertNotNull("signed doc", resp.getSignedPDF());
assertEquals("sign check", 0, resp.getVerificationResponse().getValueCode());
@@ -64,7 +69,7 @@ public class SimpleWebServiceTest {
@Test
@SneakyThrows
public void withSignatureFields() {
- byte[] pdf = IOUtils.toByteArray(SimpleVerifyServletTest.class.getResourceAsStream("/data/placeholder_sigfield_and_qr.pdf"));
+ byte[] pdf = IOUtils.toByteArray(SimpleVerifyServletTest.class.getResourceAsStream("/data/placeholder_sigfield_and_qr.pdf"));
PDFASSignResponse resp = executeTest(pdf);
assertNotNull("signed doc", resp.getSignedPDF());
assertEquals("sign check", 0, resp.getVerificationResponse().getValueCode());
@@ -74,7 +79,11 @@ public class SimpleWebServiceTest {
@SneakyThrows
private PDFASSignResponse executeTest(byte[] pdf) {
- PDFASSigningImpl service = new PDFASSigningImpl();
+ val wsdl = new URL("http://localhost:"+port+"/services/wssign?wsdl");
+ val serviceName = new QName(
+ "http://ws.web.pdfas.egiz.gv.at/",
+ "PDFASSigningImplService");
+ val proxy = Service.create(wsdl, serviceName).getPort(PDFASSigning.class);
PDFASSignRequest req = new PDFASSignRequest();
req.setRequestID(UUID.randomUUID().toString());
@@ -82,9 +91,9 @@ public class SimpleWebServiceTest {
PDFASSignParameters signParams = new PDFASSignParameters();
signParams.setConnector(Connector.JKS);
signParams.setTransactionId(UUID.randomUUID().toString());
- req.setParameters(signParams );
+ req.setParameters(signParams);
- PDFASSignResponse resp = service.signPDFDokument(req);
+ PDFASSignResponse resp = proxy.signPDFDokument(req);
assertNotNull(resp);
return resp;
diff --git a/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/SimpleWebServiceWithoutVerificationTest.java b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/SimpleWebServiceWithoutVerificationTest.java
index d7529721..7954415b 100644
--- a/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/SimpleWebServiceWithoutVerificationTest.java
+++ b/pdf-as-web/src/test/java/at/gv/egiz/pdfas/web/test/SimpleWebServiceWithoutVerificationTest.java
@@ -4,8 +4,13 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.IOException;
+import java.net.URL;
import java.util.UUID;
+import at.gv.egiz.pdfas.api.ws.PDFASSigning;
+import at.gv.egiz.pdfas.web.servlets.SimpleVerifyServletTest;
+import jakarta.xml.ws.Service;
+import lombok.val;
import org.apache.commons.io.IOUtils;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -23,8 +28,15 @@ import at.gv.egiz.pdfas.web.config.WebConfiguration;
import at.gv.egiz.pdfas.web.helper.PdfAsHelper;
import at.gv.egiz.pdfas.web.ws.PDFASSigningImpl;
import lombok.SneakyThrows;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.web.server.LocalServerPort;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
-@RunWith(BlockJUnit4ClassRunner.class)
+import javax.xml.namespace.QName;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class SimpleWebServiceWithoutVerificationTest {
@BeforeClass
@@ -32,28 +44,20 @@ public class SimpleWebServiceWithoutVerificationTest {
final String current = new java.io.File(".").getCanonicalPath();
System.setProperty("pdf-as-web.conf",
current + "/src/test/resources/config/pdfas/pdf-as-web-verify-disabled.properties");
-
- String webconfig = System.getProperty("pdf-as-web.conf");
-
- if(webconfig == null) {
- throw new RuntimeException("No web configuration provided!");
- }
-
- WebConfiguration.configure(webconfig);
- PdfAsHelper.init();
-
- try {
- PdfAsFactory.validateConfiguration((ISettings)PdfAsHelper.getPdfAsConfig());
-
- } catch (PdfAsSettingsValidationException e) {
- e.printStackTrace();
- }
}
+
+ @BeforeClass
+ public static void jceWorkaround() {
+ System.setProperty("javax.net.ssl.trustStoreType", "JKS");
+ }
+
+ @LocalServerPort
+ int port;
@Test
@SneakyThrows
public void sign() {
- byte[] pdf = IOUtils.toByteArray(SimpleVerifyServletTest.class.getResourceAsStream("/data/enc_own.pdf"));
+ byte[] pdf = IOUtils.toByteArray(SimpleVerifyServletTest.class.getResourceAsStream("/data/enc_own.pdf"));
PDFASSignResponse resp = executeTest(pdf);
assertNotNull("signed doc", resp.getSignedPDF());
assertEquals("sign check", 0, resp.getVerificationResponse().getValueCode());
@@ -64,7 +68,7 @@ public class SimpleWebServiceWithoutVerificationTest {
@Test
@SneakyThrows
public void withSignatureFields() {
- byte[] pdf = IOUtils.toByteArray(SimpleVerifyServletTest.class.getResourceAsStream("/data/placeholder_sigfield_and_qr.pdf"));
+ byte[] pdf = IOUtils.toByteArray(SimpleVerifyServletTest.class.getResourceAsStream("/data/placeholder_sigfield_and_qr.pdf"));
PDFASSignResponse resp = executeTest(pdf);
assertNotNull("signed doc", resp.getSignedPDF());
assertEquals("sign check", 0, resp.getVerificationResponse().getValueCode());
@@ -74,7 +78,11 @@ public class SimpleWebServiceWithoutVerificationTest {
@SneakyThrows
private PDFASSignResponse executeTest(byte[] pdf) {
- PDFASSigningImpl service = new PDFASSigningImpl();
+ val wsdl = new URL("http://localhost:"+port+"/services/wssign?wsdl");
+ val serviceName = new QName(
+ "http://ws.web.pdfas.egiz.gv.at/",
+ "PDFASSigningImplService");
+ val proxy = Service.create(wsdl, serviceName).getPort(PDFASSigning.class);
PDFASSignRequest req = new PDFASSignRequest();
req.setRequestID(UUID.randomUUID().toString());
@@ -84,7 +92,7 @@ public class SimpleWebServiceWithoutVerificationTest {
signParams.setTransactionId(UUID.randomUUID().toString());
req.setParameters(signParams );
- PDFASSignResponse resp = service.signPDFDokument(req);
+ PDFASSignResponse resp = proxy.signPDFDokument(req);
assertNotNull(resp);
return resp;