fix(volumes): decrypt values before testing connection (#939)

* fix(volumes): decrypt values before testing connection

* chore: lint issue
This commit is contained in:
Nico 2026-06-03 19:05:39 +02:00 committed by GitHub
parent edab1b231b
commit 885ea10f2a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 2 deletions

View file

@ -16,6 +16,7 @@ import { withContext } from "~/server/core/request-context";
import { asShortId } from "~/server/utils/branded";
import { createTestVolume } from "~/test/helpers/volume";
import { config } from "~/server/core/config";
import { cryptoUtils } from "~/server/utils/crypto";
afterEach(() => {
config.flags.enableLocalAgent = false;
@ -286,4 +287,31 @@ describe("volumeService.testConnection", () => {
expect.objectContaining({ name: "volume.testConnection" }),
);
});
test("decrypts encrypted config values before testing the connection", async () => {
config.flags.enableLocalAgent = true;
agentManagerMock.runVolumeCommand.mockResolvedValue({
name: "volume.testConnection",
result: { success: true, message: "Connection successful" },
});
const encryptedPassword = await cryptoUtils.sealSecret("plain-password");
await volumeService.testConnection({
backend: "smb",
server: "127.0.0.1",
share: "backup",
username: "backup-user",
password: encryptedPassword,
domain: "",
vers: "3.0",
port: 445,
mapToContainerUidGid: false,
readOnly: false,
});
expect(agentManagerMock.runVolumeCommand).toHaveBeenCalledWith("local", {
name: "volume.testConnection",
backendConfig: expect.objectContaining({ password: "plain-password" }),
});
});
});

View file

@ -285,11 +285,13 @@ const updateVolume = async (shortId: ShortId, volumeData: UpdateVolumeBody) => {
};
const testConnection = async (backendConfig: BackendConfig) => {
const resolvedConfig = await decryptVolumeConfig(backendConfig);
if (!config.flags.enableLocalAgent) {
return Effect.runPromise(testVolumeConnection(backendConfig));
return Effect.runPromise(testVolumeConnection(resolvedConfig));
}
const command = await runVolumeCommand(LOCAL_AGENT_ID, { name: "volume.testConnection", backendConfig });
const command = await runVolumeCommand(LOCAL_AGENT_ID, { name: "volume.testConnection", backendConfig: resolvedConfig });
return command.result;
};