aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/at/gv/egiz/moazs
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/at/gv/egiz/moazs')
-rw-r--r--src/test/java/at/gv/egiz/moazs/MoaSPSSSignatureVerifierTest.java49
-rw-r--r--src/test/java/at/gv/egiz/moazs/SameThreadDeliveryPipelineTest.java11
2 files changed, 53 insertions, 7 deletions
diff --git a/src/test/java/at/gv/egiz/moazs/MoaSPSSSignatureVerifierTest.java b/src/test/java/at/gv/egiz/moazs/MoaSPSSSignatureVerifierTest.java
new file mode 100644
index 0000000..afa817f
--- /dev/null
+++ b/src/test/java/at/gv/egiz/moazs/MoaSPSSSignatureVerifierTest.java
@@ -0,0 +1,49 @@
+package at.gv.egiz.moazs;
+
+import at.gv.egiz.eid.authhandler.modules.sigverify.moasig.api.ISignatureVerificationService;
+import at.gv.egiz.moazs.verify.MoaSPSSSignatureVerifier;
+import at.gv.egiz.moazs.verify.SignatureVerifier;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.TestConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+ public class MoaSPSSSignatureVerifierTest {
+
+ private final String resourcesPath = "src/test/resources/at/gv/egiz/moazs/MoaSPSSSignatureVerifierTest/";
+
+ @TestConfiguration
+ public class Config{
+
+ @Bean
+ public SignatureVerifier verifier(@Autowired ISignatureVerificationService service){
+ return new MoaSPSSSignatureVerifier(service, "test-trust-profile", true);
+ }
+
+ }
+
+ @Autowired
+ private SignatureVerifier verifier;
+
+ //TODO make sure that testcase does not depend on runtime because it's certificate expires in 2023-09-27.
+ @Test
+ public void acceptValidSignedDeliveryResponse() throws IOException {
+
+ var path = resourcesPath + "valid-signed-delivery-response.xml";
+ var signature = Files.readAllBytes(new File(path).toPath());
+
+ verifier.verify(signature);
+ }
+
+}
diff --git a/src/test/java/at/gv/egiz/moazs/SameThreadDeliveryPipelineTest.java b/src/test/java/at/gv/egiz/moazs/SameThreadDeliveryPipelineTest.java
index 768f376..cd454f2 100644
--- a/src/test/java/at/gv/egiz/moazs/SameThreadDeliveryPipelineTest.java
+++ b/src/test/java/at/gv/egiz/moazs/SameThreadDeliveryPipelineTest.java
@@ -20,10 +20,12 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.List;
+import static at.gv.egiz.moazs.MoaZSException.moaZSException;
import static at.gv.zustellung.app2mzs.xsd.ConfigType.configTypeBuilder;
import static at.gv.zustellung.app2mzs.xsd.DeliveryRequestType.Payload;
import static at.gv.zustellung.app2mzs.xsd.DeliveryRequestType.Payload.payloadBuilder;
@@ -148,7 +150,8 @@ public class SameThreadDeliveryPipelineTest {
@Test
public void rejectInvalidSignature() {
var appDeliveryId = "invalid-signature";
- setupMocks(appDeliveryId, true, List.of(), List.of("*/*"), false);
+ setupMocks(appDeliveryId, true, List.of(), List.of("*/*"));
+ doThrow(moaZSException("Signature Invalid!")).when(verifier).verify(any());
pipeline.processRequest(appDeliveryId);
var actualCode = repository.getDeliveryRequestStatus(appDeliveryId).get()
@@ -160,11 +163,6 @@ public class SameThreadDeliveryPipelineTest {
private DeliveryRequestStatusType setupMocks(String appDeliveryId, boolean tnvzRequest,
List<String> attachedTypes, List<String> acceptedTypes) {
- return setupMocks(appDeliveryId, tnvzRequest, attachedTypes, acceptedTypes, true);
- }
-
- private DeliveryRequestStatusType setupMocks(String appDeliveryId, boolean tnvzRequest,
- List<String> attachedTypes, List<String> acceptedTypes, boolean isSignedStatusValid) {
var mzsRequest = setupMzsRequest(appDeliveryId, tnvzRequest, attachedTypes);
var msgRequest = setupMsgRequest(appDeliveryId);
@@ -178,7 +176,6 @@ public class SameThreadDeliveryPipelineTest {
when(converter.convert(eq(mzsRequest), any())).thenReturn(msgRequest);
when(msgClientFactory.create(msgRequest, mzsRequest.getConfig(), interceptor)).thenReturn(msgClient);
when(msgClient.send()).thenReturn(status);
- when(verifier.verify(signedStatus)).thenReturn(isSignedStatusValid);
return status;