diff --git a/artemis-cli/src/test/java/org/apache/activemq/artemis/cli/commands/ShellTest.java b/artemis-cli/src/test/java/org/apache/activemq/artemis/cli/commands/ShellTest.java index 6060c4d9147..1dc2a5efaac 100644 --- a/artemis-cli/src/test/java/org/apache/activemq/artemis/cli/commands/ShellTest.java +++ b/artemis-cli/src/test/java/org/apache/activemq/artemis/cli/commands/ShellTest.java @@ -98,17 +98,23 @@ private static void executeShell(String input, File outputHistory) throws Interr assertTrue(outputHistory.exists()); - // Validate file permissions are 600 (owner read/write only) - Set permissions = Files.getPosixFilePermissions(outputHistory.toPath()); - assertTrue(permissions.contains(PosixFilePermission.OWNER_READ), "File should be readable by owner"); - assertTrue(permissions.contains(PosixFilePermission.OWNER_WRITE), "File should be writable by owner"); - // Explicitly verify group and others cannot read - assertFalse(permissions.contains(PosixFilePermission.GROUP_READ), "File should not be readable by group"); - assertFalse(permissions.contains(PosixFilePermission.GROUP_WRITE), "File should not be writable by group"); - assertFalse(permissions.contains(PosixFilePermission.GROUP_EXECUTE), "File should not be executable by group"); - assertFalse(permissions.contains(PosixFilePermission.OTHERS_READ), "File should not be readable by others"); - assertFalse(permissions.contains(PosixFilePermission.OTHERS_WRITE), "File should not be writable by others"); - assertFalse(permissions.contains(PosixFilePermission.OTHERS_EXECUTE), "File should not be executable by others"); + // Validate file permissions are 600 on unix-type systems (owner read/write only) + if (Files.getFileStore(outputHistory.toPath()).supportsFileAttributeView("posix")) { + Set permissions = Files.getPosixFilePermissions(outputHistory.toPath()); + assertTrue(permissions.contains(PosixFilePermission.OWNER_READ), "File should be readable by owner"); + assertTrue(permissions.contains(PosixFilePermission.OWNER_WRITE), "File should be writable by owner"); + // Explicitly verify group and others cannot read + assertFalse(permissions.contains(PosixFilePermission.GROUP_READ), "File should not be readable by group"); + assertFalse(permissions.contains(PosixFilePermission.GROUP_WRITE), "File should not be writable by group"); + assertFalse(permissions.contains(PosixFilePermission.GROUP_EXECUTE), "File should not be executable by group"); + assertFalse(permissions.contains(PosixFilePermission.OTHERS_READ), "File should not be readable by others"); + assertFalse(permissions.contains(PosixFilePermission.OTHERS_WRITE), "File should not be writable by others"); + assertFalse(permissions.contains(PosixFilePermission.OTHERS_EXECUTE), "File should not be executable by others"); + } else { + // Fallback for Windows: Verify owner can read/write + assertTrue(outputHistory.canRead(), "File should be readable"); + assertTrue(outputHistory.canWrite(), "File should be writable"); + } } finally { System.clearProperty("artemis.instance"); diff --git a/artemis-cli/src/test/java/org/apache/activemq/artemis/cli/commands/messages/ProducerThreadTest.java b/artemis-cli/src/test/java/org/apache/activemq/artemis/cli/commands/messages/ProducerThreadTest.java index 813dbf46446..2d2d1b83340 100644 --- a/artemis-cli/src/test/java/org/apache/activemq/artemis/cli/commands/messages/ProducerThreadTest.java +++ b/artemis-cli/src/test/java/org/apache/activemq/artemis/cli/commands/messages/ProducerThreadTest.java @@ -225,7 +225,7 @@ public void testBadMessagePropertyType() throws Exception { producer.setProperties(createJsonProperty("myType", "myKey", "myValue")); producer.applyProperties(mockMessage); - assertEquals("Unable to set property: myKey. Did not recognize type: myType. Supported types are: boolean, int, long, byte, short, float, double, string.\n", context.getStderr()); + assertEquals("Unable to set property: myKey. Did not recognize type: myType. Supported types are: boolean, int, long, byte, short, float, double, string." + System.lineSeparator(), context.getStderr()); } private static String createJsonProperty(String type, String key, String value) { diff --git a/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/NetworkHealthTest.java b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/NetworkHealthTest.java index f3508008ef2..0d84690864e 100644 --- a/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/NetworkHealthTest.java +++ b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/NetworkHealthTest.java @@ -327,12 +327,18 @@ public boolean purePing(InetAddress address) throws IOException, InterruptedExce @Test @Timeout(30) public void testPurePingTimeout() throws Exception { - NetworkHealthCheck check = new NetworkHealthCheck(null, 100, 2000); + int timeout = 2000; + + // Add a "tolerance" for Windows, since it reports less time spent in timeout than the networkTimeout parameter (around 200ms) + int tolerance = 500; + + NetworkHealthCheck check = new NetworkHealthCheck(null, 100, timeout); long time = System.currentTimeMillis(); //[RFC1166] reserves the address block 192.0.2.0/24 for test. assertFalse(check.purePing(InetAddress.getByName("192.0.2.0"))); - assertTrue(System.currentTimeMillis() - time >= 2000); + + assertTrue(System.currentTimeMillis() - time >= (timeout - tolerance)); } } diff --git a/artemis-dto/src/test/java/org/apache/activemq/artemis/dto/XmlUtilTest.java b/artemis-dto/src/test/java/org/apache/activemq/artemis/dto/XmlUtilTest.java index c2dac261303..aa5d800493c 100644 --- a/artemis-dto/src/test/java/org/apache/activemq/artemis/dto/XmlUtilTest.java +++ b/artemis-dto/src/test/java/org/apache/activemq/artemis/dto/XmlUtilTest.java @@ -30,13 +30,18 @@ public class XmlUtilTest extends ArtemisTestCase { @Test - public void testPropertySubstituion(@TempDir Path tempDir) throws Exception { + public void testPropertySubstitution(@TempDir Path tempDir) throws Exception { final String SYSTEM_PROP_NAME = getTestMethodName() + "SysPropName"; final String SYSTEM_PROP_VALUE = getTestMethodName() + "SysPropValue"; System.setProperty(SYSTEM_PROP_NAME, SYSTEM_PROP_VALUE); // since System.getenv() returns an immutable Map we rely here on an environment variable that is likely to exist - final String ENV_VAR_NAME = "HOME"; + String ENV_VAR_NAME = "HOME"; + + // override to USERPROFILE if OS is windows + if (System.getProperty("os.name").toLowerCase().contains("win")) { + ENV_VAR_NAME = "USERPROFILE"; + } BrokerDTO brokerDTO = getBrokerDTO(tempDir, SYSTEM_PROP_NAME, ENV_VAR_NAME); assertEquals(SYSTEM_PROP_VALUE, ((JaasSecurityDTO)brokerDTO.security).domain); @@ -44,7 +49,7 @@ public void testPropertySubstituion(@TempDir Path tempDir) throws Exception { } @Test - public void testPropertySubstituionPrecedence(@TempDir Path tempDir) throws Exception { + public void testPropertySubstitutionPrecedence(@TempDir Path tempDir) throws Exception { final String SYSTEM_PROP_NAME = "HOME"; final String SYSTEM_PROP_VALUE = getTestMethodName() + "SysPropValue"; System.setProperty(SYSTEM_PROP_NAME, SYSTEM_PROP_VALUE); diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java index 6d43db8f4b7..b878681dba7 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImplTest.java @@ -2969,12 +2969,15 @@ public void testRegxPropertiesFilesInDir() throws Exception { File tmpFile = File.createTempFile("a_stuff", ".properties", temporaryFolder); Properties properties = new Properties(); properties.put("name", "a"); - properties.store(new FileOutputStream(tmpFile), null); - + try (FileOutputStream out = new FileOutputStream(tmpFile)) { + properties.store(out, null); + } tmpFile = File.createTempFile("b_stuff", ".0-properties", temporaryFolder); properties = new Properties(); properties.put("name", "0"); - properties.store(new FileOutputStream(tmpFile), null); + try (FileOutputStream out = new FileOutputStream(tmpFile)) { + properties.store(out, null); + } ConfigurationImpl configuration = new ConfigurationImpl(); configuration.parseProperties(temporaryFolder + "/"); diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/spi/core/security/jaas/PropertiesLoaderTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/spi/core/security/jaas/PropertiesLoaderTest.java index aa36e13e8f7..33fa93186f4 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/spi/core/security/jaas/PropertiesLoaderTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/spi/core/security/jaas/PropertiesLoaderTest.java @@ -40,8 +40,9 @@ void load(@TempDir Path tempDir) throws IOException { properties.put("p2", "b"); properties.put("p3", "/b/"); // regexp - FileWriter fileWriter = new FileWriter(file.toFile()); - properties.store(fileWriter, ""); + try (FileWriter fileWriter = new FileWriter(file.toFile())) { + properties.store(fileWriter, ""); + } PropertiesLoader underTest = new PropertiesLoader(); Map options = new HashMap(); diff --git a/artemis-web/src/test/java/org/apache/activemq/cli/test/WebServerComponentTest.java b/artemis-web/src/test/java/org/apache/activemq/cli/test/WebServerComponentTest.java index 3f7b83fe64b..6ad61d5851d 100644 --- a/artemis-web/src/test/java/org/apache/activemq/cli/test/WebServerComponentTest.java +++ b/artemis-web/src/test/java/org/apache/activemq/cli/test/WebServerComponentTest.java @@ -34,6 +34,7 @@ import java.net.URL; import java.net.http.HttpClient; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.ArrayList; @@ -126,9 +127,18 @@ public class WebServerComponentTest extends ArtemisTestCase { static final String URL = System.getProperty("url", "http://localhost:8161/WebServerComponentTest.txt"); static final String SECURE_URL = System.getProperty("url", "https://localhost:8448/WebServerComponentTest.txt"); - static final String KEY_STORE_PATH = WebServerComponentTest.class.getClassLoader().getResource("server-keystore.p12").getFile(); + private static String getResourcePath(String resourceName) { + try { + URI uri = WebServerComponentTest.class.getClassLoader().getResource(resourceName).toURI(); + return Path.of(uri).toString(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } - static final String PEM_KEY_STORE_PATH = WebServerComponentTest.class.getClassLoader().getResource("server-keystore.pemcfg").getFile(); + static final String KEY_STORE_PATH = getResourcePath("server-keystore.p12"); + + static final String PEM_KEY_STORE_PATH = getResourcePath("server-keystore.pemcfg"); static final String KEY_STORE_PASSWORD = "securepass"; @@ -659,8 +669,8 @@ private void testSSLAutoReloadPemConfigSources(boolean useSymbolicLinks) throws } Files.write(serverPemConfigFile.toPath(), Arrays.asList(new String[]{ - "source.key=" + sourceKey, - "source.cert=" + sourceCert + "source.key=" + sourceKey.replace("\\", "/"), + "source.cert=" + sourceCert.replace("\\", "/") })); String keyStorePath; @@ -762,10 +772,11 @@ public HttpRoute determineRoute(HttpHost host, public void simpleSecureServerWithClientAuth() throws Exception { BindingDTO bindingDTO = new BindingDTO(); bindingDTO.uri = "https://localhost:0"; - bindingDTO.setKeyStorePath(KEY_STORE_PATH); + String keyStorePath = KEY_STORE_PATH.replace("\\", "/"); + bindingDTO.setKeyStorePath(keyStorePath); bindingDTO.setKeyStorePassword(KEY_STORE_PASSWORD); bindingDTO.setClientAuth(true); - bindingDTO.setTrustStorePath(KEY_STORE_PATH); + bindingDTO.setTrustStorePath(keyStorePath); bindingDTO.setTrustStorePassword(KEY_STORE_PASSWORD); if (System.getProperty("java.vendor").contains("IBM")) { //By default on IBM Java 8 JVM, org.eclipse.jetty.util.ssl.SslContextFactory doesn't include TLSv1.2 diff --git a/pom.xml b/pom.xml index c9850b5e4c7..9cf8e3957be 100644 --- a/pom.xml +++ b/pom.xml @@ -272,7 +272,7 @@ -Dbasedir=${basedir} -Djdk.attach.allowAttachSelf=true -Dartemis.distribution.output="${artemis.distribution.output}" - -Dlog4j2.configurationFile="file:${activemq.basedir}/tests/config/${logging.config}" + -Dlog4j2.configurationFile="${activemq.basedir}/tests/config/${logging.config}" ${project.basedir} false