From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: "Kernel.org Tools" <tools@kernel.org>
Cc: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Subject: [PATCH kgl 1/4] Disable interactive OAuth flows when stdin is not a terminal
Date: Fri, 04 Dec 2026 22:56:16 -0800 [thread overview]
Message-ID: <20261204-delivery-rules-v1-1-80af76016200@gmail.com> (raw)
In-Reply-To: <20261204-delivery-rules-v1-0-80af76016200@gmail.com>
Target initialization previously treated any CLI invocation without
GUI mode enabled as interactive. When running unattended under systemd
timers or cron jobs where standard input is not connected to a
terminal, missing credentials or expired refresh tokens could block
indefinitely waiting for a browser OAuth callback.
Require both non-GUI mode and a terminal on standard input before
enabling interactive authentication flows for target services.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
src/korgalore/cli.py | 4 ++--
tests/test_cli_misc.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 62 insertions(+), 3 deletions(-)
diff --git a/src/korgalore/cli.py b/src/korgalore/cli.py
index 0692ab8..68f5e2d 100644
--- a/src/korgalore/cli.py
+++ b/src/korgalore/cli.py
@@ -275,8 +275,8 @@ def get_target(ctx: click.Context, identifier: str) -> Any:
target_type = details.get('type', '')
# Instantiate based on type
- # In GUI mode, don't run interactive OAuth flows
- interactive = not ctx.obj.get('gui_mode', False)
+ # In GUI mode or non-interactive terminals, don't run interactive OAuth flows
+ interactive = not ctx.obj.get('gui_mode', False) and sys.stdin.isatty()
service: Any
if target_type == 'gmail':
service = get_gmail_target(
diff --git a/tests/test_cli_misc.py b/tests/test_cli_misc.py
index e351b0b..9c7ed0e 100644
--- a/tests/test_cli_misc.py
+++ b/tests/test_cli_misc.py
@@ -10,12 +10,14 @@ noise into somebody's debug log.
"""
import io
+from unittest.mock import patch
import click
import pytest
from korgalore import format_key_for_display
-from korgalore.cli import progress_file
+from korgalore.cli import get_target, progress_file
+from tests.digest_helpers import make_ctx
@pytest.mark.parametrize(
@@ -75,3 +77,60 @@ def test_hidden_bar_writes_nothing_to_stdout(capsys: pytest.CaptureFixture[str])
# stream is what keeps it off the user's terminal, so check it landed here.
assert isinstance(stream, io.StringIO)
assert 'Hiding' in stream.getvalue()
+
+
+def test_get_target_interactive_when_tty_and_not_gui() -> None:
+ ctx = make_ctx(
+ {
+ 'config': {'targets': {'test': {'type': 'gmail', 'credentials': 'creds.json'}}},
+ 'targets': {},
+ 'gui_mode': False,
+ }
+ )
+ with (
+ patch('sys.stdin.isatty', return_value=True),
+ patch('korgalore.cli.get_gmail_target') as mock_gmail,
+ ):
+ mock_gmail.return_value = 'target-service'
+ res = get_target(ctx, 'test')
+ assert res == 'target-service'
+ assert mock_gmail.call_args.kwargs['interactive'] is True
+ assert mock_gmail.call_args.kwargs['identifier'] == 'test'
+
+
+def test_get_target_non_interactive_when_not_tty() -> None:
+ ctx = make_ctx(
+ {
+ 'config': {'targets': {'test': {'type': 'gmail', 'credentials': 'creds.json'}}},
+ 'targets': {},
+ 'gui_mode': False,
+ }
+ )
+ with (
+ patch('sys.stdin.isatty', return_value=False),
+ patch('korgalore.cli.get_gmail_target') as mock_gmail,
+ ):
+ mock_gmail.return_value = 'target-service'
+ res = get_target(ctx, 'test')
+ assert res == 'target-service'
+ assert mock_gmail.call_args.kwargs['interactive'] is False
+ assert mock_gmail.call_args.kwargs['identifier'] == 'test'
+
+
+def test_get_target_non_interactive_when_gui_mode() -> None:
+ ctx = make_ctx(
+ {
+ 'config': {'targets': {'test': {'type': 'gmail', 'credentials': 'creds.json'}}},
+ 'targets': {},
+ 'gui_mode': True,
+ }
+ )
+ with (
+ patch('sys.stdin.isatty', return_value=True),
+ patch('korgalore.cli.get_gmail_target') as mock_gmail,
+ ):
+ mock_gmail.return_value = 'target-service'
+ res = get_target(ctx, 'test')
+ assert res == 'target-service'
+ assert mock_gmail.call_args.kwargs['interactive'] is False
+ assert mock_gmail.call_args.kwargs['identifier'] == 'test'
--
2.56.1.987.g2ec0ab4260-goog
next prev parent reply other threads:[~2026-12-05 6:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 6:56 [PATCH kgl 0/4] Add conditional initial-arrival delivery rules Dmitry Torokhov
2026-12-05 6:56 ` Dmitry Torokhov [this message]
2026-12-05 6:56 ` [PATCH kgl 2/4] Defer Gmail OAuth loading until delivery and isolate target failures Dmitry Torokhov
2026-12-05 6:56 ` [PATCH kgl 3/4] Add initial_labels, intra-pull dedup cache, and Gmail scope upgrades Dmitry Torokhov
2026-12-05 6:56 ` [PATCH kgl 4/4] Add conditional initial-arrival delivery rules Dmitry Torokhov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204-delivery-rules-v1-1-80af76016200@gmail.com \
--to=dmitry.torokhov@gmail.com \
--cc=konstantin@linuxfoundation.org \
--cc=tools@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox