ARTEMIS-4778: rework tests manipulating Xxe config so it is reset after class, and not updated at all for skipped tests
This commit is contained in:
parent
7849e2dcbf
commit
f64d918406
|
@ -21,30 +21,67 @@ import javax.xml.transform.dom.DOMSource;
|
|||
import javax.xml.transform.stream.StreamSource;
|
||||
import javax.xml.validation.Validator;
|
||||
import java.io.File;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.activemq.artemis.tests.util.ArtemisTestCase;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class XmlProviderTest {
|
||||
public class XmlProviderTest extends ArtemisTestCase {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
||||
|
||||
private static Boolean origXxeEnabled;
|
||||
|
||||
protected boolean xxeEnabled;
|
||||
|
||||
@Parameterized.Parameters(name = "xxeEnabled={0}")
|
||||
public static Collection getParameters() {
|
||||
return Arrays.asList(new Boolean[]{true, false});
|
||||
}
|
||||
|
||||
public XmlProviderTest(boolean xxeEnabled) {
|
||||
@BeforeClass
|
||||
public static void beforeAll() {
|
||||
if (origXxeEnabled == null) {
|
||||
origXxeEnabled = XmlProvider.isXxeEnabled();
|
||||
}
|
||||
|
||||
logger.trace("BeforeAll - origXxeEnabled={}, isXxeEnabled={}", origXxeEnabled, XmlProvider.isXxeEnabled());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterAll() {
|
||||
logger.trace("AfterAll - origXxeEnabled={}, isXxeEnabled={} ", origXxeEnabled, XmlProvider.isXxeEnabled());
|
||||
if (origXxeEnabled != null) {
|
||||
logger.trace("AfterAll - Resetting XxeEnabled={}", origXxeEnabled);
|
||||
XmlProvider.setXxeEnabled(origXxeEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
logger.trace("Running setUp - xxeEnabled={}", xxeEnabled);
|
||||
XmlProvider.setXxeEnabled(xxeEnabled);
|
||||
}
|
||||
|
||||
public XmlProviderTest(boolean xxeEnabled) {
|
||||
this.xxeEnabled = xxeEnabled;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDocument() throws Exception {
|
||||
DocumentBuilder documentBuilder = XmlProvider.newDocumentBuilder();
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.nio.file.Path;
|
|||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -76,39 +77,81 @@ import org.apache.activemq.artemis.logs.AssertionLoggerHandler;
|
|||
import org.apache.activemq.artemis.utils.RandomUtil;
|
||||
import org.apache.activemq.artemis.utils.XmlProvider;
|
||||
import org.apache.activemq.artemis.utils.critical.CriticalAnalyzerPolicy;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class FileConfigurationTest extends AbstractConfigurationTestBase {
|
||||
|
||||
@BeforeClass
|
||||
public static void setupProperties() {
|
||||
System.setProperty("a2Prop", "a2");
|
||||
System.setProperty("falseProp", "false");
|
||||
System.setProperty("trueProp", "true");
|
||||
System.setProperty("ninetyTwoProp", "92");
|
||||
}
|
||||
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
||||
|
||||
@AfterClass
|
||||
public static void clearProperties() {
|
||||
System.clearProperty("a2Prop");
|
||||
System.clearProperty("falseProp");
|
||||
System.clearProperty("trueProp");
|
||||
System.clearProperty("ninetyTwoProp");
|
||||
}
|
||||
private static Boolean origXxeEnabled;
|
||||
|
||||
protected boolean xxeEnabled;
|
||||
|
||||
@Parameterized.Parameters(name = "xxeEnabled={0}")
|
||||
public static Collection getParameters() {
|
||||
return Arrays.asList(new Boolean[] {true, false});
|
||||
}
|
||||
|
||||
public FileConfigurationTest(boolean xxeEnabled) {
|
||||
@BeforeClass
|
||||
public static void beforeAll() {
|
||||
if (origXxeEnabled == null) {
|
||||
origXxeEnabled = XmlProvider.isXxeEnabled();
|
||||
}
|
||||
|
||||
logger.trace("BeforeAll - origXxeEnabled={}, isXxeEnabled={}", origXxeEnabled, XmlProvider.isXxeEnabled());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterAll() {
|
||||
logger.trace("AfterAll - origXxeEnabled={}, isXxeEnabled={} ", origXxeEnabled, XmlProvider.isXxeEnabled());
|
||||
if (origXxeEnabled != null) {
|
||||
logger.trace("AfterAll - Resetting XxeEnabled={}", origXxeEnabled);
|
||||
XmlProvider.setXxeEnabled(origXxeEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
logger.trace("Running setUp - xxeEnabled={}", xxeEnabled);
|
||||
XmlProvider.setXxeEnabled(xxeEnabled);
|
||||
|
||||
setupProperties();
|
||||
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@After
|
||||
public void afterEach() {
|
||||
clearProperties();
|
||||
}
|
||||
|
||||
public void setupProperties() {
|
||||
System.setProperty("a2Prop", "a2");
|
||||
System.setProperty("falseProp", "false");
|
||||
System.setProperty("trueProp", "true");
|
||||
System.setProperty("ninetyTwoProp", "92");
|
||||
}
|
||||
|
||||
public void clearProperties() {
|
||||
System.clearProperty("a2Prop");
|
||||
System.clearProperty("falseProp");
|
||||
System.clearProperty("trueProp");
|
||||
System.clearProperty("ninetyTwoProp");
|
||||
}
|
||||
|
||||
public FileConfigurationTest(boolean xxeEnabled) {
|
||||
this.xxeEnabled = xxeEnabled;
|
||||
}
|
||||
|
||||
protected String getConfigurationName() {
|
||||
|
|
|
@ -16,9 +16,8 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.core.config.impl;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assume;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Before;
|
||||
|
||||
public class FileXIncludeConfigurationTest extends FileConfigurationTest {
|
||||
|
||||
|
@ -29,11 +28,18 @@ public class FileXIncludeConfigurationTest extends FileConfigurationTest {
|
|||
|
||||
public FileXIncludeConfigurationTest(boolean xxeEnabled) {
|
||||
super(xxeEnabled);
|
||||
Assume.assumeTrue(xxeEnabled);
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setupProperties() {
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
Assume.assumeTrue(xxeEnabled);
|
||||
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupProperties() {
|
||||
System.setProperty("xincludePath", "./src/test/resources");
|
||||
System.setProperty("a2Prop", "a2");
|
||||
System.setProperty("falseProp", "false");
|
||||
|
@ -41,8 +47,8 @@ public class FileXIncludeConfigurationTest extends FileConfigurationTest {
|
|||
System.setProperty("ninetyTwoProp", "92");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void clearProperties() {
|
||||
@Override
|
||||
public void clearProperties() {
|
||||
System.clearProperty("xincludePath");
|
||||
System.clearProperty("a2Prop");
|
||||
System.clearProperty("falseProp");
|
||||
|
|
|
@ -17,9 +17,8 @@
|
|||
package org.apache.activemq.artemis.core.config.impl;
|
||||
|
||||
import org.apache.activemq.artemis.core.server.plugin.ActiveMQServerBasePlugin;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assume;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FileXIncludeSchemaConfigurationTest extends FileConfigurationTest {
|
||||
|
@ -31,11 +30,18 @@ public class FileXIncludeSchemaConfigurationTest extends FileConfigurationTest {
|
|||
|
||||
public FileXIncludeSchemaConfigurationTest(boolean xxeEnabled) {
|
||||
super(xxeEnabled);
|
||||
Assume.assumeTrue(xxeEnabled);
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setupProperties() {
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
Assume.assumeTrue(xxeEnabled);
|
||||
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupProperties() {
|
||||
System.setProperty("xincludePath", "./src/test/resources");
|
||||
System.setProperty("a2Prop", "a2");
|
||||
System.setProperty("falseProp", "false");
|
||||
|
@ -43,8 +49,8 @@ public class FileXIncludeSchemaConfigurationTest extends FileConfigurationTest {
|
|||
System.setProperty("ninetyTwoProp", "92");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void clearProperties() {
|
||||
@Override
|
||||
public void clearProperties() {
|
||||
System.clearProperty("xincludePath");
|
||||
System.clearProperty("a2Prop");
|
||||
System.clearProperty("falseProp");
|
||||
|
|
Loading…
Reference in New Issue