fix: reject hard-linked project files and verify retained Windows proposals
This commit is contained in:
@@ -60,8 +60,13 @@ test('duplicate canonical paths, ancestor collisions, links, dependencies and Wi
|
||||
const dependency = proposeFile(f.store, f.session, { path: 'node_modules/owned.txt', content: 'dependency', reason: 'excluded' });
|
||||
await assert.rejects(b.manager.prepare(f.session, [dependency.change_id]), /普通源码/);
|
||||
if (process.platform === 'win32') {
|
||||
const windows = proposeFile(f.store, f.session, { path: 'src/one.mjs.', content: 'alias', reason: 'windows alias' });
|
||||
await assert.rejects(b.manager.prepare(f.session, [windows.change_id]), /路径别名/);
|
||||
assert.throws(() => proposeFile(f.store, f.session, { path: 'src/one.mjs.', content: 'alias', reason: 'windows alias' }), /可读取的项目范围/);
|
||||
// A proposal retained from an older host must still be refused by batch
|
||||
// validation even though the current proposal API now rejects it earlier.
|
||||
const retained = f.session.changes.find(value => value.id === alias.change_id), originalPath = retained.path;
|
||||
retained.path = 'src/one.mjs.';
|
||||
try { await assert.rejects(b.manager.prepare(f.session, [retained.id]), /可读取的项目范围/); }
|
||||
finally { retained.path = originalPath; }
|
||||
}
|
||||
assertBatchBytes(assert, f, b.before);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fixture } from './helpers.mjs';
|
||||
import { readText, listFiles, proposeFile } from '../src/server/files.mjs';
|
||||
import { inspectProject } from '../src/core/project-inspector.mjs';
|
||||
|
||||
test('hard-link aliases cannot expose protected bytes through reads, proposals, inventory or automatic project rules', async t => {
|
||||
const f = fixture(t);
|
||||
fs.mkdirSync(path.join(f.projectRoot, '.git')); fs.mkdirSync(path.join(f.projectRoot, '.secrets'));
|
||||
fs.writeFileSync(path.join(f.projectRoot, '.git/config'), '[core]\nrepositoryformatversion = 0\n');
|
||||
fs.writeFileSync(path.join(f.projectRoot, '.secrets/owned.txt'), 'owned-protected-rule-marker');
|
||||
fs.linkSync(path.join(f.projectRoot, '.git/config'), path.join(f.projectRoot, 'public-config.txt'));
|
||||
fs.linkSync(path.join(f.projectRoot, '.secrets/owned.txt'), path.join(f.projectRoot, 'AGENTS.md'));
|
||||
for (const filename of ['public-config.txt', 'AGENTS.md']) {
|
||||
assert.throws(() => readText(f.project, filename), /硬链接/);
|
||||
assert.throws(() => proposeFile(f.store, f.session, { path: filename, content: 'new bytes' }), /硬链接/);
|
||||
}
|
||||
const inventory = listFiles(f.project); assert.ok(!inventory.files.some(value => ['public-config.txt', 'AGENTS.md'].includes(value.path)));
|
||||
const inspection = await inspectProject(f.project); assert.equal(inspection.rules.length, 0);
|
||||
assert.equal(JSON.stringify(inspection).includes('owned-protected-rule-marker'), false);
|
||||
assert.equal(fs.readFileSync(path.join(f.projectRoot, '.secrets/owned.txt'), 'utf8'), 'owned-protected-rule-marker');
|
||||
});
|
||||
|
||||
test('ambiguous project hard links are explicit and ordinary independent file copies remain readable', t => {
|
||||
const f = fixture(t), original = path.join(f.projectRoot, 'README.md'), alias = path.join(f.projectRoot, 'alias.md');
|
||||
fs.linkSync(original, alias);
|
||||
assert.throws(() => readText(f.project, 'README.md'), /独立文件副本/); assert.throws(() => readText(f.project, 'alias.md'), /硬链接/);
|
||||
fs.unlinkSync(alias); fs.copyFileSync(original, alias);
|
||||
assert.match(readText(f.project, 'README.md').content, /Fixture project/);
|
||||
assert.match(readText(f.project, 'alias.md').content, /Fixture project/);
|
||||
assert.ok(listFiles(f.project).files.some(value => value.path === 'alias.md'));
|
||||
});
|
||||
Reference in New Issue
Block a user