def test_update_ownertrust_failure(context, mocker):
    def popen(*args, **kwargs):
        return FakeProc(returncode=1)

    mocker.patch.object(subprocess, 'Popen', new=popen)
    with pytest.raises(ScriptWorkerGPGException):
        sgpg.update_ownertrust(context, "foo")
Example #2
0
def test_ownertrust(context, trusted_names):
    """This is a fairly complex test.

    Create a new gnupg_home, update ownertrust with just my fingerprint.
    The original update will run its own verify; we then make sure to get full
    code coverage by testing that extra and missing fingerprints raise a
    ScriptWorkerGPGException.
    """
    gpg = sgpg.GPG(context)
    my_fingerprint = sgpg.generate_key(gpg, "one", "one", "one")
    sgpg.create_gpg_conf(context.config['gpg_home'],
                         my_fingerprint=my_fingerprint)
    trusted_fingerprints = []
    for name in trusted_names:
        trusted_fingerprints.append(sgpg.generate_key(gpg, name, name, name))
    # append my fingerprint to get more coverage
    if trusted_fingerprints:
        trusted_fingerprints.append(my_fingerprint)
    unsigned_fingerprint = sgpg.generate_key(gpg, "four", "four", "four")
    sgpg.update_ownertrust(context,
                           my_fingerprint,
                           trusted_fingerprints=trusted_fingerprints)
    with pytest.raises(ScriptWorkerGPGException):
        sgpg.verify_ownertrust(context, my_fingerprint,
                               trusted_fingerprints + [unsigned_fingerprint])
    if trusted_fingerprints:
        with pytest.raises(ScriptWorkerGPGException):
            sgpg.verify_ownertrust(context, my_fingerprint,
                                   [trusted_fingerprints[0]])