mirror of
https://github.com/garrytan/gstack.git
synced 2026-09-22 21:00:51 +02:00
test: pin the security-property regression guards from pre-landing review
The pre-landing review found the fixes were correct but three regression guards were missing — each pins a property whose silent revert would keep behavior identical while reopening the hole: - validateAuth: a static tripwire asserting crypto.timingSafeEqual + the got.length===want.length gate + the null-header guard (a revert to `===` keeps accept/reject green but restores the timing side-channel). - redact: a table-driven loop over the exported URL_PASSWORD_PLACEHOLDER_WORDS so a typo or dropped entry can't silently start blocking a doc placeholder; plus a substring-can't-rescue-a-real-secret assertion. - config: assert the self-contained .gitignore is written even when git already ignores .gstack/, proving the write precedes the isIgnoredByGit early return. - bun-polyfill: cover the 128+signal exit branch (POSIX only). URL_PASSWORD_PLACEHOLDER_WORDS is exported so the table test can't drift. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
341d7be27c
commit
5d74ed7231
@@ -76,6 +76,24 @@ describe('config', () => {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
test('writes the self-contained .gitignore even when git already ignores .gstack/ (before the early return)', () => {
|
||||
// Pins the load-bearing property: the state-dir ignore is written
|
||||
// UNCONDITIONALLY, before the `if (isIgnoredByGit(...)) return` early exit.
|
||||
// A git repo whose root .gitignore already lists .gstack/ makes
|
||||
// isIgnoredByGit true, so the early return fires — moving the write below
|
||||
// it (the exact bug the fix removed) would skip the guard here.
|
||||
const tmpDir = path.join(os.tmpdir(), `browse-gitignored-repo-test-${Date.now()}`);
|
||||
fs.mkdirSync(tmpDir, { recursive: true });
|
||||
Bun.spawnSync(['git', 'init'], { cwd: tmpDir, stdout: 'ignore', stderr: 'ignore' });
|
||||
fs.writeFileSync(path.join(tmpDir, '.gitignore'), '.gstack/\n');
|
||||
const config = resolveConfig({ BROWSE_STATE_FILE: path.join(tmpDir, '.gstack', 'browse.json') });
|
||||
ensureStateDir(config);
|
||||
const selfIgnore = path.join(config.stateDir, '.gitignore');
|
||||
expect(fs.existsSync(selfIgnore)).toBe(true);
|
||||
expect(fs.readFileSync(selfIgnore, 'utf-8')).toBe('*\n');
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
test('adds .gstack/ to .gitignore if not present', () => {
|
||||
const tmpDir = path.join(os.tmpdir(), `browse-gitignore-test-${Date.now()}`);
|
||||
fs.mkdirSync(tmpDir, { recursive: true });
|
||||
|
||||
Reference in New Issue
Block a user