diff options
| author | Justus Winter <[email protected]> | 2017-02-17 11:18:56 +0000 | 
|---|---|---|
| committer | Justus Winter <[email protected]> | 2017-02-17 11:18:56 +0000 | 
| commit | de8494b16bc50c60a8438f2cae1f8c88e8949f7a (patch) | |
| tree | 3fae3b3fd43eb9e860fc446415dccd0d6358044c /lang/python/tests/support.py | |
| parent | python: Fix using strings as commands in the assuan protocol. (diff) | |
| download | gpgme-de8494b16bc50c60a8438f2cae1f8c88e8949f7a.tar.gz gpgme-de8494b16bc50c60a8438f2cae1f8c88e8949f7a.zip | |
python: Fix teardown of ephemeral contexts.
* lang/python/tests/support.py (EphemeralContext): New function.
* lang/python/tests/t-quick-key-creation.py: Use the new function to
manage ephemeral contexts.
* lang/python/tests/t-quick-key-manipulation.py: Likewise.
* lang/python/tests/t-quick-subkey-creation.py: Likewise.
--
Previously, there was a problem with cleaning up ephemeral home
directories.  shutil.rmtree deleted the agents main socket, gpg-agent
detected that, and deleted the other sockets as well, racing
shutil.rmtree which did not cope will with that.
Fix this by asking the agent nicely to shut down.
Signed-off-by: Justus Winter <[email protected]>
Diffstat (limited to '')
| -rw-r--r-- | lang/python/tests/support.py | 24 | 
1 files changed, 23 insertions, 1 deletions
| diff --git a/lang/python/tests/support.py b/lang/python/tests/support.py index ed5bf615..a381270d 100644 --- a/lang/python/tests/support.py +++ b/lang/python/tests/support.py @@ -18,9 +18,12 @@  from __future__ import absolute_import, print_function, unicode_literals  del absolute_import, print_function, unicode_literals +import contextlib +import shutil  import sys  import os  import tempfile +import time  import gpg  # known keys @@ -85,5 +88,24 @@ else:              self.path = tempfile.mkdtemp()              return self.path          def __exit__(self, *args): -            import shutil              shutil.rmtree(self.path) + +def EphemeralContext(): +    with TemporaryDirectory() as tmp: +        home = os.environ['GNUPGHOME'] +        shutil.copy(os.path.join(home, "gpg.conf"), tmp) +        shutil.copy(os.path.join(home, "gpg-agent.conf"), tmp) + +        with gpg.Context(home_dir=tmp) as ctx: +            yield ctx + +            # Ask the agent to quit. +            agent_socket = os.path.join(tmp, "S.gpg-agent") +            ctx.protocol = gpg.constants.protocol.ASSUAN +            ctx.set_engine_info(ctx.protocol, file_name=agent_socket) +            ctx.assuan_transact(["KILLAGENT"]) + +            # Block until it is really gone. +            while os.path.exists(agent_socket): +                time.sleep(.01) | 
