fix(email): verify mailbox identity on OAuth reconnect#5648
Conversation
There was a problem hiding this comment.
LGTM, I would suggest adding a new test but it could be done later, PR is in a good state already.
The identity gate now also runs on first-time connects. For a fresh account with empty imap_user/smtp_user, configured_logins is empty, so the gate reduces to "userinfo email must be present" and auto-fill proceeds correct. But no test covers this path: the test helper _make_account defaults both logins to test@example.com, so every callback test exercises a populated row. If someone later tightens any(login != verified_email ...) into a positive match requirement, first-connect breaks with no test catching it. One test with fresh account, successful userinfo, assert tokens stored and imap_user/smtp_user auto-filled would lock in the empty-set semantics.
Summary
Keep Google OAuth reconnects bound to the mailbox already configured on the saved account. The callback now requires a verified user-info email, compares it case-insensitively with every populated IMAP/SMTP login, and refuses to replace credentials when the identities differ.
A successful reconnect also requires and replaces both the access token and the offline refresh token as one pair. Existing tokens remain untouched when identity verification fails or Google omits a fresh refresh token.
Target branch
dev, notmain.Linked Issue
Fixes #5638
Part of #5637
Type of Change
Checklist
dev.How to Test
Run the OAuth and adjacent email suites:
Reconnect a saved Google account with the same mailbox and verify the callback succeeds and replaces both credentials.
Attempt to reconnect it with a different Google identity and verify the callback reports identity verification failure without changing the saved credentials.
Return an access token without a fresh refresh token and verify the existing credential pair remains unchanged.
Current-
devisolated validation passes 150 adjacent tests. Python compilation and diff checks pass. Live Google validation remains a reviewer item.Visual / UI changes
N/A — callback validation and tests only; no UI rendering changed.
Screenshots / clips
N/A — no visual changes.