Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 44 lines 1.75 KB
Raw
1 /**
2 * Roundtrip check of the Windows Credential Manager store against the real
3 * credential store. It needs `bun:ffi` and Windows, so it is a plain script
4 * rather than a vitest suite:
5 *
6 * bun test/windows-credential.smoke.ts
7 *
8 * The native Windows CI job runs it with the compiled CLI as the Bun runtime.
9 */
10
11 import assert from 'node:assert/strict';
12 import { randomUUID } from 'node:crypto';
13 import { Entry } from '../src/core/entry';
14 import { KeyringError } from '../src/core/errors';
15 import { createDefaultStore, setDefaultStore } from '../src/index';
16
17 const store = await createDefaultStore();
18 assert.equal(store.id, 'windows-credential-ffi');
19 setDefaultStore(store);
20
21 const isNoEntry = (error: unknown) => error instanceof KeyringError && error.kind === 'NoEntry';
22 const entry = new Entry(`com.composio.cli.test.${randomUUID()}`, 'default');
23
24 await assert.rejects(entry.getPassword(), isNoEntry, 'a missing credential reads as NoEntry');
25
26 await entry.setPassword('first');
27 await entry.setPassword('second: ünïcödé ✓');
28 assert.equal(await entry.getPassword(), 'second: ünïcödé ✓', 'the last write wins');
29
30 const bytes = Uint8Array.from({ length: 256 }, (_, index) => index);
31 await entry.setSecret(bytes);
32 assert.deepEqual(Array.from(await entry.getSecret()), Array.from(bytes), 'binary roundtrip');
33
34 await assert.rejects(
35 entry.setSecret(new Uint8Array(4096)),
36 (error: unknown) => error instanceof KeyringError && error.kind === 'TooLong',
37 'an oversized secret is rejected'
38 );
39
40 await entry.deleteCredential();
41 await assert.rejects(entry.getPassword(), isNoEntry, 'a deleted credential reads as NoEntry');
42 await assert.rejects(entry.deleteCredential(), isNoEntry, 'deleting twice reports NoEntry');
43
44 console.log('Windows Credential Manager roundtrip passed.');