mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
fix(plugins): ask before loading a changed Java agent (#4003)
When a plugin's Java agent jar changed, the host already refused to load it until java.agent was granted again, but Settings still showed the permission as granted, so the agent silently disappeared from Run/Debug. PluginInfo now carries the agent's file name, arguments and whether its jar still matches the approved hash; Settings › Plugins warns about a changed jar and offers Approve new jar, which grants the permission again. Co-authored-by: NeverKnowsTomorrow <36879844+NeverKnowsTomorrow@users.noreply.github.com>
This commit is contained in:
@@ -581,7 +581,7 @@ function CapabilityList({ plugin, busy }: { plugin: PluginInfo; busy: boolean })
|
||||
c.id.startsWith("process:") ? (
|
||||
<ProgramPermission plugin={plugin} cap={c} disabled={busy || !confirmed} />
|
||||
) : (
|
||||
c.id === "java.agent" && <JavaAgentDetail plugin={plugin} />
|
||||
c.id === "java.agent" && <JavaAgentDetail plugin={plugin} cap={c} disabled={busy || !confirmed} />
|
||||
)
|
||||
}
|
||||
>
|
||||
@@ -601,14 +601,31 @@ function CapabilityList({ plugin, busy }: { plugin: PluginInfo; busy: boolean })
|
||||
}
|
||||
|
||||
/** The agent a `java.agent` grant loads: its jar's file name and arguments, as `-javaagent:` takes them. */
|
||||
function JavaAgentDetail({ plugin }: { plugin: PluginInfo }) {
|
||||
const agent = plugin.contributions.find((c) => c.point === "javaAgents");
|
||||
function JavaAgentDetail({ plugin, cap, disabled }: { plugin: PluginInfo; cap: CapabilityInfo; disabled: boolean }) {
|
||||
const agent = plugin.javaAgent;
|
||||
if (!agent) return null;
|
||||
const approve = async () => {
|
||||
// Revoking and granting again recomputes the jar's hash in the host.
|
||||
if (await setPluginCapability(plugin.id, cap.id, false)) {
|
||||
await setPluginCapability(plugin.id, cap.id, true);
|
||||
}
|
||||
};
|
||||
return (
|
||||
<div className={styles.programPermission}>
|
||||
<span className={clsx(styles.mono, styles.programPath)} aria-label={tx("Java agent")}>
|
||||
{agent.label}
|
||||
{agent.fileName}
|
||||
{agent.args ? `=${agent.args}` : ""}
|
||||
</span>
|
||||
{cap.granted && !agent.approved && (
|
||||
<div className={styles.error} role="alert">
|
||||
<p>
|
||||
<T>The agent jar changed since you approved it. Approve the new jar before the next launch.</T>
|
||||
</p>
|
||||
<Button size="small" variant="primary" disabled={disabled} onClick={() => void approve()}>
|
||||
<T>Approve new jar</T>
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ function plugin(partial: Partial<PluginInfo> & Pick<PluginInfo, "id">): PluginIn
|
||||
homepage: null,
|
||||
changeNotes: null,
|
||||
icon: null,
|
||||
javaAgent: null,
|
||||
source: "installed",
|
||||
path: `/plugins/${partial.id}`,
|
||||
enabled: true,
|
||||
@@ -1604,6 +1605,7 @@ describe("marketplace", () => {
|
||||
},
|
||||
],
|
||||
contributions: [{ point: "javaAgents", label: "spring-agent.jar=port=0" }],
|
||||
javaAgent: { fileName: "spring-agent.jar", args: "port=0", approved: true },
|
||||
}),
|
||||
]),
|
||||
);
|
||||
@@ -1613,6 +1615,47 @@ describe("marketplace", () => {
|
||||
expect(within(permissions).getByLabelText("Java agent")).toHaveTextContent("spring-agent.jar=port=0");
|
||||
});
|
||||
|
||||
it("warns when a granted Java agent jar changed and can approve it again", async () => {
|
||||
const user = userEvent.setup();
|
||||
const base = createMemoryPluginsBackend([
|
||||
plugin({
|
||||
id: "spring",
|
||||
name: "Spring",
|
||||
hasCode: false,
|
||||
status: "static",
|
||||
javaAgent: { fileName: "spring-agent.jar", args: null, approved: false },
|
||||
capabilities: [
|
||||
{
|
||||
id: "java.agent",
|
||||
risk: "high",
|
||||
description: "Run code inside the Java applications you start",
|
||||
optional: true,
|
||||
granted: true,
|
||||
},
|
||||
],
|
||||
contributions: [{ point: "javaAgents", label: "spring-agent.jar" }],
|
||||
}),
|
||||
]);
|
||||
const calls: [string, string, boolean][] = [];
|
||||
setPluginsBackend({
|
||||
...base,
|
||||
setCapability: async (id, capability, granted) => {
|
||||
calls.push([id, capability, granted]);
|
||||
return base.setCapability(id, capability, granted);
|
||||
},
|
||||
});
|
||||
render(<PluginsPage initialTab="installed" />);
|
||||
const permissions = await screen.findByRole("list", { name: "Permissions" });
|
||||
expect(within(permissions).getByRole("alert")).toHaveTextContent("The agent jar changed since you approved it");
|
||||
await user.click(within(permissions).getByRole("button", { name: "Approve new jar" }));
|
||||
await waitFor(() =>
|
||||
expect(calls).toEqual([
|
||||
["spring", "java.agent", false],
|
||||
["spring", "java.agent", true],
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it("offers to roll back an update", async () => {
|
||||
const base = createMemoryPluginsBackend([
|
||||
plugin({ id: "p", name: "P", version: "2.0.0", previousVersion: "1.0.0" }),
|
||||
|
||||
@@ -453,6 +453,7 @@ function samplePlugins(): PluginInfo[] {
|
||||
homepage: null,
|
||||
changeNotes: null,
|
||||
icon: null,
|
||||
javaAgent: null,
|
||||
source: "installed" as const,
|
||||
enabled: true,
|
||||
error: null,
|
||||
|
||||
Reference in New Issue
Block a user