You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2022/05/02 00:00:14 UTC
[logging-log4j2] branch master updated (b1e6f2654e -> ad648a02cd)
This is an automated email from the ASF dual-hosted git repository.
mattsicker pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
from b1e6f2654e LOG4J2-3473 (DOC) fix version number
new 04f19a7725 Disable SecurityManager-using tests on Java 18+
new b5790244eb Ignore AsyncWaitStrategy tests in XmlSchemaTest
new ad648a02cd Update log4j-bom parent pom version for reproducible builds
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
...EnvironmentPropertySourceSecurityManagerIT.java | 24 ++++++-----
...ropertyFilePropertySourceSecurityManagerIT.java | 36 ++++++++--------
...mPropertiesPropertySourceSecurityManagerIT.java | 28 ++++++------
log4j-bom/pom.xml | 6 ++-
.../log4j/core/config/xml/XmlSchemaTest.java | 50 ++++++++++------------
.../log4j/core/impl/ThrowableProxyTest.java | 35 +++++++--------
6 files changed, 93 insertions(+), 86 deletions(-)
[logging-log4j2] 03/03: Update log4j-bom parent pom version for reproducible builds
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
mattsicker pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit ad648a02cd5e94950c2a9d4bb73e84c1f0050222
Author: Matt Sicker <ma...@apache.org>
AuthorDate: Sun May 1 18:27:05 2022 -0500
Update log4j-bom parent pom version for reproducible builds
Signed-off-by: Matt Sicker <ma...@apache.org>
---
log4j-bom/pom.xml | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/log4j-bom/pom.xml b/log4j-bom/pom.xml
index cefb284f8e..19ee573d88 100644
--- a/log4j-bom/pom.xml
+++ b/log4j-bom/pom.xml
@@ -19,7 +19,7 @@
<parent>
<groupId>org.apache.logging</groupId>
<artifactId>logging-parent</artifactId>
- <version>3</version>
+ <version>5</version>
<relativePath/>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -29,6 +29,10 @@
<artifactId>log4j-bom</artifactId>
<version>3.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
+ <properties>
+ <!-- reproducible build setting -->
+ <project.build.outputTimestamp>10</project.build.outputTimestamp>
+ </properties>
<dependencyManagement>
<dependencies>
<!-- Log4j API -->
[logging-log4j2] 01/03: Disable SecurityManager-using tests on Java 18+
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
mattsicker pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit 04f19a7725a831d5fa33e4d4fc06f181a7014c42
Author: Matt Sicker <ma...@apache.org>
AuthorDate: Sun May 1 17:53:53 2022 -0500
Disable SecurityManager-using tests on Java 18+
SecurityManager is a deprecated API that is now throwing an UnsupportedOperationException on Java 18 on attempt to use a custom SecurityManager instance.
Signed-off-by: Matt Sicker <ma...@apache.org>
---
...EnvironmentPropertySourceSecurityManagerIT.java | 24 +++++++++------
...ropertyFilePropertySourceSecurityManagerIT.java | 36 ++++++++++++----------
...mPropertiesPropertySourceSecurityManagerIT.java | 28 +++++++++--------
.../log4j/core/impl/ThrowableProxyTest.java | 35 ++++++++++-----------
4 files changed, 65 insertions(+), 58 deletions(-)
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/util/EnvironmentPropertySourceSecurityManagerIT.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/util/EnvironmentPropertySourceSecurityManagerIT.java
index 58ed8a15eb..eebb0a73aa 100644
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/util/EnvironmentPropertySourceSecurityManagerIT.java
+++ b/log4j-api-test/src/test/java/org/apache/logging/log4j/util/EnvironmentPropertySourceSecurityManagerIT.java
@@ -17,15 +17,15 @@
package org.apache.logging.log4j.util;
-import java.security.Permission;
-
-import org.apache.logging.log4j.test.junit.SecurityManagerTestRule;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledForJreRange;
+import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.parallel.ResourceLock;
+import java.security.Permission;
+
/**
- * Tests https://issues.apache.org/jira/browse/LOG4J2-2274.
+ * Tests <a href="https://issues.apache.org/jira/browse/LOG4J2-2274">LOG4J2-2274</a>.
* <p>
* Using a security manager can mess up other tests so this is best used from
* integration tests (classes that end in "IT" instead of "Test" and
@@ -37,11 +37,9 @@ import org.junit.jupiter.api.parallel.ResourceLock;
* @see System#setSecurityManager(SecurityManager)
*/
@ResourceLock("java.lang.SecurityManager")
+@DisabledForJreRange(min = JRE.JAVA_18) // custom SecurityManager instances throw UnsupportedOperationException
public class EnvironmentPropertySourceSecurityManagerIT {
- @Rule
- public final SecurityManagerTestRule rule = new SecurityManagerTestRule(new TestSecurityManager());
-
/**
* Always throws a SecurityException for any environment variables permission
* check.
@@ -75,6 +73,12 @@ public class EnvironmentPropertySourceSecurityManagerIT {
*/
@Test
public void test() {
- PropertiesUtil.getProperties();
+ var existing = System.getSecurityManager();
+ try {
+ System.setSecurityManager(new TestSecurityManager());
+ PropertiesUtil.getProperties();
+ } finally {
+ System.setSecurityManager(existing);
+ }
}
}
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/util/PropertyFilePropertySourceSecurityManagerIT.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/util/PropertyFilePropertySourceSecurityManagerIT.java
index c586c9d29e..40cdcb611f 100644
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/util/PropertyFilePropertySourceSecurityManagerIT.java
+++ b/log4j-api-test/src/test/java/org/apache/logging/log4j/util/PropertyFilePropertySourceSecurityManagerIT.java
@@ -17,23 +17,21 @@
package org.apache.logging.log4j.util;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledForJreRange;
+import org.junit.jupiter.api.condition.JRE;
+import org.junit.jupiter.api.parallel.ResourceLock;
+
import java.io.FilePermission;
-import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.Permission;
import java.util.PropertyPermission;
-import org.apache.logging.log4j.test.junit.SecurityManagerTestRule;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.jupiter.api.parallel.ResourceLock;
-
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
/**
- * Test related to https://issues.apache.org/jira/browse/LOG4J2-2274.
+ * Test related to <a href="https://issues.apache.org/jira/browse/LOG4J2-2274">LOG4J2-2274</a>.
* <p>
* Using a security manager can mess up other tests so this is best used from
* integration tests (classes that end in "IT" instead of "Test" and
@@ -46,15 +44,13 @@ import static org.junit.Assert.assertTrue;
* @see PropertyPermission
*/
@ResourceLock("java.lang.SecurityManager")
+@DisabledForJreRange(min = JRE.JAVA_18) // custom SecurityManager instances throw UnsupportedOperationException
public class PropertyFilePropertySourceSecurityManagerIT {
- @BeforeClass
+ @BeforeAll
public static void beforeClass() {
- assertTrue(TEST_FIXTURE_PATH, Files.exists(Paths.get(TEST_FIXTURE_PATH)));
+ assertThat(Paths.get(TEST_FIXTURE_PATH)).exists();
}
-
- @Rule
- public final SecurityManagerTestRule rule = new SecurityManagerTestRule(new TestSecurityManager());
private static final String TEST_FIXTURE_PATH = "src/test/resources/PropertiesUtilTest.properties";
@@ -82,7 +78,13 @@ public class PropertyFilePropertySourceSecurityManagerIT {
*/
@Test
public void test() {
- final PropertiesUtil propertiesUtil = new PropertiesUtil(TEST_FIXTURE_PATH);
- assertNull(propertiesUtil.getStringProperty("a.1"));
+ var existing = System.getSecurityManager();
+ try {
+ System.setSecurityManager(new TestSecurityManager());
+ final PropertiesUtil propertiesUtil = new PropertiesUtil(TEST_FIXTURE_PATH);
+ assertThat(propertiesUtil.getStringProperty("a.1")).isNull();
+ } finally {
+ System.setSecurityManager(existing);
+ }
}
}
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/util/SystemPropertiesPropertySourceSecurityManagerIT.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/util/SystemPropertiesPropertySourceSecurityManagerIT.java
index fe7014a8f0..d4df643cf2 100644
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/util/SystemPropertiesPropertySourceSecurityManagerIT.java
+++ b/log4j-api-test/src/test/java/org/apache/logging/log4j/util/SystemPropertiesPropertySourceSecurityManagerIT.java
@@ -17,18 +17,18 @@
package org.apache.logging.log4j.util;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledForJreRange;
+import org.junit.jupiter.api.condition.JRE;
+import org.junit.jupiter.api.parallel.ResourceLock;
+
import java.security.Permission;
import java.util.PropertyPermission;
-import org.apache.logging.log4j.test.junit.SecurityManagerTestRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.jupiter.api.parallel.ResourceLock;
-
-import static org.junit.Assert.assertNull;
+import static org.assertj.core.api.Assertions.assertThat;
/**
- * Test related to https://issues.apache.org/jira/browse/LOG4J2-2274.
+ * Test related to <a href="https://issues.apache.org/jira/browse/LOG4J2-2274">LOG4J2-2274</a>.
* <p>
* Using a security manager can mess up other tests so this is best used from
* integration tests (classes that end in "IT" instead of "Test" and
@@ -41,11 +41,9 @@ import static org.junit.Assert.assertNull;
* @see PropertyPermission
*/
@ResourceLock("java.lang.SecurityManager")
+@DisabledForJreRange(min = JRE.JAVA_18) // custom SecurityManager instances throw UnsupportedOperationException
public class SystemPropertiesPropertySourceSecurityManagerIT {
- @Rule
- public final SecurityManagerTestRule rule = new SecurityManagerTestRule(new TestSecurityManager());
-
/**
* Always throws a SecurityException for any environment variables permission
* check.
@@ -83,7 +81,13 @@ public class SystemPropertiesPropertySourceSecurityManagerIT {
*/
@Test
public void test() {
- final PropertiesUtil propertiesUtil = new PropertiesUtil("src/test/resources/PropertiesUtilTest.properties");
- assertNull(propertiesUtil.getStringProperty("a.1"));
+ var existing = System.getSecurityManager();
+ try {
+ System.setSecurityManager(new TestSecurityManager());
+ final PropertiesUtil propertiesUtil = new PropertiesUtil("src/test/resources/PropertiesUtilTest.properties");
+ assertThat(propertiesUtil.getStringProperty("a.1")).isNull();
+ } finally {
+ System.setSecurityManager(existing);
+ }
}
}
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/impl/ThrowableProxyTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/impl/ThrowableProxyTest.java
index e4953a817e..e1b3179a1a 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/impl/ThrowableProxyTest.java
+++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/impl/ThrowableProxyTest.java
@@ -16,13 +16,20 @@
*/
package org.apache.logging.log4j.core.impl;
-import static org.junit.jupiter.api.Assertions.assertArrayEquals;
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.pattern.PlainTextRenderer;
+import org.apache.logging.log4j.util.Strings;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledForJreRange;
+import org.junit.jupiter.api.condition.JRE;
+import javax.crypto.BadPaddingException;
+import javax.crypto.Cipher;
+import javax.crypto.KeyGenerator;
+import javax.crypto.spec.IvParameterSpec;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -39,19 +46,7 @@ import java.util.Deque;
import java.util.HashMap;
import java.util.Map;
-import javax.crypto.BadPaddingException;
-import javax.crypto.Cipher;
-import javax.crypto.KeyGenerator;
-import javax.crypto.spec.IvParameterSpec;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.pattern.PlainTextRenderer;
-import org.apache.logging.log4j.util.Strings;
-import org.junit.jupiter.api.Test;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import static org.junit.jupiter.api.Assertions.*;
/**
*
@@ -142,6 +137,7 @@ public class ThrowableProxyTest {
}
@Test
+ @DisabledForJreRange(min = JRE.JAVA_18) // custom SecurityManager instances throw UnsupportedOperationException
public void testLogStackTraceWithClassThatWillCauseSecurityException() throws IOException {
final SecurityManager sm = System.getSecurityManager();
try {
@@ -169,6 +165,7 @@ public class ThrowableProxyTest {
}
@Test
+ @DisabledForJreRange(min = JRE.JAVA_18) // custom SecurityManager instances throw UnsupportedOperationException
public void testLogStackTraceWithClassLoaderThatWithCauseSecurityException() throws Exception {
final SecurityManager sm = System.getSecurityManager();
try {
[logging-log4j2] 02/03: Ignore AsyncWaitStrategy tests in XmlSchemaTest
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
mattsicker pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit b5790244ebd3bd2e630c930b069dec4a4b86fcea
Author: Matt Sicker <ma...@apache.org>
AuthorDate: Sun May 1 18:17:28 2022 -0500
Ignore AsyncWaitStrategy tests in XmlSchemaTest
As there is no corresponding XML schema definition for AsyncWaitStrategyFactory, these cannot be used in strict mode. This also improves the debuggability of the test assertions and uses some modern Java APIs.
Signed-off-by: Matt Sicker <ma...@apache.org>
---
.../log4j/core/config/xml/XmlSchemaTest.java | 50 ++++++++++------------
1 file changed, 23 insertions(+), 27 deletions(-)
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/xml/XmlSchemaTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/xml/XmlSchemaTest.java
index fa1ffd8433..6d150e0023 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/xml/XmlSchemaTest.java
+++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/xml/XmlSchemaTest.java
@@ -16,37 +16,35 @@
*/
package org.apache.logging.log4j.core.config.xml;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.mutable.MutableInt;
+import org.junit.jupiter.api.Test;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.XMLFilterImpl;
+import org.xml.sax.helpers.XMLReaderFactory;
+
+import javax.xml.XMLConstants;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
-import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
-import javax.xml.XMLConstants;
-import javax.xml.transform.sax.SAXSource;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-import javax.xml.validation.Validator;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.mutable.MutableInt;
-import org.junit.jupiter.api.Test;
-import org.xml.sax.Attributes;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.XMLFilterImpl;
-import org.xml.sax.helpers.XMLReaderFactory;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
public class XmlSchemaTest {
@@ -63,7 +61,8 @@ public class XmlSchemaTest {
"log4j12", // log4j 1.x configs
"perf-CountingNoOpAppender.xml", // uses test-appender CountingNoOp
"reconfiguration-deadlock.xml", // uses test-appender ReconfigurationDeadlockTestAppender
- "XmlConfigurationSecurity.xml" //
+ "AsyncWaitStrategy", // uses AsyncWaitStrategyFactory (LOG4J2-3472)
+ "XmlConfigurationSecurity.xml" // used for testing XML parser; shouldn't be parseable in secure settings
);
private static String capitalizeTags(final String xml) {
@@ -104,7 +103,7 @@ public class XmlSchemaTest {
};
final MutableInt configs = new MutableInt();
- final MutableInt failures = new MutableInt();
+ final List<Exception> exceptions = new ArrayList<>();
try (final Stream<Path> testResources = Files.list(Paths.get("src", "test", "resources"))) {
testResources
@@ -123,18 +122,15 @@ public class XmlSchemaTest {
System.out.flush();
try {
- final String xml = fixXml(
- FileUtils.readFileToString(filePath.toFile(), Charset.defaultCharset()));
+ final String xml = fixXml(Files.readString(filePath));
validator.validate(new SAXSource(namespaceAdder,
new InputSource(new ByteArrayInputStream(xml.getBytes()))), null);
} catch (final Exception ex) {
- System.err.println(ex);
- System.err.flush();
- failures.increment();
+ exceptions.add(ex);
}
});
}
- assertEquals(0, failures.intValue());
+ assertThat(exceptions).isEmpty();
}
}