Skip to content

Commit

Permalink
Create a new temporary directory for GNUPGHOME
Browse files Browse the repository at this point in the history
Storing GNUPGHOME inside the build tree may result in the following when
calling gpg.Context().create_key():

gpg.errors.GPGMEError: gpgme_op_createkey: GnuPG: No agent running

This happens if the path to the build tree is so long, that the path to
the socket `S.gpg-agent` inside the GNUPGHOME exceeds 108 characters.
The limit comes from sockaddr_un.sun_path, see unix(7) or:

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=847206

Long build paths are commonly found when building bmaptool inside sbuild
or on Debian gitlab CI.

By setting GNUPGHOME to a new temporary directory, which will likely be
placed in /tmp, we avoid problems with long paths to GNUPGHOME.
  • Loading branch information
josch committed Jan 29, 2025
1 parent 8403297 commit e8b144e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tests/test_CLI.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class Key:


testkeys = {
"correct": Key("tests/test-data/gnupg", "correct <foo@bar.org>"),
"unknown": Key("tests/test-data/gnupg2", "unknown <blub@bla.net>"),
"correct": Key(None, "correct <foo@bar.org>", None),
"unknown": Key(None, "unknown <blub@bla.net>", None),
}


Expand Down Expand Up @@ -149,9 +149,8 @@ def setUp(self):

os.makedirs("tests/test-data/signatures", exist_ok=True)
for key in testkeys.values():
if os.path.exists(key.gnupghome):
shutil.rmtree(key.gnupghome)
os.makedirs(key.gnupghome)
assert key.gnupghome is None
key.gnupghome = tempfile.mkdtemp(prefix="bmaptool")
context = gpg.Context(home_dir=key.gnupghome)
dmkey = context.create_key(
key.uid,
Expand Down Expand Up @@ -194,6 +193,7 @@ def tearDown(self):
for key in testkeys.values():
shutil.rmtree(key.gnupghome)
os.unlink(f"{key.gnupghome}.keyring")
key.gnupghome = None
for bmapv in ["2.0", "1.4"]:
testp = "tests/test-data"
imbn = "test.image.bmap.v"
Expand Down

0 comments on commit e8b144e

Please sign in to comment.