From 166803b30756b3993b0740592edf0555517dddda Mon Sep 17 00:00:00 2001 From: tcheeric Date: Wed, 25 Nov 2026 21:01:45 +0000 Subject: [PATCH] test(mcp): isolate user.home in NostrMcpServerStdioIT --- .../java/nostr/mcp/NostrMcpServerStdioIT.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/nostr-java-mcp/src/test/java/nostr/mcp/NostrMcpServerStdioIT.java b/nostr-java-mcp/src/test/java/nostr/mcp/NostrMcpServerStdioIT.java index 993abf14..bdc5cf36 100644 --- a/nostr-java-mcp/src/test/java/nostr/mcp/NostrMcpServerStdioIT.java +++ b/nostr-java-mcp/src/test/java/nostr/mcp/NostrMcpServerStdioIT.java @@ -12,6 +12,9 @@ import io.modelcontextprotocol.spec.McpSchema.Tool; import org.junit.jupiter.api.Test; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Files; import java.time.Duration; import java.util.List; import java.util.Map; @@ -270,6 +273,7 @@ private McpSyncClient launchServerWithEnvironment(Map environmen ServerParameters.builder("java") .args( "-Dnostr.mcp.relays.read=" + UNREACHABLE_RELAY, + isolatedUserHome(), "-cp", runtimeClasspath(), NostrMcpApplication.class.getName()) @@ -284,6 +288,7 @@ private McpSyncClient launchServerWithEnvironment(Map environmen private McpSyncClient launchServer(String... extraProperties) { List arguments = new java.util.ArrayList<>(); arguments.add("-Dnostr.mcp.relays.read=" + UNREACHABLE_RELAY); + arguments.add(isolatedUserHome()); arguments.addAll(List.of(extraProperties)); arguments.add("-cp"); arguments.add(runtimeClasspath()); @@ -297,6 +302,18 @@ private McpSyncClient launchServer(String... extraProperties) { .build(); } + /** + * Points the server at an empty home directory, so identities the developer running the build + * has created (indexed under {@code ~/.nostr-java}) do not leak into what the server reports. + */ + private String isolatedUserHome() { + try { + return "-Duser.home=" + Files.createTempDirectory("nostr-mcp-it-home"); + } catch (IOException e) { + throw new UncheckedIOException("Could not create an isolated home directory", e); + } + } + /** The classpath this test is running with, which already contains the module and the SDK. */ private String runtimeClasspath() { return System.getProperty("java.class.path");