Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/git_commit_guard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def _verify_gpg(rev, gpg_text):
if import_proc.returncode != 0:
return False
verify_proc = subprocess.run( # noqa: S603
["git", "verify-commit", rev], # noqa: S607
["git", "-c", "gpg.ssh.allowedSignersFile=/dev/null", "verify-commit", rev], # noqa: S607
capture_output=True,
text=True,
env=env,
Expand All @@ -368,6 +368,8 @@ def _verify_ssh(rev, email, ssh_text):
[ # noqa: S607
"git",
"-c",
"gpg.format=ssh",
"-c",
f"gpg.ssh.allowedSignersFile={signers_path}",
"verify-commit",
rev,
Expand Down
9 changes: 7 additions & 2 deletions tests/test_git_commit_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,10 @@ def test_verify_success_returns_true(self):
verify_proc = MagicMock(returncode=0)
with patch(
"git_commit_guard.subprocess.run", side_effect=[import_proc, verify_proc]
):
) as mock_run:
assert _verify_gpg("abc123", "gpg key data") is True
verify_cmd = mock_run.call_args_list[1][0][0]
assert "gpg.ssh.allowedSignersFile=/dev/null" in verify_cmd

def test_verify_failure_returns_false(self):
import_proc = MagicMock(returncode=0)
Expand All @@ -737,10 +739,13 @@ def test_empty_ssh_returns_false(self):

def test_verify_success_returns_true(self):
proc = MagicMock(returncode=0)
with patch("git_commit_guard.subprocess.run", return_value=proc):
with patch("git_commit_guard.subprocess.run", return_value=proc) as mock_run:
assert (
_verify_ssh("abc123", "user@example.com", "ssh-ed25519 AAAA...") is True
)
verify_cmd = mock_run.call_args[0][0]
assert "-c" in verify_cmd
assert "gpg.format=ssh" in verify_cmd

def test_verify_failure_returns_false(self):
proc = MagicMock(returncode=1)
Expand Down
Loading