perf(core): check the Windows vault key ACL once per process (P1.2)
Every VaultStore construction started PowerShell to re-apply the key ACL. The ACL does not change while the process runs; a created key is still written and hardened by the same PowerShell call.
This commit is contained in:
@@ -471,6 +471,32 @@ describe('VaultStore', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('Windows key protection — an existing key is checked once per process', () => {
|
||||
const dir = makeTempDir();
|
||||
const keyPath = path.join(dir, '.vault-key');
|
||||
fs.writeFileSync(keyPath, 'cd'.repeat(32), { mode: 0o600 });
|
||||
|
||||
const originalPlatform = Object.getOwnPropertyDescriptor(process, 'platform')!;
|
||||
const originalSystemRoot = process.env.SystemRoot;
|
||||
Object.defineProperty(process, 'platform', { value: 'win32', configurable: true });
|
||||
process.env.SystemRoot = 'C:\\Windows';
|
||||
mockExecFileSync.mockImplementation(() => '');
|
||||
|
||||
try {
|
||||
new VaultStore(dir);
|
||||
new VaultStore(dir);
|
||||
new VaultStore(dir);
|
||||
const powershellCalls = mockExecFileSync.mock.calls
|
||||
.filter(([cmd]) => String(cmd).endsWith('powershell.exe'));
|
||||
expect(powershellCalls).toHaveLength(1);
|
||||
} finally {
|
||||
Object.defineProperty(process, 'platform', originalPlatform);
|
||||
if (originalSystemRoot === undefined) delete process.env.SystemRoot;
|
||||
else process.env.SystemRoot = originalSystemRoot;
|
||||
mockExecFileSync.mockReset();
|
||||
}
|
||||
});
|
||||
|
||||
it('Windows key protection — existing keys are re-hardened and retained on failure', () => {
|
||||
const dir = makeTempDir();
|
||||
const keyPath = path.join(dir, '.vault-key');
|
||||
|
||||
Reference in New Issue
Block a user