-
Notifications
You must be signed in to change notification settings - Fork 0
feat: retry Schwab refresh with proxy after auth rejection #14
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
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| function normalizeText(value) { | ||
| return String(value ?? '') | ||
| .replace(/[’‘]/g, "'") | ||
| .replace(/\s+/g, ' ') | ||
| .trim(); | ||
| } | ||
|
|
||
| const BANNER_PATTERNS = [ | ||
| /we can'?t log you in right now/i, | ||
| /your (?:login id|user id) or password.*incorrect/i, | ||
| /the (?:login id|user id) or password.*incorrect/i, | ||
| /invalid (?:login|credentials|user id|password)/i, | ||
| /incorrect (?:login id|user id|password)/i, | ||
| /locked/i, | ||
| /too many failed/i, | ||
| /suspicious/i, | ||
| /risk/i, | ||
| ]; | ||
|
|
||
| const RETRYABLE_ERROR_PATTERNS = [ | ||
| /net::ERR_TUNNEL_CONNECTION_FAILED/i, | ||
| /net::ERR_PROXY_CONNECTION_FAILED/i, | ||
| /net::ERR_CONNECTION_REFUSED/i, | ||
| /net::ERR_CONNECTION_RESET/i, | ||
| /net::ERR_CONNECTION_CLOSED/i, | ||
| /login form did not become visible after/i, | ||
| /credential\/risk rejection/i, | ||
| /login page rejected credentials or flagged risk/i, | ||
| /token exchange network error/i, | ||
| ]; | ||
|
|
||
| function looksLikeCredentialOrRiskBanner(value) { | ||
| const text = normalizeText(value); | ||
| return BANNER_PATTERNS.some(pattern => pattern.test(text)); | ||
| } | ||
|
|
||
| function isRetryableWithProxy(value) { | ||
| const text = normalizeText(value); | ||
| return RETRYABLE_ERROR_PATTERNS.some(pattern => pattern.test(text)); | ||
| } | ||
|
|
||
| module.exports = { | ||
| isRetryableWithProxy, | ||
| looksLikeCredentialOrRiskBanner, | ||
| normalizeText, | ||
| }; |
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,33 @@ | ||
| const assert = require('assert'); | ||
|
|
||
| const { | ||
| isRetryableWithProxy, | ||
| looksLikeCredentialOrRiskBanner, | ||
| } = require('../lib/auth_retry'); | ||
|
|
||
| assert.strictEqual( | ||
| looksLikeCredentialOrRiskBanner('We can’t log you in right now. Please try again later.'), | ||
| true, | ||
| ); | ||
|
|
||
| assert.strictEqual( | ||
| looksLikeCredentialOrRiskBanner('Login ID Password'), | ||
| false, | ||
| ); | ||
|
|
||
| assert.strictEqual( | ||
| isRetryableWithProxy('Login page rejected credentials or flagged risk: We can’t log you in right now.'), | ||
| true, | ||
| ); | ||
|
|
||
| assert.strictEqual( | ||
| isRetryableWithProxy('Failure: page.goto: net::ERR_TUNNEL_CONNECTION_FAILED at https://api.schwabapi.com/v1/oauth/authorize'), | ||
| true, | ||
| ); | ||
|
|
||
| assert.strictEqual( | ||
| isRetryableWithProxy('2FA code was rejected after retry.'), | ||
| false, | ||
| ); | ||
|
|
||
| console.log('schwab auth retry checks passed'); |
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
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.
runRefreshOncebuildAttemptPlan()creates attempts with alabelfield, butrunRefreshOncedestructures{ modeLabel, proxyUrl }, somodeLabelis alwaysundefined. That means both direct and proxy attempts reuse the same persistent profile directory (schwab-local-session-undefined) instead of isolated per-mode sessions, which can carry over cookies/state from the failed direct attempt and make the proxy retry unreliable; it also obscures logs for diagnosing which mode ran.Useful? React with 👍 / 👎.