Repository navigation
feat: warn before apify mcp install embeds an expiring OAuth token
#1529
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
afd736f
feat: warn before `apify mcp install` embeds an expiring OAuth token
claude 99f7224
fix(mcp install): account-scoped Console link, honest --yes, singular…
claude 1f40651
fix(mcp install): don't round a dying token down to "0 minutes"
claude 8520a3f
refactor(mcp install): keep the established --yes confirmation pattern
claude 1895c49
fix: make --yes skip confirmations on a TTY too
claude 640e815
fix(mcp install): fail instead of hanging when nothing can answer the…
claude 91a1dde
refactor: name the non-interactive default for what it is
claude 81ea87f
Merge branch 'master' into claude/keen-brown-qd7jqh
l2ysho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { existsSync } from 'node:fs'; | ||
| import { mkdir, writeFile } from 'node:fs/promises'; | ||
| import process from 'node:process'; | ||
|
|
||
| // Deliberately NOT mocking `isCI`: a Docker build or a cron job is non-interactive without being | ||
| // CI, and `useStdin` reports `hasData` for such a stdin, so the expiry prompt used to hang there. | ||
| vitest.mock('ci-info', async (importOriginal) => { | ||
| const original = await importOriginal<typeof import('ci-info')>(); | ||
| return { ...original, isCI: false }; | ||
| }); | ||
|
|
||
| import { MCPInstallCommand } from '../../../../src/commands/mcp/install.js'; | ||
| import { testRunCommand } from '../../../../src/lib/command-framework/apify-command.js'; | ||
| import { AUTH_FILE_PATH, CommandExitCodes, GLOBAL_CONFIGS_FOLDER } from '../../../../src/lib/consts.js'; | ||
| import { setSecret } from '../../../../src/lib/credentials.js'; | ||
| import { TEST_USER_ID, v2AuthFile } from '../../../__setup__/auth-file.js'; | ||
| import { useAuthSetup } from '../../../__setup__/hooks/useAuthSetup.js'; | ||
| import { useConsoleSpy } from '../../../__setup__/hooks/useConsoleSpy.js'; | ||
| import { useTempPath } from '../../../__setup__/hooks/useTempPath.js'; | ||
|
|
||
| const STORED_TOKEN = 'apify_api_STORED_zzzzzzzzzzzzzzzzzzzz'; | ||
|
|
||
| const { tmpPath, joinPath, beforeAllCalls, afterAllCalls } = useTempPath('mcp-install-non-tty'); | ||
|
|
||
| useAuthSetup(); | ||
|
|
||
| const { logMessages } = useConsoleSpy(); | ||
|
|
||
| beforeAll(beforeAllCalls); | ||
| afterAll(afterAllCalls); | ||
|
|
||
| beforeEach(async () => { | ||
| vitest.stubEnv('HOME', tmpPath); | ||
| vitest.stubEnv('APIFY_TOKEN', ''); | ||
|
|
||
| await mkdir(GLOBAL_CONFIGS_FOLDER(), { recursive: true }); | ||
| await writeFile( | ||
| AUTH_FILE_PATH(), | ||
| JSON.stringify( | ||
| v2AuthFile({ | ||
| authMethod: 'oauth2', | ||
| expiresAt: new Date(Date.now() + 50 * 60_000).toISOString(), | ||
| hasRefreshToken: true, | ||
| oauth: { | ||
| issuer: 'https://issuer.test', | ||
| clientId: 'https://client.test/oauth-client.json', | ||
| tokenEndpoint: 'https://issuer.test/oauth/apps/token', | ||
| refreshTokenExpiresAt: new Date(Date.now() + 60 * 24 * 60 * 60_000).toISOString(), | ||
| }, | ||
| }), | ||
| ), | ||
| 'utf-8', | ||
| ); | ||
| await setSecret(TEST_USER_ID, 'token', STORED_TOKEN); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| process.exitCode = undefined; | ||
| }); | ||
|
|
||
| describe('apify mcp install, non-interactive but not CI', () => { | ||
| it('fails with the --token hint instead of waiting on a prompt nobody can answer', async () => { | ||
| await testRunCommand(MCPInstallCommand, { args_client: 'cursor' }); | ||
|
|
||
| expect(process.exitCode).toBe(CommandExitCodes.InvalidInput); | ||
| expect(logMessages.error.join('\n')).toMatch(/Pass --token with an API token/); | ||
| expect(existsSync(joinPath('.cursor', 'mcp.json'))).toBe(false); | ||
| }); | ||
|
|
||
| it('--yes writes the config without prompting', async () => { | ||
| await testRunCommand(MCPInstallCommand, { args_client: 'cursor', flags_yes: true }); | ||
|
|
||
| expect(process.exitCode).toBeUndefined(); | ||
| expect(existsSync(joinPath('.cursor', 'mcp.json'))).toBe(true); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Long-lived sounds wonky