Skip to content

Commit

Permalink
stderr bad
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealFalcon committed Sep 26, 2024
1 parent 050ba0e commit a1186a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
17 changes: 13 additions & 4 deletions cloudinit/gpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ def decrypt(self, data: str, *, require_signature=False) -> str:
:return: decrypted data
:raises: ProcessExecutionError if gpg fails to decrypt data
"""
if require_signature:
try:
subp.subp(
["gpg", "--verify"],
data=data,
update_env=self.env,
)
except subp.ProcessExecutionError as e:
if e.exit_code == 2:
raise GpgVerificationError(
"Signature verification failed"
) from e
raise
result = subp.subp(
[
"gpg",
Expand All @@ -109,10 +122,6 @@ def decrypt(self, data: str, *, require_signature=False) -> str:
data=data,
update_env=self.env,
)
if require_signature and "gpg: Good signature" not in result.stderr:
raise GpgVerificationError(
"Signature verification required, but no signature found"
)
return result.stdout

def dearmor(self, key: str) -> str:
Expand Down
5 changes: 1 addition & 4 deletions tests/integration_tests/userdata/test_pgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,4 @@ def test_encrypted_message_but_required_signature(

result = client.execute("cloud-init status --format=json")
assert result.failed
assert (
"Signature verification required, but no signature found"
in result.stdout
)
assert "Signature verification failed" in result.stdout

0 comments on commit a1186a8

Please sign in to comment.