/******************************************************************************* * Copyright 2019 Graz University of Technology * MOA ZS has been developed in a cooperation between EGIZ * and Graz University of Technology. * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * https://joinup.ec.europa.eu/news/understanding-eupl-v12 * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. *******************************************************************************/ 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; /** * @author Christof Rabensteiner * */ //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); } }