Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<PosixFilePermission> 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<PosixFilePermission> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,24 +152,34 @@ private void exportMessages(String address, File output) throws Exception {
}

private void exportMessages(String address, int messageCount, boolean durable, String clientId, File output) throws Exception {
new Consumer()
.setFile(output.getAbsolutePath())
.setDurable(durable)
.setDestination(address)
.setMessageCount(messageCount)
.setClientID(clientId)
.setUser("admin")
.setPassword("admin")
.execute(new TestActionContext());
try {
new Consumer()
.setFile(output.getAbsolutePath())
.setDurable(durable)
.setDestination(address)
.setMessageCount(messageCount)
.setClientID(clientId)
.setUser("admin")
.setPassword("admin")
.execute(new TestActionContext());
} finally {
// release file handles
System.gc();
}
}

private void importMessages(String address, File input) throws Exception {
new Producer()
.setFile(input.getAbsolutePath())
.setDestination(address)
.setUser("admin")
.setPassword("admin")
.execute(new TestActionContext());
try {
new Producer()
.setFile(input.getAbsolutePath())
.setDestination(address)
.setUser("admin")
.setPassword("admin")
.execute(new TestActionContext());
} finally {
// release file handles
System.gc();
}
}

private void createBothTypeAddress(String address) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,26 @@
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);
assertEquals(System.getenv(ENV_VAR_NAME), brokerDTO.server.configuration);
}

