You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by co...@apache.org on 2020/05/12 08:07:47 UTC

svn commit: r1877632 - /santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/

Author: coheigea
Date: Tue May 12 08:07:46 2020
New Revision: 1877632

URL: http://svn.apache.org/viewvc?rev=1877632&view=rev
Log:
Consolidating some test code for registering bouncycastle

Modified:
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/AbstractSignatureCreationTest.java
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/AbstractSignatureVerificationTest.java
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/PKSignatureCreationTest.java
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/PKSignatureVerificationTest.java
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/RSASecurityTest.java
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureCreationTest.java
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureDigestCreationTest.java
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureDigestVerificationTest.java
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureHMACCreationTest.java
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureHMACVerificationTest.java
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureVerificationMaxRefTest.java
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureVerificationMaxTransTest.java
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureVerificationReferenceURIResolverRemoteReferenceTest.java
    santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureVerificationTest.java

Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/AbstractSignatureCreationTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/AbstractSignatureCreationTest.java?rev=1877632&r1=1877631&r2=1877632&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/AbstractSignatureCreationTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/AbstractSignatureCreationTest.java Tue May 12 08:07:46 2020
@@ -19,7 +19,10 @@
 package org.apache.xml.security.test.stax.signature;
 
 import java.io.File;
+import java.lang.reflect.Constructor;
 import java.security.Key;
+import java.security.Provider;
+import java.security.Security;
 import java.security.cert.X509Certificate;
 import java.util.List;
 
@@ -37,6 +40,8 @@ import org.apache.xml.security.test.stax
 import org.apache.xml.security.utils.resolver.ResourceResolverContext;
 import org.apache.xml.security.utils.resolver.ResourceResolverException;
 import org.apache.xml.security.utils.resolver.ResourceResolverSpi;
