Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.
JavaScript agent-collaborationagent-harnessagent-orchestrationagent-teamagent-workflowai-assistantai-automationai-employeeai-productivityai-teamai-workflowautonomous-agentsclaude-code-guiclaude-coworkdesktop-agentlocal-firstmulti-agentmulti-agent-systemself-evolving-agentstask-automation
test(connectors): cover damaged credentials and authorization recovery
wyt5a74ac5eb447
diff --git a/test/main/features/connectors/oauth.test.ts b/test/main/features/connectors/oauth.test.tsindex fe2a8f89..f4da9d4c 100644--- a/test/main/features/connectors/oauth.test.ts+++ b/test/main/features/connectors/oauth.test.ts@@ -94,10 +94,13 @@ describe('features/connectors/oauth', () => {expect(JSON.stringify(logInfo.mock.calls)).not.toContain('a'.repeat(43));});- it('requires reconnect when a consumed exchange has no connection credential', async () => {+ it.each([+ ['missing', undefined], ['empty', ''], ['short', 'a'.repeat(42)], ['long', 'a'.repeat(44)],+ ['whitespace', 'a'.repeat(42) + ' '], ['non-ASCII', 'a'.repeat(42) + '中'], ['non-string', { token: 'a'.repeat(43) }],+ ])('requires reconnect when a consumed exchange credential is %s', async (_kind, connectionToken) => {const fetchMock = vi.fn().mockResolvedValueOnce(new Response(JSON.stringify({ code: 0, redirect_url: 'https://provider.example/connect' })))- .mockResolvedValueOnce(new Response(JSON.stringify({ code: 0, connection_id: 'legacy', toolkit: 'gmail', auth_config_id: 'ac_public' })));+ .mockResolvedValueOnce(new Response(JSON.stringify({ code: 0, connection_id: 'legacy', toolkit: 'gmail', auth_config_id: 'ac_public', connection_token: connectionToken })));vi.stubGlobal('fetch', fetchMock);const oauth = await import('../../../../src/main/features/connectors/oauth');const { shell } = await import('electron');@@ -107,6 +110,42 @@ describe('features/connectors/oauth', () => {await oauth.handleCallbackUrl('orkas://connectors/oauth/callback?exchange_code=consumed-code');await rejected;expect(fetchMock).toHaveBeenCalledTimes(2);+ expect(oauth.cancelInFlightOAuth()).toBe(false);+ });++ it.each(['http_503', 'truncated_body'])('requires fresh authorization after %s without retrying the consumed exchange', async (failure) => {+ const start = () => new Response(JSON.stringify({ code: 0, redirect_url: 'https://provider.example/connect' }));+ const broken = failure === 'http_503'+ ? new Response(JSON.stringify({ code: 1, msg: 'Temporarily unavailable' }), { status: 503 })+ : { ok: true, status: 200, text: async () => { throw new Error('response body interrupted'); } };+ const fetchMock = vi.fn()+ .mockImplementationOnce(start)+ .mockResolvedValueOnce(broken)+ .mockImplementationOnce(start)+ .mockResolvedValueOnce(new Response(JSON.stringify({+ code: 0, connection_id: 'replacement', connection_token: 'b'.repeat(43), toolkit: 'gmail', auth_config_id: 'ac_public',+ })));+ vi.stubGlobal('fetch', fetchMock);+ const oauth = await import('../../../../src/main/features/connectors/oauth');+ const { shell } = await import('electron');+ const entry = { id: 'gmail', auth_mode: 'composio' } as any;+ const first = oauth.startComposioConnect(entry);+ const failed = expect(first).rejects.toMatchObject({ code: failure === 'http_503' ? 'exchange_http_5xx' : 'exchange_failed' });+ await vi.waitFor(() => expect(shell.openExternal).toHaveBeenCalledTimes(1));+ await oauth.handleCallbackUrl('orkas://connectors/oauth/callback?exchange_code=consumed');+ await failed;+ expect(fetchMock).toHaveBeenCalledTimes(2);+ expect(oauth.cancelInFlightOAuth()).toBe(false);+ const replacement = oauth.startComposioConnect(entry);+ await vi.waitFor(() => expect(shell.openExternal).toHaveBeenCalledTimes(2));+ await oauth.handleCallbackUrl('orkas://connectors/oauth/callback?exchange_code=fresh');+ await expect(replacement).resolves.toMatchObject({ connection_id: 'replacement', connection_token: 'b'.repeat(43) });+ expect(fetchMock).toHaveBeenCalledTimes(4);+ expect(fetchMock.mock.calls.map(([url]) => new URL(url).pathname)).toEqual([+ '/connectors/composio/start', '/connectors/composio/exchange',+ '/connectors/composio/start', '/connectors/composio/exchange',+ ]);+ expect(JSON.parse(fetchMock.mock.calls[3][1].body).exchange_code).toBe('fresh');});it('does not retry a lost credential exchange response or duplicate callback', async () => {diff --git a/test/main/features/connectors/registry-secret-store.test.ts b/test/main/features/connectors/registry-secret-store.test.tsindex 3a6623ea..48efe860 100644--- a/test/main/features/connectors/registry-secret-store.test.ts+++ b/test/main/features/connectors/registry-secret-store.test.ts@@ -67,6 +67,46 @@ describe('connectors registry secret storage', () => {expect(registry.load(TEST_UID).connections['paid-mail'].composio_grant).toEqual(inst.composio_grant);});+ it.each(['tampered', 'other_owner', 'other_connector'])('preserves unavailable %s connection ciphertext and recovers after restoring the original', async (variation) => {+ let registry = await import('../../../../src/main/features/connectors/registry');+ const paths = await import('../../../../src/main/paths');+ const inst = { ...sampleInstance(), id: 'paid-mail', composio_grant: {+ connection_id: 'connection-1', toolkit: 'gmail', auth_config_id: 'ac_public', connection_token: 'a'.repeat(43),+ } };+ await registry.upsert(TEST_UID, inst);+ const originalFile = paths.userConnectorsConfigFile(TEST_UID);+ const original = fs.readFileSync(originalFile, 'utf8');+ const disk = JSON.parse(original);+ const uid = variation === 'other_owner' ? 'another-owner' : TEST_UID;+ const id = variation === 'other_connector' ? 'other-mail' : inst.id;+ const row = disk.connections[inst.id];+ if (variation === 'tampered') {+ const bytes = Buffer.from(row.secrets_enc, 'base64');+ bytes[bytes.length - 1] ^= 1;+ row.secrets_enc = bytes.toString('base64');+ }+ disk.connections = { [id]: { ...row, id } };+ const file = paths.userConnectorsConfigFile(uid);+ fs.mkdirSync(path.dirname(file), { recursive: true });+ fs.writeFileSync(file, JSON.stringify(disk));+ vi.resetModules();+ registry = await import('../../../../src/main/features/connectors/registry');+ const unavailable = registry.load(uid).connections[id];+ expect(registry.hasUnavailableSecrets(unavailable)).toBe(true);+ expect(unavailable.status).toMatchObject({ kind: 'error', message: 'connector_secrets_unavailable' });+ expect(unavailable.composio_grant).toBeUndefined();+ expect(unavailable.transport).toBeUndefined();+ await registry.update(uid, id, (value) => ({ ...value, tools_cached_at: 42 }));+ const after = JSON.parse(fs.readFileSync(file, 'utf8'));+ expect(after.connections[id].secrets_enc).toBe(row.secrets_enc);+ expect(JSON.stringify(after)).not.toContain(inst.composio_grant.connection_token);+ // Restoring the original encrypted file in its original context remains usable.+ fs.writeFileSync(originalFile, original);+ vi.resetModules();+ registry = await import('../../../../src/main/features/connectors/registry');+ expect(registry.load(TEST_UID).connections[inst.id].composio_grant).toEqual(inst.composio_grant);+ });+it('writes token-bearing fields as local-secret ciphertext', async () => {const registry = await import('../../../../src/main/features/connectors/registry');const paths = await import('../../../../src/main/paths');