@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public DistributedLock getDistributedLock(String lockId) throws ExecutionExcepti
@Override
public MutableLong getMutableLong(final String mutableLongId) throws ExecutionException {
// use a lock file - but with a prefix
final FileDistributedLock fileDistributedLock = (FileDistributedLock) getDistributedLock("ML:" + mutableLongId);
final FileDistributedLock fileDistributedLock = (FileDistributedLock) getDistributedLock("ML_" + mutableLongId);
return new MutableLong() {
@Override
public String getMutableLongId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2447,7 +2447,7 @@ public void testTextPropertiesReaderFromFile() throws Exception {
try (FileOutputStream fileOutputStream = new FileOutputStream(tmpFile);
PrintWriter printWriter = new PrintWriter(fileOutputStream)) {
for (String textProperty : textProperties) {
printWriter.println(textProperty);
printWriter.print(textProperty + "\n");
}
}

Expand Down Expand Up @@ -2971,12 +2971,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 + "/");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@ public class FileLockNodeManagerTest {
@Timeout(3)
public void testChannelClosed() throws Exception {
FileLockNodeManager manager = new FileLockNodeManager(temporaryFolder, false);
try {
// calling this method sets up the internal FileChannel as it would be in normal usage
manager.pausePrimaryServer();

// calling this method sets up the internal FileChannel as it would be in normal usage
manager.pausePrimaryServer();

// now close the channel so we can ensure it throws
manager.getChannel().close();
// now close the channel so we can ensure it throws
manager.getChannel().close();

assertThrows(ClosedChannelException.class, () -> manager.lock(0));
assertThrows(ClosedChannelException.class, () -> manager.lock(0));
} finally {
manager.stop();
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.net.URL;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -99,9 +101,10 @@ public void setUp() throws Exception {
directoryService.setAllowAnonymousAccess(true);
ldapServer.setDirectoryService(directoryService);

String keystore = Objects.requireNonNull(this.getClass().getClassLoader().
getResource("server-keystore-without-ca.p12")).getFile();
ldapServer.setKeystoreFile(keystore);
URL keystore = Objects.requireNonNull(this.getClass().getClassLoader().
getResource("server-keystore-without-ca.p12"));
String keystorePath = Paths.get(keystore.toURI()).toString();
ldapServer.setKeystoreFile(keystorePath);
ldapServer.setCertificatePassword("securepass");

ldapServer.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.io.File;
import java.lang.invoke.MethodHandles;
import java.net.URL;
import java.nio.file.Paths;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -72,7 +73,7 @@ public class KubernetesClientImplTest {
"kind": "TokenReview", "spec": {"token": "kermit_token"}}""";

@BeforeAll
public static void startServer() {
public static void startServer() throws Exception {
ConfigurationProperties.directoryToSaveDynamicSSLCertificate(tempDir.getAbsolutePath());
ConfigurationProperties.certificateAuthorityPrivateKey(KubernetesClientImplTest.class.getClassLoader().getResource("server-ca.pem").getPath());
ConfigurationProperties.certificateAuthorityCertificate(KubernetesClientImplTest.class.getClassLoader().getResource("server-ca-cert.pem").getPath());
Expand All @@ -86,10 +87,13 @@ public static void startServer() {

assertNotNull(mockServer);
assertTrue(mockServer.hasStarted());

URL token = KubernetesClientImplTest.class.getClassLoader().getResource("client_token");
String tokenPath = Paths.get(token.toURI()).toString();

System.setProperty("KUBERNETES_SERVICE_HOST", host);
System.setProperty("KUBERNETES_SERVICE_PORT", port);
System.setProperty("KUBERNETES_TOKEN_PATH",
KubernetesClientImplTest.class.getClassLoader().getResource("client_token").getPath());
System.setProperty("KUBERNETES_TOKEN_PATH", tokenPath);

URL caPath = KubernetesClientImplTest.class.getClassLoader()
.getResource("client-and-server-ca-certs.pem");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.net.http.HttpClient;
import java.nio.file.FileSystemException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
Expand Down Expand Up @@ -103,6 +105,7 @@
import org.eclipse.jetty.ee9.webapp.WebInfConfiguration;
import org.eclipse.jetty.util.thread.ThreadPool;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand All @@ -124,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 KEY_STORE_PATH = getResourcePath("server-keystore.p12");

static final String PEM_KEY_STORE_PATH = WebServerComponentTest.class.getClassLoader().getResource("server-keystore.pemcfg").getFile();
static final String PEM_KEY_STORE_PATH = getResourcePath("server-keystore.pemcfg");

static final String KEY_STORE_PASSWORD = "securepass";

Expand Down Expand Up @@ -559,8 +571,16 @@ public void testSSLAutoReload(boolean useSymbolicLinks) throws Exception {

String keyStorePath;
if (useSymbolicLinks) {
keyStorePath = Files.createSymbolicLink(storeFolder.toPath().resolve(
"store-keystore.p12"), keyStoreFile.toPath()).toString();
try {
keyStorePath = Files.createSymbolicLink(storeFolder.toPath().resolve(
"store-keystore.p12"), keyStoreFile.toPath()).toString();
} catch (FileSystemException e) {
// Check if privileges are missing on Windows
if (e.getMessage() != null && e.getMessage().contains("A required privilege is not held by the client")) {
Assumptions.assumeTrue(false, "Skipping test: Windows account lacks the privilege to create symbolic links.");
}
throw e;
}
} else {
keyStorePath = keyStoreFile.getAbsolutePath();
}
Expand Down Expand Up @@ -633,24 +653,40 @@ private void testSSLAutoReloadPemConfigSources(boolean useSymbolicLinks) throws
String sourceKey;
String sourceCert;
if (useSymbolicLinks) {
sourceKey = Files.createSymbolicLink(storeFolder.toPath().resolve(
"store-key.pem"), serverKeyFile.toPath()).toString();
sourceCert = Files.createSymbolicLink(storeFolder.toPath().resolve(
"store-cert.pem"), serverCertFile.toPath()).toString();
try {
sourceKey = Files.createSymbolicLink(storeFolder.toPath().resolve(
"store-key.pem"), serverKeyFile.toPath()).toString();
sourceCert = Files.createSymbolicLink(storeFolder.toPath().resolve(
"store-cert.pem"), serverCertFile.toPath()).toString();
} catch (FileSystemException e) {
// Check if privileges are missing on Windows
if (e.getMessage() != null && e.getMessage().contains("A required privilege is not held by the client")) {
Assumptions.assumeTrue(false, "Skipping test: Windows account lacks the privilege to create symbolic links.");
}
throw e;
}
} else {
sourceKey = serverKeyFile.getAbsolutePath();
sourceCert = serverCertFile.getAbsolutePath();
}

Files.write(serverPemConfigFile.toPath(), Arrays.asList(new String[]{
"source.key=" + sourceKey,
"source.cert=" + sourceCert
"source.key=" + sourceKey.replace("\\", "/"),
"source.cert=" + sourceCert.replace("\\", "/")
}));

String keyStorePath;
if (useSymbolicLinks) {
keyStorePath = Files.createSymbolicLink(storeFolder.toPath().resolve(
"store-pem-config.properties"), serverPemConfigFile.toPath()).toString();
try {
keyStorePath = Files.createSymbolicLink(storeFolder.toPath().resolve(
"store-pem-config.properties"), serverPemConfigFile.toPath()).toString();
} catch (FileSystemException e) {
// Check if privileges are missing on Windows
if (e.getMessage() != null && e.getMessage().contains("A required privilege is not held by the client")) {
Assumptions.assumeTrue(false, "Skipping test: Windows account lacks the privilege to create symbolic links.");
}
throw e;
}
} else {
keyStorePath = serverPemConfigFile.getAbsolutePath();
}
Expand Down Expand Up @@ -746,10 +782,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);
WebServerDTO webServerDTO = new WebServerDTO();
webServerDTO.setBindings(Collections.singletonList(bindingDTO));
Expand Down
Loading