From 34adf17296b8f2252eb9b3274c62f40a9d18ae81 Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Mon, 26 Aug 2019 13:30:53 +0200 Subject: Fix: Change Injection of signatureVerifier Bean into TestSuite - Problem: @TestConfiguration did not override config/MoaSigConfig. - Therefore test uses bean that is configured via application.yaml. - Solution: Replace @TestConfiguration with bean that was created and configured directly in testcase. --- .../at/gv/egiz/moazs/ITSignatureVerifierTest.java | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/test') diff --git a/src/test/java/at/gv/egiz/moazs/ITSignatureVerifierTest.java b/src/test/java/at/gv/egiz/moazs/ITSignatureVerifierTest.java index af958a5..1d6f7e0 100644 --- a/src/test/java/at/gv/egiz/moazs/ITSignatureVerifierTest.java +++ b/src/test/java/at/gv/egiz/moazs/ITSignatureVerifierTest.java @@ -3,6 +3,7 @@ package at.gv.egiz.moazs; import at.gv.egiz.eid.authhandler.modules.sigverify.moasig.api.ISignatureVerificationService; import at.gv.egiz.moazs.backend.SignatureVerifier; import at.gv.egiz.moazs.scheme.SOAPUtils; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.slf4j.Logger; @@ -11,6 +12,7 @@ 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.context.annotation.Primary; import org.springframework.test.context.junit4.SpringRunner; import org.xml.sax.SAXException; @@ -19,6 +21,7 @@ import javax.xml.transform.TransformerException; import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.util.function.Consumer; //Note: Certificate that signed these delivery responses expires in 2023-09-27. @RunWith(SpringRunner.class) @@ -29,26 +32,23 @@ import java.nio.file.Files; private final String resourcesPath = "src/test/resources/at/gv/egiz/moazs/ITSignatureVerifierTest/"; - @TestConfiguration - public class Config{ + private Consumer signatureVerifier; - @Bean - public SignatureVerifier verifier(@Autowired ISignatureVerificationService service){ - return new SignatureVerifier(service, "test-trust-profile", true); - } + @Autowired + private ISignatureVerificationService service; + @Before + public void setup() { + this.signatureVerifier = new SignatureVerifier(service, "test-trustprofile", true); } - @Autowired - private SignatureVerifier verifier; - @Test public void acceptValidSignedDeliveryResponse() throws IOException { var path = resourcesPath + "valid-signed-delivery-response.xml"; var signature = Files.readAllBytes(new File(path).toPath()); - verifier.accept(signature); + signatureVerifier.accept(signature); } @Test @@ -57,7 +57,7 @@ import java.nio.file.Files; var path = resourcesPath + "valid-signed-notification.xml"; var signature = Files.readAllBytes(new File(path).toPath()); - verifier.accept(signature); + signatureVerifier.accept(signature); } @@ -67,7 +67,7 @@ import java.nio.file.Files; var path = resourcesPath + "invalid-signed-delivery-response.xml"; var signature = Files.readAllBytes(new File(path).toPath()); - verifier.accept(signature); + signatureVerifier.accept(signature); } @@ -82,7 +82,7 @@ import java.nio.file.Files; var deliveryNotificationNode = soapUtils.getChildElementOfSoapBody(soapedNotification); var notificationBytes = soapUtils.toBytes(deliveryNotificationNode); - verifier.accept(notificationBytes); + signatureVerifier.accept(notificationBytes); } //shuffled means that the was moved from it's original @@ -98,6 +98,6 @@ import java.nio.file.Files; var deliveryNotificationNode = soapUtils.getChildElementOfSoapBody(soapedNotification); var notificationBytes = soapUtils.toBytes(deliveryNotificationNode); - verifier.accept(notificationBytes); + signatureVerifier.accept(notificationBytes); } } -- cgit v1.2.3