From: Brian Masney <masneyb@kernel.org>
To: "Kernel.org Tools" <tools@kernel.org>
Cc: Konstantin Ryabitsev <konstantin@linuxfoundation.org>,
Jerome Brunet <jbrunet@baylibre.com>,
Brian Masney <masneyb@kernel.org>
Subject: [PATCH b4 3/3] review: tests: add tests for get_pw_key() and b4.pw-key-command
Date: Thu, 15 Oct 2026 10:08:43 -0400 [thread overview]
Message-ID: <20261015-pw-key-command-v1-3-6daa9b8cee2a@kernel.org> (raw)
In-Reply-To: <20261015-pw-key-command-v1-0-6daa9b8cee2a@kernel.org>
Introduce tests for pw-key and pw-key-command.
Assisted-by: LLM
Signed-off-by: Brian Masney <masneyb@kernel.org>
---
src/tests/test___init__.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/src/tests/test___init__.py b/src/tests/test___init__.py
index 764829d7e756..0eb6e6193b1c 100644
--- a/src/tests/test___init__.py
+++ b/src/tests/test___init__.py
@@ -2924,3 +2924,56 @@ class TestGetAmMessageFromLines:
lines = payload.decode().splitlines()
assert 'From the manual, bar() must be called here.' in lines
assert '>From an old thread.' in lines
+
+
+class TestGetPwKey:
+ """b4.pw-key-command fetches the Patchwork key from a password manager."""
+
+ @pytest.fixture(autouse=True)
+ def _clear_cache(self) -> None:
+ b4._PW_KEY_CACHE.clear()
+
+ def test_plain_key(self) -> None:
+ assert b4.get_pw_key({'pw-key': 'secret'}) == 'secret'
+
+ def test_unset(self) -> None:
+ assert b4.get_pw_key({}) == ''
+
+ def test_command_first_line(self) -> None:
+ """Only the first line counts, as with `pass show`."""
+ config: b4.ConfigDictT = {
+ 'pw-key': 'ignored',
+ 'pw-key-command': "printf 'fromcmd\\nuser: me\\n'",
+ }
+ assert b4.get_pw_key(config) == 'fromcmd'
+
+ def test_command_runs_once(self, tmp_path: pathlib.Path) -> None:
+ counter = tmp_path / 'count'
+ config: b4.ConfigDictT = {
+ 'pw-key-command': f"sh -c 'echo x >> {counter}; echo key'",
+ }
+ assert b4.get_pw_key(config) == 'key'
+ assert b4.get_pw_key(config) == 'key'
+ assert counter.read_text().count('x') == 1
+
+ def test_command_fails(self, caplog: pytest.LogCaptureFixture) -> None:
+ config: b4.ConfigDictT = {'pw-key-command': 'false'}
+ with caplog.at_level(logging.CRITICAL, logger='b4'):
+ assert b4.get_pw_key(config) == ''
+ assert 'exited with status 1' in caplog.text
+
+ def test_command_missing(self, caplog: pytest.LogCaptureFixture) -> None:
+ config: b4.ConfigDictT = {'pw-key-command': '/nonexistent/b4-pw-helper'}
+ with caplog.at_level(logging.CRITICAL, logger='b4'):
+ assert b4.get_pw_key(config) == ''
+ assert 'Could not run pw-key-command' in caplog.text
+
+ def test_ignored_in_worktree_config(self, gitdir: str) -> None:
+ """A cloned tree's .b4-config must not get to run a command."""
+ wtcfg = pathlib.Path(gitdir) / '.b4-config'
+ wtcfg.write_text(
+ '[b4]\n\tpw-key-command = echo stolen\n\tpw-url = https://pw.example.org\n'
+ )
+ b4._setup_main_config(topdir=gitdir)
+ assert b4.MAIN_CONFIG.get('pw-url') == 'https://pw.example.org'
+ assert b4.MAIN_CONFIG.get('pw-key-command') is None
--
2.55.0
prev parent reply other threads:[~2026-10-15 14:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 14:08 [PATCH b4 0/3] review: add support for b4.pw-key-command Brian Masney
2026-10-15 14:08 ` [PATCH b4 1/3] review: centralize lookup of patchwork key in one place Brian Masney
2026-10-15 14:08 ` [PATCH b4 2/3] review: introduce support for b4.pw-key-command Brian Masney
2026-10-15 14:08 ` Brian Masney [this message]
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=20261015-pw-key-command-v1-3-6daa9b8cee2a@kernel.org \
--to=masneyb@kernel.org \
--cc=jbrunet@baylibre.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