fix(volumes): isolate test-connection mounts in temp directories
This commit is contained in:
parent
8ece1ef187
commit
694f1c212f
3 changed files with 36 additions and 11 deletions
|
|
@ -19,27 +19,25 @@ export type VolumeBackend = {
|
||||||
checkHealth: () => Promise<OperationResult>;
|
checkHealth: () => Promise<OperationResult>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createVolumeBackend = (volume: Volume): VolumeBackend => {
|
export const createVolumeBackend = (volume: Volume, mountPath = getVolumePath(volume)): VolumeBackend => {
|
||||||
const path = getVolumePath(volume);
|
|
||||||
|
|
||||||
switch (volume.config.backend) {
|
switch (volume.config.backend) {
|
||||||
case "nfs": {
|
case "nfs": {
|
||||||
return makeNfsBackend(volume.config, path);
|
return makeNfsBackend(volume.config, mountPath);
|
||||||
}
|
}
|
||||||
case "smb": {
|
case "smb": {
|
||||||
return makeSmbBackend(volume.config, path);
|
return makeSmbBackend(volume.config, mountPath);
|
||||||
}
|
}
|
||||||
case "directory": {
|
case "directory": {
|
||||||
return makeDirectoryBackend(volume.config, path);
|
return makeDirectoryBackend(volume.config, mountPath);
|
||||||
}
|
}
|
||||||
case "webdav": {
|
case "webdav": {
|
||||||
return makeWebdavBackend(volume.config, path);
|
return makeWebdavBackend(volume.config, mountPath);
|
||||||
}
|
}
|
||||||
case "rclone": {
|
case "rclone": {
|
||||||
return makeRcloneBackend(volume.config, path);
|
return makeRcloneBackend(volume.config, mountPath);
|
||||||
}
|
}
|
||||||
case "sftp": {
|
case "sftp": {
|
||||||
return makeSftpBackend(volume.config, path);
|
return makeSftpBackend(volume.config, mountPath);
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
throw new Error("Unsupported backend");
|
throw new Error("Unsupported backend");
|
||||||
|
|
|
||||||
|
|
@ -211,3 +211,31 @@ describe("volumeService.ensureHealthyVolume", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("volumeService.testConnection", () => {
|
||||||
|
test("uses an isolated temp mount path for backend test connections", async () => {
|
||||||
|
const mount = vi.fn().mockResolvedValue({ status: "mounted" });
|
||||||
|
const unmount = vi.fn().mockResolvedValue({ status: "unmounted" });
|
||||||
|
const createVolumeBackendSpy = vi.spyOn(backendModule, "createVolumeBackend").mockReturnValue({
|
||||||
|
mount,
|
||||||
|
unmount,
|
||||||
|
checkHealth: vi.fn(),
|
||||||
|
});
|
||||||
|
|
||||||
|
await volumeService.testConnection({
|
||||||
|
backend: "nfs",
|
||||||
|
server: "127.0.0.1",
|
||||||
|
exportPath: "/exports/test",
|
||||||
|
version: "4",
|
||||||
|
port: 2049,
|
||||||
|
readOnly: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(createVolumeBackendSpy).toHaveBeenCalledOnce();
|
||||||
|
const [, mountPath] = createVolumeBackendSpy.mock.calls[0];
|
||||||
|
expect(mountPath).toEqual(expect.stringContaining(`${path.sep}zerobyte-test-`));
|
||||||
|
await expect(fs.access(mountPath as string)).rejects.toThrow();
|
||||||
|
expect(mount).toHaveBeenCalledOnce();
|
||||||
|
expect(unmount).toHaveBeenCalledOnce();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -237,7 +237,6 @@ const testConnection = async (backendConfig: BackendConfig) => {
|
||||||
id: 0,
|
id: 0,
|
||||||
shortId: asShortId("test"),
|
shortId: asShortId("test"),
|
||||||
name: "test-connection",
|
name: "test-connection",
|
||||||
path: tempDir,
|
|
||||||
config: encryptedConfig,
|
config: encryptedConfig,
|
||||||
createdAt: Date.now(),
|
createdAt: Date.now(),
|
||||||
updatedAt: Date.now(),
|
updatedAt: Date.now(),
|
||||||
|
|
@ -250,7 +249,7 @@ const testConnection = async (backendConfig: BackendConfig) => {
|
||||||
organizationId: "test-org",
|
organizationId: "test-org",
|
||||||
};
|
};
|
||||||
|
|
||||||
const backend = createVolumeBackend(mockVolume);
|
const backend = createVolumeBackend(mockVolume, tempDir);
|
||||||
const { error } = await backend.mount();
|
const { error } = await backend.mount();
|
||||||
|
|
||||||
await backend.unmount();
|
await backend.unmount();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue