Commit 629ef070 authored by Antoine Beaupré's avatar Antoine Beaupré
Browse files

try to run check-trustdb ourselves

parent 7c8570be
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -431,7 +431,7 @@ class Keyring():
        self.context.expect(proc.stderr, 'GET_LINE keyedit.prompt')
        print >>proc.stdin, 'save'
        self.context.expect(proc.stderr, 'GOT_IT')
        return proc.wait() == 0
        return proc.wait() == 0 and self.check_trustdb()

    def sign_key(self, pattern, signall = False, local = False):
        """sign a OpenPGP public key
@@ -542,6 +542,16 @@ class Keyring():
            self.context.expect(proc.stderr, 'GOT_IT')
        return proc.wait() == 0

    def check_trustdb(self):
        """regenerate the trustdb

we run under --no-auto-check-trustdb so we need to call this from time to time ourselves
"""
        self.context.call_command(['check-trustdb'])
        if not self.context.returncode == 0:
            raise GpgRuntimeError(self.context.returncode, _('check-trustdb failed: %s') % self.context.stderr.split("\n")[-2])
        return True        

class TempKeyring(Keyring):
    def __init__(self):
        """Override the parent class to generate a temporary GPG home
+5 −4
Original line number Diff line number Diff line
@@ -273,6 +273,10 @@ work.

        keys = self.tmpkeyring.get_keys(self.pattern)

        self.tmpkeyring.context.call_command(['--check-trustdb'])
        if not self.tmpkeyring.context.returncode == 0:
            raise GpgRuntimeError(self.context.returncode, _('decryption failed: %s') % self.context.stderr.split("\n")[-2])

        self.log(_('found %d keys matching your request') % len(keys))

        for key in keys:
@@ -426,10 +430,7 @@ mailto: who to send the mail to (usually similar to recipient, but can be used t
        self.tmpkeyring.import_data(keydata)
        # prepare for email transport
        self.tmpkeyring.context.set_option('armor')
        # this is necessary because we reimport keys from outside our
        # keyring, so gpg doesn't trust them anymore
        # but we know we do, so we ignore the trustdb
        self.tmpkeyring.context.set_option('trust-model', 'always')
        self.tmpkeyring.context.set_option('no-auto-check-trustdb')
        # remove UIDs we don't want to send
        self.cleanup_uids()
        # cleanup email addresses
+1 −0
Original line number Diff line number Diff line
@@ -185,6 +185,7 @@ class EmailFactoryTest(BaseTestCase):
        self.assertTrue(self.ui.tmpkeyring.import_data(open(os.path.dirname(__file__) + '/96F47C6A.asc').read()))
        self.assertTrue(self.ui.tmpkeyring.import_data(open(os.path.dirname(__file__) + '/96F47C6A-secret.asc').read()))

        self.ui.tmpkeyring.context.set_option('always-trust')
        self.email = EmailFactory(self.ui.tmpkeyring.export_data(self.pattern), self.pattern, 'Antoine Beaupré <anarcat@orangeseeds.org>', 'nobody@example.com', 'nobody@example.com')

    def test_cleanup_uids(self):