Skip to content
Open
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 @@ -14,6 +14,7 @@

import java.util.List;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
Expand All @@ -26,9 +27,18 @@ class DocumentAccessPolicyTest {

private DocumentAccessPolicy policy;
private Environment env;
private String originalUserHome;

@BeforeEach
void setUp() {
// The ~/worker-payload/ fallback is derived from user.home, and "/root/" is a built-in
// blocked prefix. When the tests run as root — which they do in a container-based CI, where
// user.home is /root — the fallback directory is itself blocked and the "safe path" cases
// fail for reasons unrelated to what they assert. Pin user.home to a neutral location so
// these tests describe the policy rather than the identity of the user running them.
originalUserHome = System.getProperty("user.home");
System.setProperty("user.home", "/home/conductor-test");

env = mock(Environment.class);
// Default: no file-storage.parentDir set — uses ~/worker-payload/ fallback
when(env.getProperty("conductor.file-storage.parentDir")).thenReturn(null);
Expand All @@ -37,6 +47,15 @@ void setUp() {
policy.resolveEffectiveAllowedDirectories();
}

@AfterEach
void restoreUserHome() {
if (originalUserHome != null) {
System.setProperty("user.home", originalUserHome);
} else {
System.clearProperty("user.home");
}
}

// ========================================================================
// Blocklist — local filesystem sensitive paths
// ========================================================================
Expand Down