Skip to content

Commit 4b4ef42

Browse files
committed
test(aws-secrets-inspector): assert runs.log and parent dir are owner-only
Add two POSIX-only tests, one per branch (inspector and retrieve), that pre-create ~/.cache/claude-grc at 0o755 and runs.log at 0o644 before running collect.js. The pre-creation forces the chmod-after calls to do real work; without it, fs.mkdir's mode option would create the dir at 0o700 and fs.appendFile's mode option would create the file at 0o600 on first run, masking any regression in the chmod-after path (Node honors the mode option only on creation). Each test asserts the post-run mode of both the file (0o600) and its parent directory (0o700).
1 parent 06ac15d commit 4b4ef42

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

tests/aws-secrets-inspector-collect.test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,4 +354,54 @@ test('retrieval mode records the resolved region in the runs.log manifest', asyn
354354
const manifest = JSON.parse(runsLog.trim().split('\n').pop());
355355
assert.equal(manifest.region, 'ap-southeast-2', 'manifest should fall back to AWS_DEFAULT_REGION');
356356
}
357+
});
358+
359+
test('inspector branch leaves runs.log at 0o600 and parent dir at 0o700 on POSIX', async () => {
360+
if (process.platform === 'win32') return; // chmod is a no-op on Windows
361+
362+
const { home, env } = await makeEnv();
363+
const parentDir = path.join(home, '.cache', 'claude-grc');
364+
const runsLogPath = path.join(parentDir, 'runs.log');
365+
366+
// Pre-create at default umask to force the chmod-after path to do real
367+
// work. Without this pre-creation, fs.mkdir's mode option would create
368+
// the dir at 0o700 and fs.appendFile's mode option would create the
369+
// file at 0o600 on first run, masking a regression in the chmod-after
370+
// calls (Node honors the mode option only on creation).
371+
await fs.mkdir(parentDir, { recursive: true });
372+
await fs.chmod(parentDir, 0o755);
373+
await fs.writeFile(runsLogPath, '');
374+
await fs.chmod(runsLogPath, 0o644);
375+
376+
const result = runCollect(env, ['--quiet']);
377+
assert.equal(result.status, 0, `stderr: ${result.stderr}`);
378+
379+
const dirStat = await fs.stat(parentDir);
380+
const fileStat = await fs.stat(runsLogPath);
381+
assert.equal((dirStat.mode & 0o777), 0o700, `parent dir not tightened: ${(dirStat.mode & 0o777).toString(8)}`);
382+
assert.equal((fileStat.mode & 0o777), 0o600, `runs.log not tightened: ${(fileStat.mode & 0o777).toString(8)}`);
383+
});
384+
385+
test('retrieve branch leaves runs.log at 0o600 and parent dir at 0o700 on POSIX', async () => {
386+
if (process.platform === 'win32') return; // chmod is a no-op on Windows
387+
388+
const { home, env } = await makeEnv();
389+
const parentDir = path.join(home, '.cache', 'claude-grc');
390+
const runsLogPath = path.join(parentDir, 'runs.log');
391+
const arn = 'arn:aws:secretsmanager:us-east-1:123456789012:secret:legacy-db-credentials-AbCdEf';
392+
393+
// Pre-create at default umask to force the chmod-after path to do real
394+
// work (same rationale as the inspector test above).
395+
await fs.mkdir(parentDir, { recursive: true });
396+
await fs.chmod(parentDir, 0o755);
397+
await fs.writeFile(runsLogPath, '');
398+
await fs.chmod(runsLogPath, 0o644);
399+
400+
const result = runCollect(env, ['--retrieve=' + arn, '--quiet']);
401+
assert.equal(result.status, 0, `stderr: ${result.stderr}`);
402+
403+
const dirStat = await fs.stat(parentDir);
404+
const fileStat = await fs.stat(runsLogPath);
405+
assert.equal((dirStat.mode & 0o777), 0o700, `parent dir not tightened: ${(dirStat.mode & 0o777).toString(8)}`);
406+
assert.equal((fileStat.mode & 0o777), 0o600, `runs.log not tightened: ${(fileStat.mode & 0o777).toString(8)}`);
357407
});

0 commit comments

Comments
 (0)