test(nominatim): share one POSIX guard and say the cache is private only on POSIX

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
quanticsoul4772andClaude Opus 5.5 committed 2026-11-05 05:43:36 -08:00
1 parent c2a04c11b7
commit e5ab5f945a
1 file changed
+12 -7
+12 -7
View File
@@ -684,29 +684,34 @@ test('the disk cache survives a restart and stays within its bounds', async () =
await createNominatimCache({ dir, now: time.now }).get('k0'),
null,
);
// Windows has no POSIX mode bits (directories stat as 0o666), so only
// POSIX systems can check privacy this way.
if (process.platform !== 'win32')
// The cache is private only through POSIX mode bits. Windows has none
// (directories stat as 0o666) and the cache keeps the checkout's ACLs,
// so these checks run, and privacy holds, only on POSIX systems.
const posixModes = process.platform !== 'win32';
if (posixModes) {
assert.equal(
fs.statSync(dir).mode & 0o777,
0o700,
'the query cache directory is private',
'the query cache directory is private (POSIX modes)',
);
}
const text = fs
.readdirSync(dir)
.filter((name) => name.endsWith('.json'))
.map((name) => fs.readFileSync(path.join(dir, name), 'utf8'))
.join('\n');
assert.equal(text.includes('k4'), false, 'disk entries never store raw keys');
if (process.platform !== 'win32')
if (posixModes) {
for (const name of fs
.readdirSync(dir)
.filter((entry) => entry.endsWith('.json')))
.filter((entry) => entry.endsWith('.json'))) {
assert.equal(
fs.statSync(path.join(dir, name)).mode & 0o777,
0o600,
`${name} is private`,
`${name} is private (POSIX modes)`,
);
}
}
fs.rmSync(dir, { recursive: true, force: true });
});