and fix #158 - Added `requestExternalFileAccess` method to the Electron API for requesting access to files outside the workspace. - Enhanced security handling in `secureFile.ts` to manage external file access requests with user confirmation. - Updated `resolvePath` function in executors to support external file access under strict workspace mode. - Modified user file access logic to include 'agent-read' as a valid grant source. - Improved tests to cover new external file access functionality and ensure proper authorization handling.
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
import { afterEach, describe, expect, it } from 'vitest'
|
|
import * as path from 'path'
|
|
import {
|
|
authorizeUserFile,
|
|
clearUserFileGrants,
|
|
isUserAuthorizedFile,
|
|
} from '../../../src/main/security/userFileAccess'
|
|
|
|
describe('user file session grants', () => {
|
|
afterEach(() => clearUserFileGrants())
|
|
|
|
it('authorizes only the exact normalized file', () => {
|
|
const target = path.resolve('outside', 'library.ts')
|
|
authorizeUserFile(target, 'lsp-navigation')
|
|
|
|
expect(isUserAuthorizedFile(target)).toBe(true)
|
|
expect(isUserAuthorizedFile(path.join(path.dirname(target), '.', path.basename(target)))).toBe(true)
|
|
expect(isUserAuthorizedFile(path.resolve('outside', 'sibling.ts'))).toBe(false)
|
|
expect(isUserAuthorizedFile(path.dirname(target))).toBe(false)
|
|
})
|
|
|
|
it('authorizes agent-read grants for exact files', () => {
|
|
const target = path.resolve('outside', 'agent-target.ts')
|
|
authorizeUserFile(target, 'agent-read')
|
|
expect(isUserAuthorizedFile(target)).toBe(true)
|
|
expect(isUserAuthorizedFile(path.resolve('outside', 'other.ts'))).toBe(false)
|
|
})
|
|
})
|