Skip to content

Commit df5a3af

Browse files
Mossakaclaude
andcommitted
fix(test): create dummy credential files before testing /dev/null mounts
On CI runners, credential files like ~/.ssh/id_rsa don't exist, so AWF skips the /dev/null mount and the tests find 0 files instead of 11. Create dummy files in beforeAll and clean up in afterAll. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e10ad83 commit df5a3af

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/integration/credential-hiding.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,40 @@ describe('Credential Hiding Security', () => {
245245
{ name: 'Composer auth.json', path: '.composer/auth.json' },
246246
];
247247

248+
// Track files we create so we only clean up what we added
249+
const createdFiles: string[] = [];
250+
const createdDirs: string[] = [];
251+
252+
beforeAll(() => {
253+
// Create dummy credential files on the host so AWF will mount /dev/null over them.
254+
// Without these files existing, AWF skips the /dev/null mount and the files
255+
// simply don't exist inside the container.
256+
const homeDir = os.homedir();
257+
for (const p of untestedPaths) {
258+
const fullPath = `${homeDir}/${p.path}`;
259+
if (!fs.existsSync(fullPath)) {
260+
const dir = fullPath.substring(0, fullPath.lastIndexOf('/'));
261+
if (!fs.existsSync(dir)) {
262+
fs.mkdirSync(dir, { recursive: true });
263+
createdDirs.push(dir);
264+
}
265+
fs.writeFileSync(fullPath, 'DUMMY_SECRET_VALUE');
266+
createdFiles.push(fullPath);
267+
}
268+
}
269+
});
270+
271+
afterAll(() => {
272+
// Clean up only the files/dirs we created
273+
for (const f of createdFiles) {
274+
try { fs.unlinkSync(f); } catch { /* ignore */ }
275+
}
276+
// Remove dirs in reverse order (deepest first)
277+
for (const d of createdDirs.reverse()) {
278+
try { fs.rmdirSync(d); } catch { /* ignore if not empty */ }
279+
}
280+
});
281+
248282
test('All untested credential files are hidden at direct home path (0 bytes)', async () => {
249283
const homeDir = os.homedir();
250284
const paths = untestedPaths.map(p => `${homeDir}/${p.path}`).join(' ');

0 commit comments

Comments
 (0)