-
Notifications
You must be signed in to change notification settings - Fork 19
test(custody): pin cross-tenant manifest isolation #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -129,6 +129,93 @@ describe('CustodyHandleManifestReader', () => { | |
| }) | ||
| }) | ||
|
|
||
| test('reads our accounts while ignoring a foreign block with unknown account keys', async () => { | ||
| const foreign = { | ||
| provider: 'xai', | ||
| serve: 'opencode-claustrum', | ||
| accounts: [ | ||
| { | ||
| label: 'main', | ||
| handle: `ckh_${'H'.repeat(43)}`, | ||
| credential_id: 'oauth:xai', | ||
| minTtlMs: 7_200_000, | ||
| }, | ||
| ], | ||
| } | ||
| await withManifest( | ||
| serialize({ | ||
| version: 1, | ||
| providers: [ | ||
| foreign, | ||
| { | ||
| provider: 'anthropic', | ||
| shape: 'oauth', | ||
| serve: 'anthropic-auth', | ||
| accounts: [ | ||
| { | ||
| label: 'work-alt', | ||
| handle: `ckh_${'A'.repeat(43)}`, | ||
| credential_id: 'oauth:anthropic:work-alt', | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }), | ||
| async (path) => { | ||
| const result = await reader(path).read() | ||
| expect(result.status).toBe('ready') | ||
| if (result.status !== 'ready') | ||
| throw new Error('expected ready manifest') | ||
| expect(result.manifest.accounts).toEqual([ | ||
| { | ||
| label: 'work-alt', | ||
| handle: `ckh_${'A'.repeat(43)}`, | ||
| credentialId: 'oauth:anthropic:work-alt', | ||
| }, | ||
| ]) | ||
| expect(result.manifest.corruptLabels).toEqual(new Set()) | ||
| }, | ||
| ) | ||
| }) | ||
|
|
||
| test('reads our accounts while ignoring hostile foreign provider entries', async () => { | ||
| await withManifest( | ||
| serialize({ | ||
| version: 1, | ||
| providers: [ | ||
| { | ||
| provider: 'xai', | ||
| serve: 'opencode-claustrum', | ||
| accounts: 'not-an-array', | ||
| }, | ||
| null, | ||
| 42, | ||
| { provider: 'xai' }, | ||
| { | ||
| provider: 'anthropic', | ||
| shape: 'oauth', | ||
| serve: 'anthropic-auth', | ||
| accounts: [ | ||
| { | ||
| label: 'work-alt', | ||
| handle: `ckh_${'A'.repeat(43)}`, | ||
| credential_id: 'oauth:anthropic:work-alt', | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }), | ||
| async (path) => { | ||
| const result = await reader(path).read() | ||
| expect(result.status).toBe('ready') | ||
| if (result.status !== 'ready') | ||
| throw new Error('expected ready manifest') | ||
| expect(result.manifest.accounts).toHaveLength(1) | ||
| expect(result.manifest.corruptLabels).toEqual(new Set()) | ||
| }, | ||
| ) | ||
| }) | ||
|
|
||
| test('ignores an anthropic block with a foreign serve', async () => { | ||
| await withManifest( | ||
| withProvider((provider) => { | ||
|
|
@@ -543,6 +630,55 @@ describe('writeCustodyHandleManifestEntry', () => { | |
| }) | ||
| }) | ||
|
|
||
| test('preserves a foreign block unknown key byte-identically when writing our account', async () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test parses the file and serializes both objects with the same formatter before comparing them. This checks structure and key order, but cannot detect changes to the foreign block's original whitespace or formatting; the writer also reformats the complete document. Rename the test to describe structural or key-order preservation rather than a byte-level guarantee. Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
| const foreign = { | ||
| provider: 'xai', | ||
| serve: 'opencode-claustrum', | ||
| accounts: [ | ||
| { | ||
| label: 'main', | ||
| handle: `ckh_${'H'.repeat(43)}`, | ||
| credential_id: 'oauth:xai', | ||
| minTtlMs: 7_200_000, | ||
| }, | ||
| ], | ||
| } | ||
| await withManifest( | ||
| serialize({ | ||
| version: 1, | ||
| providers: [ | ||
| foreign, | ||
| { | ||
| provider: 'anthropic', | ||
| shape: 'oauth', | ||
| serve: 'anthropic-auth', | ||
| accounts: [], | ||
| }, | ||
| ], | ||
| }), | ||
| async (path) => { | ||
| const result = await writeCustodyHandleManifestEntry({ | ||
| path, | ||
| entry: writerEntry, | ||
| }) | ||
| expect(result).toEqual({ status: 'written' }) | ||
|
|
||
| const output = JSON.parse(await fs.readFile(path, 'utf8')) as { | ||
| providers: Array<Record<string, unknown>> | ||
| } | ||
| const ours = output.providers.find( | ||
| (provider) => | ||
| provider.provider === 'anthropic' && | ||
| provider.serve === 'anthropic-auth', | ||
| ) as { accounts: Array<Record<string, unknown>> } | ||
| expect(ours.accounts.map((account) => account.label)).toContain( | ||
| writerEntry.label, | ||
| ) | ||
| expect(serialize(output.providers[0])).toBe(serialize(foreign)) | ||
| }, | ||
| ) | ||
| }) | ||
|
|
||
| test('repairs a missing OAuth shape while retaining all accounts and foreign blocks', async () => { | ||
| const existingAccount = { | ||
| label: 'existing', | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both new reader fixtures give the foreign block a different
servevalue as well as a different provider. The existing serve selector would therefore still exclude these blocks if provider filtering were accidentally removed, so the tests would not catch that regression. Using a foreign provider withserve: 'anthropic-auth'would independently exercise the provider boundary.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!