Skip to content

fix(email): test saved OAuth accounts through shared transports#5653

Open
RaresKeY wants to merge 3 commits into
odysseus-dev:devfrom
RaresKeY:fix/email-oauth-account-test
Open

fix(email): test saved OAuth accounts through shared transports#5653
RaresKeY wants to merge 3 commits into
odysseus-dev:devfrom
RaresKeY:fix/email-oauth-account-test

Conversation

@RaresKeY

Copy link
Copy Markdown
Collaborator

Summary

Let the saved-account Test connection action authenticate Google OAuth
accounts without requiring stored IMAP/SMTP passwords. The route resolves
OAuth only from the owner-checked saved row, keeps inline form values on the
password path, and reports the real IMAP and SMTP results independently.

This replacement preserves TNTBA's two focused commits from #5021 and keeps
the current-dev owner and authentication updates in a separate maintainer commit.

Related implementation

Supersedes #5021 on current dev while preserving its original authored commits.

Target branch

  • This PR targets dev, not main.

Linked Issue

Fixes #5644

Part of #5637

Type of Change

  • Bug fix (non-breaking — fixes a confirmed issue)
  • New feature (non-breaking — adds new behaviour)
  • Breaking change (changes or removes existing behaviour)
  • Refactor / cleanup (behaviour unchanged)
  • Documentation only
  • CI / tooling / configuration

Checklist

  • I searched open issues and open PRs — fix(email): use XOAUTH2 in test-connection endpoint for Google OAuth accounts #5021 is the stale focused implementation this branch preserves and replaces.
  • This PR targets dev.
  • My changes are limited to saved-account connection testing, OAuth-aware authentication, and focused regressions.
  • I ran the app end-to-end. No disposable Google/IMAP/SMTP account was available; protocol behavior was validated in isolated tests with mocked provider/network I/O.

How to Test

  1. Run:

    python -m pytest -q \
      tests/test_email_test_connection_oauth.py \
      tests/test_email_oauth.py \
      tests/test_email_imap_timeout.py \
      tests/test_email_smtp_security.py \
      tests/test_email_polly_imap_leak.py \
      tests/test_imap_leak_fixes.py
  2. Save a Google OAuth account with no IMAP/SMTP password and run Test connection.

  3. Verify IMAP and SMTP each use the saved account identity and report success independently.

  4. Repeat with a password account and verify its login behavior is unchanged.

Fresh current-dev review passes 137 broader email/IMAP/SMTP tests and Python compilation. Diff checks pass. Live-provider validation remains a reviewer item.

Visual / UI changes

N/A — backend connection testing and tests only; no UI rendering changed.

Screenshots / clips

N/A — no visual changes.

TNTBA and others added 3 commits July 20, 2026 15:23
The test-connection endpoint was password-only and had no awareness of
OAuth accounts. For Google-connected accounts this caused two failures:
- IMAP: "Need IMAP host, username, and password" because imap_pass is
  empty (no password is stored for OAuth accounts)
- SMTP: 535 BadCredentials because smtp.login() was called with an
  empty password instead of an XOAUTH2 token

Fix: include oauth_provider and token fields in saved_body when hydrating
from the DB, then use conn.authenticate("XOAUTH2") / smtp.auth("XOAUTH2")
for Google accounts in both the IMAP and SMTP test paths, mirroring what
_send_smtp_message already does for real sends.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Covers the XOAUTH2 changes made to routes/email_routes.py:
- Google OAuth accounts must not be rejected with 'Need IMAP host,
  username, and password' (no stored password for OAuth accounts)
- IMAP and SMTP test paths must use conn.authenticate('XOAUTH2')
  for Google accounts
- Password accounts must still use conn.login() / smtp.login()

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions github-actions Bot added the ready for review Description complete — ready for maintainer review label Jul 20, 2026
@RaresKeY
RaresKeY marked this pull request as ready for review July 21, 2026 12:20
@RaresKeY RaresKeY added the bug Something isn't working label Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ready for review Description complete — ready for maintainer review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

email: make saved-account connection tests OAuth-aware

2 participants