From e8b144ebeee356591ce91b14fe8730398333dc08 Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Wed, 29 Jan 2025 10:22:41 +0100 Subject: [PATCH] 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. --- tests/test_CLI.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_CLI.py b/tests/test_CLI.py index 20aa020..9f09e86 100644 --- a/tests/test_CLI.py +++ b/tests/test_CLI.py @@ -33,8 +33,8 @@ class Key: testkeys = { - "correct": Key("tests/test-data/gnupg", "correct "), - "unknown": Key("tests/test-data/gnupg2", "unknown "), + "correct": Key(None, "correct ", None), + "unknown": Key(None, "unknown ", None), } @@ -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, @@ -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"