refactor(ipc): harden channels and unify IPC contracts

This commit is contained in:
test
2026-03-08 12:35:00 +08:00
parent 616e2b31a5
commit 8f3e5273e2
25 changed files with 991 additions and 1263 deletions

View File

@@ -0,0 +1,17 @@
import { describe, expect, it } from 'vitest'
import path from 'path'
import { isPathWithinAllowedRoots } from '../../src/main/ipc/file-handler'
describe('File IPC Path Guard', () => {
it('accepts path under allowed root', () => {
const root = path.resolve('C:/safe/root')
const file = path.join(root, 'nested', 'file.txt')
expect(isPathWithinAllowedRoots(file, [root])).toBe(true)
})
it('rejects path outside allowed roots', () => {
const root = path.resolve('C:/safe/root')
const outside = path.resolve('C:/other/location/file.txt')
expect(isPathWithinAllowedRoots(outside, [root])).toBe(false)
})
})