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:
Garry Tan
2026-08-16 11:07:55 -07:00
co-authored by Claude Fable 5
parent 341d7be27c
commit 5d74ed7231
5 changed files with 67 additions and 1 deletions
+18
View File
@@ -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 });