test(core): test the SecretStore contract on VaultStore (P1.2)
secret-store.test.ts covers get, set, setAsync, writeBatch, delete, deleteAsync, list and has through the interface. vault.test.ts keeps what is specific to the file backend: encryption, the key file and the Windows ACL.
This commit is contained in:
@@ -61,88 +61,6 @@ describe('VaultStore', () => {
|
||||
mockExecFileSync.mockReset();
|
||||
});
|
||||
|
||||
it('set and get — store a secret, retrieve it, value matches', () => {
|
||||
const dir = makeTempDir();
|
||||
const vault = new VaultStore(dir);
|
||||
|
||||
vault.set('anthropic', 'sk-ant-secret-key-123');
|
||||
|
||||
const entry = vault.get('anthropic');
|
||||
expect(entry).not.toBeNull();
|
||||
expect(entry!.name).toBe('anthropic');
|
||||
expect(entry!.value).toBe('sk-ant-secret-key-123');
|
||||
expect(entry!.updatedAt).toBeTruthy();
|
||||
});
|
||||
|
||||
it('set overwrites — set same name twice, get returns latest', () => {
|
||||
const dir = makeTempDir();
|
||||
const vault = new VaultStore(dir);
|
||||
|
||||
vault.set('openai', 'sk-old-key');
|
||||
vault.set('openai', 'sk-new-key');
|
||||
|
||||
const entry = vault.get('openai');
|
||||
expect(entry).not.toBeNull();
|
||||
expect(entry!.value).toBe('sk-new-key');
|
||||
});
|
||||
|
||||
it('get nonexistent — returns null', () => {
|
||||
const dir = makeTempDir();
|
||||
const vault = new VaultStore(dir);
|
||||
|
||||
expect(vault.get('doesnotexist')).toBeNull();
|
||||
});
|
||||
|
||||
it('delete — removes secret, get returns null after', () => {
|
||||
const dir = makeTempDir();
|
||||
const vault = new VaultStore(dir);
|
||||
|
||||
vault.set('anthropic', 'sk-ant-key');
|
||||
expect(vault.delete('anthropic')).toBe(true);
|
||||
expect(vault.get('anthropic')).toBeNull();
|
||||
});
|
||||
|
||||
it('delete nonexistent — returns false', () => {
|
||||
const dir = makeTempDir();
|
||||
const vault = new VaultStore(dir);
|
||||
|
||||
expect(vault.delete('nope')).toBe(false);
|
||||
});
|
||||
|
||||
it('list — shows names + metadata without values', () => {
|
||||
const dir = makeTempDir();
|
||||
const vault = new VaultStore(dir);
|
||||
|
||||
vault.set('anthropic', 'sk-ant-key', { models: ['claude-sonnet-4-6'] });
|
||||
vault.set('openai', 'sk-openai-key', { models: ['gpt-4o'], baseUrl: 'https://api.openai.com' });
|
||||
|
||||
const entries = vault.list();
|
||||
expect(entries).toHaveLength(2);
|
||||
|
||||
const names = entries.map(e => e.name);
|
||||
expect(names).toContain('anthropic');
|
||||
expect(names).toContain('openai');
|
||||
|
||||
// list must NOT contain secret values
|
||||
for (const entry of entries) {
|
||||
expect(entry).not.toHaveProperty('value');
|
||||
expect(entry.updatedAt).toBeTruthy();
|
||||
}
|
||||
|
||||
const anthropicEntry = entries.find(e => e.name === 'anthropic')!;
|
||||
expect(anthropicEntry.metadata).toEqual({ models: ['claude-sonnet-4-6'] });
|
||||
});
|
||||
|
||||
it('has — returns true for existing, false for missing', () => {
|
||||
const dir = makeTempDir();
|
||||
const vault = new VaultStore(dir);
|
||||
|
||||
vault.set('anthropic', 'sk-ant-key');
|
||||
|
||||
expect(vault.has('anthropic')).toBe(true);
|
||||
expect(vault.has('missing')).toBe(false);
|
||||
});
|
||||
|
||||
it('encryption is real — vault.json does NOT contain plaintext value', () => {
|
||||
const dir = makeTempDir();
|
||||
const vault = new VaultStore(dir);
|
||||
|
||||
Reference in New Issue
Block a user