mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-10-24 07:39:36 +00:00
os.homedir() reads USERPROFILE on Windows and never HOME, so the isolation setup and every test that moved home were still resolving the developer's real home directory. Fixtures came back empty, real sessions leaked into counts, and the code under test wrote plans, receipts and a sync ledger into the real ~/.config/codeburn during a run. USERPROFILE now joins the redirected variables and a shared setHome() helper moves HOME and USERPROFILE together; every spawn env carries both. The remaining Windows-only failures were POSIX-shaped fixtures: chmod tricks that only toggle a read-only attribute on NTFS, pid 1 as an always-alive lock holder, splitting paths on '/', bare tar, mode-bit expectations, and per-file timeouts too short for the cost of a tsx spawn. Each gets a platform-aware equivalent so nothing is skipped on Windows and the POSIX branches stay byte-for-byte what they were. Full run on Windows: 267 files passed, 2 skipped, 3592 tests passed.
44 lines
1.8 KiB
TypeScript
44 lines
1.8 KiB
TypeScript
// Independent review finding: tar entry validation was blind to symlinks
|
|
// (tar -tzf hides "-> target"), so a symlink could reach extraction before
|
|
// the post-extract symlink check runs. Reject non-regular entries up front.
|
|
import { describe, it, expect } from 'vitest'
|
|
import { mkdtemp, rm, mkdir, writeFile, symlink } from 'fs/promises'
|
|
import { join } from 'path'
|
|
import { tmpdir } from 'os'
|
|
import { execFile } from 'child_process'
|
|
import { promisify } from 'util'
|
|
import { tarBin, validateTarEntries } from '../src/plugins/cli.js'
|
|
|
|
const run = promisify(execFile)
|
|
|
|
describe('tarball entry-type validation', () => {
|
|
it('rejects a tarball containing a symlink entry', async () => {
|
|
const dir = await mkdtemp(join(tmpdir(), 'tarsec-'))
|
|
try {
|
|
const build = join(dir, 'build')
|
|
await mkdir(build, { recursive: true })
|
|
await writeFile(join(build, 'ok.txt'), 'fine')
|
|
await symlink('/etc/hosts', join(build, 'evil-link'))
|
|
const tarFile = join(dir, 'evil.tgz')
|
|
await run(tarBin(), ['-czf', tarFile, '-C', build, 'ok.txt', 'evil-link'])
|
|
await expect(validateTarEntries(tarFile)).rejects.toThrow(/non-regular entry/)
|
|
} finally {
|
|
await rm(dir, { recursive: true, force: true })
|
|
}
|
|
})
|
|
|
|
it('accepts a tarball of plain files and directories', async () => {
|
|
const dir = await mkdtemp(join(tmpdir(), 'tarsec2-'))
|
|
try {
|
|
const build = join(dir, 'build')
|
|
await mkdir(join(build, 'sub'), { recursive: true })
|
|
await writeFile(join(build, 'a.txt'), 'a')
|
|
await writeFile(join(build, 'sub', 'b.txt'), 'b')
|
|
const tarFile = join(dir, 'good.tgz')
|
|
await run(tarBin(), ['-czf', tarFile, '-C', build, '.'])
|
|
await expect(validateTarEntries(tarFile)).resolves.toBeUndefined()
|
|
} finally {
|
|
await rm(dir, { recursive: true, force: true })
|
|
}
|
|
})
|
|
})
|