Skip to content

Commit 97cddaa

Browse files
joschJPEWdev
authored andcommitted
Create a new temporary directory for GNUPGHOME
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.
1 parent c39db65 commit 97cddaa

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

tests/test_CLI.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class Key:
3333

3434

3535
testkeys = {
36-
"correct": Key("tests/test-data/gnupg", "correct <[email protected]>"),
37-
"unknown": Key("tests/test-data/gnupg2", "unknown <[email protected]>"),
36+
"correct": Key(None, "correct <[email protected]>", None),
37+
"unknown": Key(None, "unknown <[email protected]>", None),
3838
}
3939

4040

@@ -149,9 +149,8 @@ def setUp(self):
149149

150150
os.makedirs("tests/test-data/signatures", exist_ok=True)
151151
for key in testkeys.values():
152-
if os.path.exists(key.gnupghome):
153-
shutil.rmtree(key.gnupghome)
154-
os.makedirs(key.gnupghome)
152+
assert key.gnupghome is None
153+
key.gnupghome = tempfile.mkdtemp(prefix="bmaptool")
155154
context = gpg.Context(home_dir=key.gnupghome)
156155
dmkey = context.create_key(
157156
key.uid,
@@ -194,6 +193,7 @@ def tearDown(self):
194193
for key in testkeys.values():
195194
shutil.rmtree(key.gnupghome)
196195
os.unlink(f"{key.gnupghome}.keyring")
196+
key.gnupghome = None
197197
for bmapv in ["2.0", "1.4"]:
198198
testp = "tests/test-data"
199199
imbn = "test.image.bmap.v"

0 commit comments

Comments
 (0)