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; 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.context.annotation.Primary; import org.springframework.test.context.junit4.SpringRunner; import org.xml.sax.SAXException; import javax.xml.parsers.ParserConfigurationException; 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) @SpringBootTest public class ITSignatureVerifierTest { private static final Logger log = LoggerFactory.getLogger(ITSignatureVerifierTest.class); private final String resourcesPath = "src/test/resources/at/gv/egiz/moazs/ITSignatureVerifierTest/"; private Consumer signatureVerifier; @Autowired private ISignatureVerificationService service; @Before public void setup() { this.signatureVerifier = new SignatureVerifier(service, "test-trustprofile", true); } @Test public void acceptValidSignedDeliveryResponse() throws IOException { var path = resourcesPath + "valid-signed-delivery-response.xml"; var signature = Files.readAllBytes(new File(path).toPath()); signatureVerifier.accept(signature); } @Test public void acceptValidDeliveryNotification() throws IOException { var path = resourcesPath + "valid-signed-notification.xml"; var signature = Files.readAllBytes(new File(path).toPath()); signatureVerifier.accept(signature); } @Test(expected = MoaZSException.class) public void rejectInvalidSignedDeliveryResponse() throws IOException { var path = resourcesPath + "invalid-signed-delivery-response.xml"; var signature = Files.readAllBytes(new File(path).toPath()); signatureVerifier.accept(signature); } @Test public void acceptValidSoapedDeliveryNotification() throws IOException, ParserConfigurationException, SAXException, TransformerException { var path = resourcesPath + "valid-signed-soaped-notification.xml"; var soapedNotificationBytes = Files.readAllBytes(new File(path).toPath()); var soapUtils = new SOAPUtils(); var soapedNotification = soapUtils.toDOM(soapedNotificationBytes); var deliveryNotificationNode = soapUtils.getChildElementOfSoapBody(soapedNotification); var notificationBytes = soapUtils.toBytes(deliveryNotificationNode); signatureVerifier.accept(notificationBytes); } //shuffled means that the was moved from it's original //place to a different place. @Test public void acceptValidShuffledSoapedDeliveryNotification() throws IOException, ParserConfigurationException, SAXException, TransformerException { var path = resourcesPath + "valid-signed-shuffled-soaped-notification.xml"; var soapedNotificationBytes = Files.readAllBytes(new File(path).toPath()); var soapUtils = new SOAPUtils(); var soapedNotification = soapUtils.toDOM(soapedNotificationBytes); var deliveryNotificationNode = soapUtils.getChildElementOfSoapBody(soapedNotification); var notificationBytes = soapUtils.toBytes(deliveryNotificationNode); signatureVerifier.accept(notificationBytes); } }