mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
Plugins that instrument the user's application had no way to get a Java agent into the JVM the IDE starts. A [[contributes.javaAgents]] entry (one per plugin, a jar inside the package, optional single-line args, API ^1.10) derives the high-risk java.agent capability; granting it records the jar's blake3 hash, and every launch re-hashes the jar and leaves out a changed or missing one until approved again. For Application, Spring Boot and JAR Application run and debug, the host adds one -javaagent argument after the VM options (java-debug vmArgs, Kotlin vmArguments), never twice, and a shortened command line keeps it as its own argument. Remote projects and run targets get no agent, with one console line. Settings › Plugins shows the agent next to the permission. Closes #3566 Co-authored-by: bertyhell <1710840+bertyhell@users.noreply.github.com>
52 lines
1.9 KiB
TypeScript
52 lines
1.9 KiB
TypeScript
import { beforeEach, expect, it, vi } from "vitest";
|
|
import type { CapabilityInfo, PluginInfo } from "@/platform/ipc";
|
|
|
|
const state = vi.hoisted(() => ({ remote: false, plugins: [] as unknown[] }));
|
|
vi.mock("@/platform/remote", () => ({ isRemoteWindow: () => state.remote }));
|
|
vi.mock("@/platform/ipc", async (original) => {
|
|
const real = await original<typeof import("@/platform/ipc")>();
|
|
return {
|
|
...real,
|
|
commands: {
|
|
...real.commands,
|
|
pluginList: vi.fn(() => Promise.resolve({ status: "ok", data: { plugins: state.plugins } })),
|
|
},
|
|
};
|
|
});
|
|
|
|
const { remoteJavaAgentNote } = await import("./javaLaunch");
|
|
|
|
function plugin(name: string, enabled: boolean, granted: boolean | null): PluginInfo {
|
|
const capabilities: CapabilityInfo[] =
|
|
granted === null ? [] : [{ id: "java.agent", risk: "high", description: "", optional: true, granted }];
|
|
return { name, enabled, capabilities } as unknown as PluginInfo;
|
|
}
|
|
|
|
beforeEach(() => {
|
|
state.remote = true;
|
|
state.plugins = [
|
|
plugin("Spring Agent", true, true),
|
|
plugin("Refused", true, false),
|
|
plugin("Off", false, true),
|
|
plugin("Theme", true, null),
|
|
];
|
|
});
|
|
|
|
it("says once that a remote Java launch got no agent, naming the plugins with a granted one", async () => {
|
|
for (const kind of ["application", "spring-boot", "jar-application"]) {
|
|
expect(await remoteJavaAgentNote({ kind })).toBe(
|
|
"Java agents of Spring Agent were not added: they load only in local projects.\n",
|
|
);
|
|
}
|
|
});
|
|
|
|
it("says nothing for local projects, other kinds, or without a granted agent", async () => {
|
|
expect(await remoteJavaAgentNote({ kind: "maven" })).toBeNull();
|
|
expect(await remoteJavaAgentNote({ kind: "junit" })).toBeNull();
|
|
state.remote = false;
|
|
expect(await remoteJavaAgentNote({ kind: "application" })).toBeNull();
|
|
state.remote = true;
|
|
state.plugins = [plugin("Refused", true, false)];
|
|
expect(await remoteJavaAgentNote({ kind: "application" })).toBeNull();
|
|
});
|