+
+import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.BeforeEach;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -51,19 +56,47 @@ import static org.junit.jupiter.api.Asse
 public class AbstractSignatureCreationTest {
 
     protected static String BASEDIR;
+    protected static boolean bcInstalled;
 
     protected XMLInputFactory xmlInputFactory;
 
-    @BeforeEach
-    public void setUp() throws Exception {
-
-        BASEDIR = System.getProperty("basedir");
-        if (BASEDIR == null) {
-            BASEDIR = new File(".").getCanonicalPath();
+    @BeforeAll
+    public static void setup() throws Exception {
+        String baseDir = System.getProperty("basedir");
+        if (baseDir == null) {
+            baseDir = new File(".").getCanonicalPath();
         }
+        BASEDIR = baseDir;
 
         org.apache.xml.security.Init.init();
 
+        //
+        // If the BouncyCastle provider is not installed, then try to load it
+        // via reflection.
+        //
+        if (Security.getProvider("BC") == null) {
+            Constructor<?> cons = null;
+            try {
+                Class<?> c = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider");
+                cons = c.getConstructor(new Class[] {});
+            } catch (Exception e) {
+                //ignore
+            }
+            if (cons != null) {
+                Provider provider = (Provider)cons.newInstance();
+                Security.insertProviderAt(provider, 2);
+                bcInstalled = true;
+            }
+        }
+    }
+
+    @org.junit.jupiter.api.AfterAll
+    public static void cleanup() throws Exception {
+        Security.removeProvider("BC");
+    }
+
+    @BeforeEach
+    public void createXMLInputFactory() throws Exception {
         xmlInputFactory = XMLInputFactory.newInstance();
         xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
     }

Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/AbstractSignatureVerificationTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/AbstractSignatureVerificationTest.java?rev=1877632&r1=1877631&r2=1877632&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/AbstractSignatureVerificationTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/AbstractSignatureVerificationTest.java Tue May 12 08:07:46 2020
@@ -19,7 +19,10 @@
 package org.apache.xml.security.test.stax.signature;
 
 import java.io.File;
+import java.lang.reflect.Constructor;
 import java.security.Key;
+import java.security.Provider;
+import java.security.Security;
 import java.security.cert.X509Certificate;
 import java.security.spec.AlgorithmParameterSpec;
 import java.util.List;
@@ -58,6 +61,7 @@ import org.apache.xml.security.test.stax
 import org.apache.xml.security.transforms.Transforms;
 import org.apache.xml.security.utils.resolver.ResourceResolverSpi;
 
+import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.BeforeEach;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -70,22 +74,50 @@ import static org.junit.jupiter.api.Asse
 public class AbstractSignatureVerificationTest {
 
     protected static String BASEDIR;
+    protected static boolean bcInstalled;
 
     protected XMLInputFactory xmlInputFactory;
     protected TransformerFactory transformerFactory = TransformerFactory.newInstance();
 
-    @BeforeEach
-    public void setUp() throws Exception {
-
-        BASEDIR = System.getProperty("basedir");
-        if (BASEDIR == null) {
-            BASEDIR = new File(".").getCanonicalPath();
+    @BeforeAll
+    public static void setup() throws Exception {
+        String baseDir = System.getProperty("basedir");
+        if (baseDir == null) {
+            baseDir = new File(".").getCanonicalPath();
         }
+        BASEDIR = baseDir;
 
         Init.init(AbstractSignatureVerificationTest.class.getClassLoader().getResource("security-config.xml").toURI(),
-                this.getClass());
+                AbstractSignatureVerificationTest.class);
         org.apache.xml.security.Init.init();
 
+        //
+        // If the BouncyCastle provider is not installed, then try to load it
+        // via reflection.
+        //
+        if (Security.getProvider("BC") == null) {
+            Constructor<?> cons = null;
+            try {
+                Class<?> c = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider");
+                cons = c.getConstructor(new Class[] {});
+            } catch (Exception e) {
+                //ignore
+            }
+            if (cons != null) {
+                Provider provider = (Provider)cons.newInstance();
+                Security.insertProviderAt(provider, 2);
+                bcInstalled = true;
+            }
+        }
+    }
+
+    @org.junit.jupiter.api.AfterAll
+    public static void cleanup() throws Exception {
+        Security.removeProvider("BC");
+    }
+
+    @BeforeEach
+    public void createXMLInputFactory() throws Exception {
         xmlInputFactory = XMLInputFactory.newInstance();
         xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
     }

Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/PKSignatureCreationTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/PKSignatureCreationTest.java?rev=1877632&r1=1877631&r2=1877632&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/PKSignatureCreationTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/PKSignatureCreationTest.java Tue May 12 08:07:46 2020
@@ -21,12 +21,9 @@ package org.apache.xml.security.test.sta
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
-import java.lang.reflect.Constructor;
 import java.nio.charset.StandardCharsets;
 import java.security.KeyPair;
 import java.security.KeyPairGenerator;
-import java.security.Provider;
-import java.security.Security;
 import java.security.spec.PSSParameterSpec;
 import java.util.ArrayList;
 import java.util.List;
@@ -56,30 +53,10 @@ import static java.security.spec.MGF1Par
  */
 public class PKSignatureCreationTest extends AbstractSignatureCreationTest {
 
-    private static boolean bcInstalled;
     private static KeyPair rsaKeyPair, ecKeyPair;
 
     @BeforeAll
-    public static void setup() throws Exception {
-        //
-        // If the BouncyCastle provider is not installed, then try to load it
-        // via reflection.
-        //
-        if (Security.getProvider("BC") == null) {
-            Constructor<?> cons = null;
-            try {
-                Class<?> c = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider");
-                cons = c.getConstructor(new Class[] {});
-            } catch (Exception e) {     //NOPMD
-                //ignore
-            }
-            if (cons != null) {
-                Provider provider = (Provider)cons.newInstance();
-                Security.insertProviderAt(provider, 2);
-                bcInstalled = true;
-            }
-        }
-
+    public static void createKeys() throws Exception {
         KeyPairGenerator rsaKpg = KeyPairGenerator.getInstance("RSA");
         rsaKpg.initialize(2048);
         rsaKeyPair = rsaKpg.genKeyPair();
@@ -87,11 +64,6 @@ public class PKSignatureCreationTest ext
         ecKeyPair = KeyPairGenerator.getInstance("EC").genKeyPair();
     }
 
-    @org.junit.jupiter.api.AfterAll
-    public static void cleanup() throws Exception {
-        Security.removeProvider("BC");
-    }
-
     @Test
     public void testRSA_SHA1() throws Exception {
         // Set up the Configuration

Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/PKSignatureVerificationTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/PKSignatureVerificationTest.java?rev=1877632&r1=1877631&r2=1877632&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/PKSignatureVerificationTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/PKSignatureVerificationTest.java Tue May 12 08:07:46 2020
@@ -21,27 +21,21 @@ package org.apache.xml.security.test.sta
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
-import java.lang.reflect.Constructor;
 import java.security.KeyPair;
 import java.security.KeyPairGenerator;
-import java.security.Provider;
-import java.security.Security;
 import java.security.spec.PSSParameterSpec;
 import java.util.ArrayList;
 import java.util.List;
 
-import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
 
-import org.apache.xml.security.stax.config.Init;
 import org.apache.xml.security.stax.ext.InboundXMLSec;
 import org.apache.xml.security.stax.ext.XMLSec;
 import org.apache.xml.security.stax.ext.XMLSecurityProperties;
 import org.apache.xml.security.test.stax.utils.StAX2DOM;
-import org.apache.xml.security.test.stax.utils.XMLSecEventAllocator;
 import org.apache.xml.security.utils.XMLUtils;
 import org.junit.jupiter.api.Assumptions;
 import org.junit.jupiter.api.BeforeAll;
@@ -56,31 +50,10 @@ import static java.security.spec.MGF1Par
  */
 public class PKSignatureVerificationTest extends AbstractSignatureVerificationTest {
     private static KeyPair rsaKeyPair, ecKeyPair;
-    private static boolean bcInstalled;
-    private XMLInputFactory xmlInputFactory;
     private TransformerFactory transformerFactory = TransformerFactory.newInstance();
 
     @BeforeAll
-    public static void setup() throws Exception {
-        //
-        // If the BouncyCastle provider is not installed, then try to load it
-        // via reflection.
-        //
-        if (Security.getProvider("BC") == null) {
-            Constructor<?> cons = null;
-            try {
-                Class<?> c = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider");
-                cons = c.getConstructor(new Class[] {});
-            } catch (Exception e) {
-                //ignore
-            }
-            if (cons != null) {
-                Provider provider = (Provider)cons.newInstance();
-                Security.insertProviderAt(provider, 2);
-                bcInstalled = true;
-            }
-        }
-
+    public static void createKeys() throws Exception {
         KeyPairGenerator rsaKpg = KeyPairGenerator.getInstance("RSA");
         rsaKpg.initialize(2048);
         rsaKeyPair = rsaKpg.genKeyPair();
@@ -88,20 +61,6 @@ public class PKSignatureVerificationTest
         ecKeyPair = KeyPairGenerator.getInstance("EC").genKeyPair();
     }
 
-    public PKSignatureVerificationTest() throws Exception {
-        Init.init(PKSignatureVerificationTest.class.getClassLoader().getResource("security-config.xml").toURI(),
-                this.getClass());
-        org.apache.xml.security.Init.init();
-
-        xmlInputFactory = XMLInputFactory.newInstance();
-        xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
-    }
-
-    @org.junit.jupiter.api.AfterAll
-    public static void cleanup() throws Exception {
-        Security.removeProvider("BC");
-    }
-
     @Test
     public void testRSA_SHA1() throws Exception {
         // Read in plaintext document

Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/RSASecurityTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/RSASecurityTest.java?rev=1877632&r1=1877631&r2=1877632&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/RSASecurityTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/RSASecurityTest.java Tue May 12 08:07:46 2020
@@ -22,21 +22,17 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 
-import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
 
-import org.apache.xml.security.stax.config.Init;
 import org.apache.xml.security.stax.ext.InboundXMLSec;
 import org.apache.xml.security.stax.ext.XMLSec;
 import org.apache.xml.security.stax.ext.XMLSecurityProperties;
 import org.apache.xml.security.stax.securityToken.SecurityTokenConstants;
 import org.apache.xml.security.test.stax.utils.StAX2DOM;
-import org.apache.xml.security.test.stax.utils.XMLSecEventAllocator;
 import org.apache.xml.security.utils.XMLUtils;
-import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.w3c.dom.Document;
 
@@ -47,19 +43,8 @@ import org.w3c.dom.Document;
  */
 public class RSASecurityTest extends AbstractSignatureVerificationTest {
 
-    private XMLInputFactory xmlInputFactory;
     private TransformerFactory transformerFactory = TransformerFactory.newInstance();
 
-    @BeforeEach
-    public void setUp() throws Exception {
-        Init.init(RSASecurityTest.class.getClassLoader().getResource("security-config.xml").toURI(),
-                this.getClass());
-        org.apache.xml.security.Init.init();
-
-        xmlInputFactory = XMLInputFactory.newInstance();
-        xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
-    }
-
     @Test
     public void test_enveloping() throws Exception {
         // Read in plaintext document

Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureCreationTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureCreationTest.java?rev=1877632&r1=1877631&r2=1877632&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureCreationTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureCreationTest.java Tue May 12 08:07:46 2020
@@ -25,7 +25,6 @@ import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
 import java.security.Key;
 import java.security.KeyStore;
-import java.security.Security;
 import java.security.cert.X509Certificate;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -41,6 +40,7 @@ import javax.xml.xpath.XPath;
 import javax.xml.xpath.XPathConstants;
 import javax.xml.xpath.XPathFactory;
 
+import org.junit.jupiter.api.Assumptions;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -805,9 +805,7 @@ public class SignatureCreationTest exten
     @Test
     public void testECDSASignatureCreation() throws Exception {
 
-        if (Security.getProvider("BC") == null) {
-            return;
-        }
+        Assumptions.assumeTrue(bcInstalled);
 
         //
         // This test fails with the IBM JDK
@@ -865,9 +863,7 @@ public class SignatureCreationTest exten
     @Test
     public void testStrongECDSASignatureCreation() throws Exception {
 
-        if (Security.getProvider("BC") == null) {
-            return;
-        }
+        Assumptions.assumeTrue(bcInstalled);
 
         //
         // This test fails with the IBM JDK
@@ -1207,7 +1203,7 @@ public class SignatureCreationTest exten
     }
 
     @Test
-    public void testSignatureCreationKeyValue() throws Exception {
+    public void testSignatureCreationRSAKeyValue() throws Exception {
         // Set up the Configuration
         XMLSecurityProperties properties = new XMLSecurityProperties();
         List<XMLSecurityConstants.Action> actions = new ArrayList<>();
@@ -1231,6 +1227,65 @@ public class SignatureCreationTest exten
         properties.addSignaturePart(securePart);
 
         OutboundXMLSec outboundXMLSec = XMLSec.getOutboundXMLSec(properties);
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        XMLStreamWriter xmlStreamWriter = outboundXMLSec.processOutMessage(baos, StandardCharsets.UTF_8.name());
+
+        InputStream sourceDocument =
+                this.getClass().getClassLoader().getResourceAsStream(
+                        "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext.xml");
+        XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(sourceDocument);
+
+        XmlReaderToWriter.writeAll(xmlStreamReader, xmlStreamWriter);
+        xmlStreamWriter.close();
+
+        // System.out.println("Got:\n" + new String(baos.toByteArray(), StandardCharsets.UTF_8.name()));
+        Document document = null;
+        try (InputStream is = new ByteArrayInputStream(baos.toByteArray())) {
+            document = XMLUtils.read(is, false);
+        }
+
+        // Verify using DOM
+        verifyUsingDOM(document, cert, properties.getSignatureSecureParts());
+    }
+
+    @Test
+    public void testSignatureCreationECDSAKeyValue() throws Exception {
+
+        Assumptions.assumeTrue(bcInstalled);
+
+        //
+        // This test fails with the IBM JDK
+        //
+        if ("IBM Corporation".equals(System.getProperty("java.vendor"))) {
+            return;
+        }
+
+        // Set up the Configuration
+        XMLSecurityProperties properties = new XMLSecurityProperties();
+        List<XMLSecurityConstants.Action> actions = new ArrayList<>();
+        actions.add(XMLSecurityConstants.SIGNATURE);
+        properties.setActions(actions);
+        properties.setSignatureKeyIdentifier(SecurityTokenConstants.KeyIdentifier_KeyValue);
+
+        // Set the key up
+        KeyStore keyStore = KeyStore.getInstance("jks");
+        keyStore.load(
+                this.getClass().getClassLoader().getResource(
+                        "org/apache/xml/security/samples/input/ecdsa.jks").openStream(),
+                "security".toCharArray()
+        );
+        Key key = keyStore.getKey("ECDSA", "security".toCharArray());
+        properties.setSignatureKey(key);
+        X509Certificate cert = (X509Certificate)keyStore.getCertificate("ECDSA");
+        properties.setSignatureCerts(new X509Certificate[]{cert});
+
+        properties.setSignatureAlgorithm("http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha1");
+
+        SecurePart securePart =
+                new SecurePart(new QName("urn:example:po", "PaymentInfo"), SecurePart.Modifier.Content);
+        properties.addSignaturePart(securePart);
+
+        OutboundXMLSec outboundXMLSec = XMLSec.getOutboundXMLSec(properties);
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         XMLStreamWriter xmlStreamWriter = outboundXMLSec.processOutMessage(baos, StandardCharsets.UTF_8.name());
 

Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureDigestCreationTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureDigestCreationTest.java?rev=1877632&r1=1877631&r2=1877632&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureDigestCreationTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureDigestCreationTest.java Tue May 12 08:07:46 2020
@@ -21,12 +21,9 @@ package org.apache.xml.security.test.sta
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
-import java.lang.reflect.Constructor;
 import java.nio.charset.StandardCharsets;
 import java.security.Key;
 import java.security.KeyStore;
-import java.security.Provider;
-import java.security.Security;
 import java.security.cert.X509Certificate;
 import java.util.ArrayList;
 import java.util.List;
@@ -47,7 +44,6 @@ import org.apache.xml.security.stax.ext.
 import org.apache.xml.security.test.stax.utils.XmlReaderToWriter;
 import org.apache.xml.security.utils.XMLUtils;
 import org.junit.jupiter.api.Assumptions;
-import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -56,34 +52,6 @@ import static org.junit.jupiter.api.Asse
  * A set of test-cases for Signature creation with various digest algorithms
  */
 public class SignatureDigestCreationTest extends AbstractSignatureCreationTest {
-    private static boolean bcInstalled;
-
-    @BeforeAll
-    public static void setup() throws Exception {
-        //
-        // If the BouncyCastle provider is not installed, then try to load it
-        // via reflection.
-        //
-        if (Security.getProvider("BC") == null) {
-            Constructor<?> cons = null;
-            try {
-                Class<?> c = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider");
-                cons = c.getConstructor(new Class[] {});
-            } catch (Exception e) {
-                //ignore
-            }
-            if (cons != null) {
-                Provider provider = (Provider)cons.newInstance();
-                Security.insertProviderAt(provider, 2);
-                bcInstalled = true;
-            }
-        }
-    }
-
-    @org.junit.jupiter.api.AfterAll
-    public static void cleanup() throws Exception {
-        Security.removeProvider("BC");
-    }
 
     @Test
     public void testSHA1() throws Exception {

Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureDigestVerificationTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureDigestVerificationTest.java?rev=1877632&r1=1877631&r2=1877632&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureDigestVerificationTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureDigestVerificationTest.java Tue May 12 08:07:46 2020
@@ -27,22 +27,18 @@ import java.security.cert.X509Certificat
 import java.util.ArrayList;
 import java.util.List;
 
-import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
 
 import org.apache.xml.security.signature.XMLSignature;
-import org.apache.xml.security.stax.config.Init;
 import org.apache.xml.security.stax.ext.InboundXMLSec;
 import org.apache.xml.security.stax.ext.XMLSec;
 import org.apache.xml.security.stax.ext.XMLSecurityProperties;
 import org.apache.xml.security.test.stax.utils.StAX2DOM;
-import org.apache.xml.security.test.stax.utils.XMLSecEventAllocator;
 import org.apache.xml.security.utils.XMLUtils;
 import org.junit.jupiter.api.Assumptions;
-import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.w3c.dom.Document;
 
@@ -51,20 +47,8 @@ import org.w3c.dom.Document;
  */
 public class SignatureDigestVerificationTest extends AbstractSignatureVerificationTest {
 
-    private boolean bcInstalled;
-    private XMLInputFactory xmlInputFactory;
     private TransformerFactory transformerFactory = TransformerFactory.newInstance();
 
-    @BeforeEach
-    public void setUp() throws Exception {
-        Init.init(SignatureDigestVerificationTest.class.getClassLoader().getResource("security-config.xml").toURI(),
-                this.getClass());
-        org.apache.xml.security.Init.init();
-
-        xmlInputFactory = XMLInputFactory.newInstance();
-        xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
-    }
-
     @Test
     public void testSHA1() throws Exception {
         // Read in plaintext document

Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureHMACCreationTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureHMACCreationTest.java?rev=1877632&r1=1877631&r2=1877632&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureHMACCreationTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureHMACCreationTest.java Tue May 12 08:07:46 2020
@@ -21,10 +21,7 @@ package org.apache.xml.security.test.sta
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
-import java.lang.reflect.Constructor;
 import java.nio.charset.StandardCharsets;
-import java.security.Provider;
-import java.security.Security;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -42,7 +39,6 @@ import org.apache.xml.security.stax.ext.
 import org.apache.xml.security.test.stax.utils.XmlReaderToWriter;
 import org.apache.xml.security.utils.XMLUtils;
 import org.junit.jupiter.api.Assumptions;
-import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 import org.w3c.dom.Document;
 
@@ -51,35 +47,6 @@ import org.w3c.dom.Document;
  */
 public class SignatureHMACCreationTest extends AbstractSignatureCreationTest {
 
-    private static boolean bcInstalled;
-
-    @BeforeAll
-    public static void setup() throws Exception {
-        //
-        // If the BouncyCastle provider is not installed, then try to load it
-        // via reflection.
-        //
-        if (Security.getProvider("BC") == null) {
-            Constructor<?> cons = null;
-            try {
-                Class<?> c = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider");
-                cons = c.getConstructor(new Class[] {});
-            } catch (Exception e) {
-                //ignore
-            }
-            if (cons != null) {
-                Provider provider = (Provider)cons.newInstance();
-                Security.insertProviderAt(provider, 2);
-                bcInstalled = true;
-            }
-        }
-    }
-
-    @org.junit.jupiter.api.AfterAll
-    public static void cleanup() throws Exception {
-        Security.removeProvider("BC");
-    }
-
     @Test
     public void testHMACSHA1() throws Exception {
         // Set up the Configuration

Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureHMACVerificationTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureHMACVerificationTest.java?rev=1877632&r1=1877631&r2=1877632&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureHMACVerificationTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureHMACVerificationTest.java Tue May 12 08:07:46 2020
@@ -21,30 +21,23 @@ package org.apache.xml.security.test.sta
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
-import java.lang.reflect.Constructor;
 import java.nio.charset.StandardCharsets;
-import java.security.Provider;
-import java.security.Security;
 import java.util.ArrayList;
 import java.util.List;
 
 import javax.crypto.SecretKey;
 import javax.crypto.spec.SecretKeySpec;
-import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
 
-import org.apache.xml.security.stax.config.Init;
 import org.apache.xml.security.stax.ext.InboundXMLSec;
 import org.apache.xml.security.stax.ext.XMLSec;
 import org.apache.xml.security.stax.ext.XMLSecurityProperties;
 import org.apache.xml.security.test.stax.utils.StAX2DOM;
-import org.apache.xml.security.test.stax.utils.XMLSecEventAllocator;
 import org.apache.xml.security.utils.XMLUtils;
 import org.junit.jupiter.api.Assumptions;
-import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 import org.w3c.dom.Document;
 
@@ -53,46 +46,8 @@ import org.w3c.dom.Document;
  */
 public class SignatureHMACVerificationTest extends AbstractSignatureVerificationTest {
 
-    private static boolean bcInstalled;
-    private XMLInputFactory xmlInputFactory;
     private TransformerFactory transformerFactory = TransformerFactory.newInstance();
 
-    @BeforeAll
-    public static void setup() throws Exception {
-        //
-        // If the BouncyCastle provider is not installed, then try to load it
-        // via reflection.
-        //
-        if (Security.getProvider("BC") == null) {
-            Constructor<?> cons = null;
-            try {
-                Class<?> c = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider");
-                cons = c.getConstructor(new Class[] {});
-            } catch (Exception e) {
-                //ignore
-            }
-            if (cons != null) {
-                Provider provider = (Provider)cons.newInstance();
-                Security.insertProviderAt(provider, 2);
-                bcInstalled = true;
-            }
-        }
-    }
-
-    public SignatureHMACVerificationTest() throws Exception {
-        Init.init(SignatureHMACVerificationTest.class.getClassLoader().getResource("security-config.xml").toURI(),
-                this.getClass());
-        org.apache.xml.security.Init.init();
-
-        xmlInputFactory = XMLInputFactory.newInstance();
-        xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
-    }
-
-    @org.junit.jupiter.api.AfterAll
-    public static void cleanup() throws Exception {
-        Security.removeProvider("BC");
-    }
-
     @Test
     public void testHMACSHA1() throws Exception {
         // Read in plaintext document

Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureVerificationMaxRefTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureVerificationMaxRefTest.java?rev=1877632&r1=1877631&r2=1877632&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureVerificationMaxRefTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureVerificationMaxRefTest.java Tue May 12 08:07:46 2020
@@ -20,14 +20,12 @@ package org.apache.xml.security.test.sta
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.File;
 import java.io.InputStream;
 import java.security.Key;
 import java.security.KeyStore;
 import java.security.cert.X509Certificate;
 import java.util.ArrayList;
 import java.util.List;
-import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.transform.TransformerFactory;
@@ -41,11 +39,9 @@ import org.apache.xml.security.stax.ext.
 import org.apache.xml.security.stax.ext.XMLSec;
 import org.apache.xml.security.stax.ext.XMLSecurityProperties;
 import org.apache.xml.security.test.stax.utils.StAX2DOM;
-import org.apache.xml.security.test.stax.utils.XMLSecEventAllocator;
 import org.apache.xml.security.utils.XMLUtils;
 
 import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.w3c.dom.Document;
 
@@ -62,29 +58,16 @@ import static org.junit.jupiter.api.Asse
  */
 public class SignatureVerificationMaxRefTest extends AbstractSignatureVerificationTest {
 
-    private XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
     private TransformerFactory transformerFactory = TransformerFactory.newInstance();
 
     @BeforeAll
-    public static void globalSetUp() throws Exception {
+    public static void setup() throws Exception {
         XMLSec.init();
         Init.init(SignatureVerificationMaxRefTest.class.getClassLoader().getResource("security-config-max-ref-per.xml").toURI(),
                 SignatureVerificationMaxRefTest.class);
         org.apache.xml.security.Init.init();
     }
 
-    @BeforeEach
-    @Override
-    public void setUp() throws Exception {
-
-        BASEDIR = System.getProperty("basedir");
-        if (BASEDIR == null) {
-            BASEDIR = new File(".").getCanonicalPath();
-        }
-
-        xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
-    }
-
     @Test
     public void testMaximumAllowedReferencesPerManifest() throws Exception {
         // Read in plaintext document

Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureVerificationMaxTransTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureVerificationMaxTransTest.java?rev=1877632&r1=1877631&r2=1877632&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureVerificationMaxTransTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureVerificationMaxTransTest.java Tue May 12 08:07:46 2020
@@ -20,14 +20,12 @@ package org.apache.xml.security.test.sta
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.File;
 import java.io.InputStream;
 import java.security.Key;
 import java.security.KeyStore;
 import java.security.cert.X509Certificate;
 import java.util.ArrayList;
 import java.util.List;
-import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.transform.TransformerFactory;
@@ -41,10 +39,8 @@ import org.apache.xml.security.stax.ext.
 import org.apache.xml.security.stax.ext.XMLSec;
 import org.apache.xml.security.stax.ext.XMLSecurityProperties;
 import org.apache.xml.security.test.stax.utils.StAX2DOM;
-import org.apache.xml.security.test.stax.utils.XMLSecEventAllocator;
 import org.apache.xml.security.utils.XMLUtils;
 import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.w3c.dom.Document;
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -60,29 +56,16 @@ import static org.junit.jupiter.api.Asse
  */
 public class SignatureVerificationMaxTransTest extends AbstractSignatureVerificationTest {
 
-    private XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
     private TransformerFactory transformerFactory = TransformerFactory.newInstance();
 
     @BeforeAll
-    public static void globalSetUp() throws Exception {
+    public static void setup() throws Exception {
         XMLSec.init();
         Init.init(SignatureVerificationMaxTransTest.class.getClassLoader().getResource("security-config-max-trans-per.xml").toURI(),
                 SignatureVerificationMaxTransTest.class);
         org.apache.xml.security.Init.init();
     }
 
-    @BeforeEach
-    @Override
-    public void setUp() throws Exception {
-
-        BASEDIR = System.getProperty("basedir");
-        if (BASEDIR == null) {
-            BASEDIR = new File(".").getCanonicalPath();
-        }
-
-        xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
-    }
-
     @Test
     public void testMaximumAllowedTransformsPerReference() throws Exception {
         // Read in plaintext document

Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureVerificationReferenceURIResolverRemoteReferenceTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureVerificationReferenceURIResolverRemoteReferenceTest.java?rev=1877632&r1=1877631&r2=1877632&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureVerificationReferenceURIResolverRemoteReferenceTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureVerificationReferenceURIResolverRemoteReferenceTest.java Tue May 12 08:07:46 2020
@@ -31,7 +31,6 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
@@ -44,12 +43,10 @@ import org.apache.xml.security.stax.ext.
 import org.apache.xml.security.stax.impl.resourceResolvers.ResolverHttp;
 import org.apache.xml.security.test.stax.utils.HttpRequestRedirectorProxy;
 import org.apache.xml.security.test.stax.utils.StAX2DOM;
-import org.apache.xml.security.test.stax.utils.XMLSecEventAllocator;
 import org.apache.xml.security.utils.XMLUtils;
 import org.apache.xml.security.utils.resolver.implementations.ResolverDirectHTTP;
 
 import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 import org.w3c.dom.Document;
@@ -61,7 +58,13 @@ import org.w3c.dom.Document;
 public class SignatureVerificationReferenceURIResolverRemoteReferenceTest extends AbstractSignatureVerificationTest {
 
     @BeforeAll
-    public static void globalSetUp() throws Exception {
+    public static void setup() throws Exception {
+        String baseDir = System.getProperty("basedir");
+        if (baseDir == null) {
+            baseDir = new File(".").getCanonicalPath();
+        }
+        BASEDIR = baseDir;
+
         XMLSec.init();
         Init.init(SignatureVerificationReferenceURIResolverRemoteReferenceTest.class.getClassLoader()
                         .getResource("security-config-allow-same-doc.xml").toURI(),
@@ -69,19 +72,6 @@ public class SignatureVerificationRefere
         org.apache.xml.security.Init.init();
     }
 
-    @BeforeEach
-    @Override
-    public void setUp() throws Exception {
-
-        BASEDIR = System.getProperty("basedir");
-        if (BASEDIR == null) {
-            BASEDIR = new File(".").getCanonicalPath();
-        }
-
-        xmlInputFactory = XMLInputFactory.newInstance();
-        xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
-    }
-
     @Test
     public void testSignatureVerificationWithExternalFilesystemXMLReference() throws Exception {
         // Read in plaintext document

Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureVerificationTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureVerificationTest.java?rev=1877632&r1=1877631&r2=1877632&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureVerificationTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/signature/SignatureVerificationTest.java Tue May 12 08:07:46 2020
@@ -33,7 +33,6 @@ import java.util.Map;
 
 import javax.crypto.SecretKey;
 import javax.crypto.spec.SecretKeySpec;
-import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.transform.TransformerFactory;
@@ -51,7 +50,6 @@ import org.apache.xml.security.keys.cont
 import org.apache.xml.security.keys.content.X509Data;
 import org.apache.xml.security.keys.content.x509.XMLX509IssuerSerial;
 import org.apache.xml.security.signature.XMLSignature;
-import org.apache.xml.security.stax.config.Init;
 import org.apache.xml.security.stax.config.TransformerAlgorithmMapper;
 import org.apache.xml.security.stax.ext.InboundXMLSec;
 import org.apache.xml.security.stax.ext.XMLSec;
@@ -65,12 +63,10 @@ import org.apache.xml.security.stax.secu
 import org.apache.xml.security.stax.securityEvent.X509TokenSecurityEvent;
 import org.apache.xml.security.stax.securityToken.SecurityTokenConstants;
 import org.apache.xml.security.test.stax.utils.StAX2DOM;
-import org.apache.xml.security.test.stax.utils.XMLSecEventAllocator;
 import org.apache.xml.security.transforms.Transform;
 import org.apache.xml.security.transforms.implementations.TransformC14N;
 import org.apache.xml.security.utils.XMLUtils;
 
-import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -83,20 +79,8 @@ import static org.junit.jupiter.api.Asse
  */
 public class SignatureVerificationTest extends AbstractSignatureVerificationTest {
 
-    private XMLInputFactory xmlInputFactory;
     private TransformerFactory transformerFactory = TransformerFactory.newInstance();
 
-    @BeforeEach
-    public void setUp() throws Exception {
-        Init.init(SignatureVerificationTest.class.getClassLoader().getResource("security-config.xml").toURI(),
-                this.getClass());
-        org.apache.xml.security.Init.init();
-
-        xmlInputFactory = XMLInputFactory.newInstance();
-        xmlInputFactory.setEventAllocator(new XMLSecEventAllocator());
-    }
-
-
     @Test
     public void testSignatureVerification() throws Exception {
         // Read in plaintext document