- Updated the ElectronAPI to support uploading both files and directories, allowing users to specify the upload mode. - Enhanced the remoteShell module to handle directory uploads recursively, including tracking uploaded files and skipped symlinks. - Improved the RemoteFileBrowser component to provide user feedback during uploads and handle different upload modes. - Added utility functions for building remote upload paths and managing upload statistics. - Updated relevant tests to ensure new upload functionality is covered and behaves as expected.
43 lines
1.7 KiB
TypeScript
43 lines
1.7 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import path from 'path'
|
|
import {
|
|
assertSafeRemoteName,
|
|
buildDirectoryDownloadTarget,
|
|
buildDirectoryUploadRemoteTarget,
|
|
isSftpSymbolicLinkMode,
|
|
remoteDirectoryBasename,
|
|
safeJoinUnderDownloadRoot,
|
|
} from '@/shared/utils/remoteDownloadPath'
|
|
|
|
describe('remoteDownloadPath', () => {
|
|
it('builds a destination folder from the remote basename', () => {
|
|
expect(buildDirectoryDownloadTarget('/tmp/downloads', '/home/ubuntu/project')).toBe(
|
|
path.join('/tmp/downloads', 'project'),
|
|
)
|
|
expect(remoteDirectoryBasename('/')).toBe('remote-download')
|
|
expect(remoteDirectoryBasename('/var/log/')).toBe('log')
|
|
})
|
|
|
|
it('builds a remote upload target from the local basename', () => {
|
|
expect(buildDirectoryUploadRemoteTarget('/var/www', '/tmp/my-app')).toBe('/var/www/my-app')
|
|
expect(buildDirectoryUploadRemoteTarget('.', '/tmp/my-app')).toBe('my-app')
|
|
expect(buildDirectoryUploadRemoteTarget('/', '/tmp/my-app')).toBe('/my-app')
|
|
})
|
|
|
|
it('rejects unsafe remote names and path escapes', () => {
|
|
expect(() => assertSafeRemoteName('..')).toThrow(/Unsafe/)
|
|
expect(() => assertSafeRemoteName('a/b')).toThrow(/Unsafe/)
|
|
expect(() => assertSafeRemoteName(' padded ')).toThrow(/Unsafe/)
|
|
expect(() => safeJoinUnderDownloadRoot('/tmp/out', '..')).toThrow()
|
|
expect(safeJoinUnderDownloadRoot('/tmp/out', 'src', 'main.ts')).toBe(
|
|
path.join('/tmp/out', 'src', 'main.ts'),
|
|
)
|
|
})
|
|
|
|
it('detects SFTP symlink mode bits', () => {
|
|
expect(isSftpSymbolicLinkMode(0o120777)).toBe(true)
|
|
expect(isSftpSymbolicLinkMode(0o040755)).toBe(false)
|
|
expect(isSftpSymbolicLinkMode(0o100644)).toBe(false)
|
|
})
|
|
})
|