Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 04:45 UTC
| 1 | /** |
| 2 | * Real-keystore roundtrip test. |
| 3 | * |
| 4 | * Gated behind `COMPOSIO_KEYRING_E2E=1` so CI and the default |
| 5 | * `pnpm test` run don't touch the user's keychain. Run locally with: |
| 6 | * |
| 7 | * COMPOSIO_KEYRING_E2E=1 pnpm --filter @composio/cli-keyring test |
| 8 | * |
| 9 | * Each test uses a UUID-suffixed service name so parallel runs (and |
| 10 | * leftover entries from crashed runs) never collide with the user's |
| 11 | * real credentials. |
| 12 | */ |
| 13 | |
| 14 | import { describe, it, expect, afterAll, beforeAll } from 'vitest'; |
| 15 | import { randomUUID } from 'node:crypto'; |
| 16 | import { Entry } from '../src/core/entry'; |
| 17 | import { KeyringError } from '../src/core/errors'; |
| 18 | import { createDefaultStore, setDefaultStore } from '../src/index'; |
| 19 | |
| 20 | const enabled = process.env.COMPOSIO_KEYRING_E2E === '1'; |
| 21 | const suite = enabled ? describe : describe.skip; |
| 22 | |
| 23 | suite('e2e: real OS keystore', () => { |
| 24 | beforeAll(async () => { |
| 25 | setDefaultStore(await createDefaultStore()); |
| 26 | }); |
| 27 | |
| 28 | const service = `com.composio.cli.test.${randomUUID()}`; |
| 29 | const user = 'default'; |
| 30 | const entry = new Entry(service, user); |
| 31 | |
| 32 | afterAll(async () => { |
| 33 | try { |
| 34 | await entry.deleteCredential(); |
| 35 | } catch (err) { |
| 36 | if (!(err instanceof KeyringError) || err.kind !== 'NoEntry') { |
| 37 | throw err; |
| 38 | } |
| 39 | } |
| 40 | }); |
| 41 | |
| 42 | it('roundtrips a password', async () => { |
| 43 | const password = `test-${randomUUID()}`; |
| 44 | await entry.setPassword(password); |
| 45 | expect(await entry.getPassword()).toBe(password); |
| 46 | }); |
| 47 | |
| 48 | it('overwrites on repeated setPassword', async () => { |
| 49 | await entry.setPassword('first'); |
| 50 | await entry.setPassword('second'); |
| 51 | expect(await entry.getPassword()).toBe('second'); |
| 52 | }); |
| 53 | |
| 54 | it('delete then get throws NoEntry', async () => { |
| 55 | await entry.setPassword('x'); |
| 56 | await entry.deleteCredential(); |
| 57 | await expect(entry.getPassword()).rejects.toSatisfy( |
| 58 | (err: unknown) => err instanceof KeyringError && err.kind === 'NoEntry' |
| 59 | ); |
| 60 | }); |
| 61 | |
| 62 | it('roundtrips binary bytes', async () => { |
| 63 | const bytes = new Uint8Array([0, 1, 2, 3, 255, 254, 253]); |
| 64 | await entry.setSecret(bytes); |
| 65 | expect(Array.from(await entry.getSecret())).toEqual(Array.from(bytes)); |
| 66 | }); |
| 67 | }); |