Commit 2693ad67 authored by Chris Lamb's avatar Chris Lamb 💬

Additionally compare pgpdump(1) output when comparing PGP signatures. (Re:...

Additionally compare pgpdump(1) output when comparing PGP signatures. (Re: #908991, #7)
parent c4eea5a9
Pipeline #37066 passed with stage
in 14 minutes and 35 seconds
......@@ -98,6 +98,7 @@ class ComparatorManager(object):
('gif.GifFile',),
('pcap.PcapFile',),
('pgp.PgpFile',),
('pgp.PgpSignature',),
('dtb.DeviceTreeFile',),
('ogg.OggFile',),
('xsb.XsbFile',),
......
......@@ -22,6 +22,7 @@ import re
from diffoscope.tools import tool_required
from diffoscope.difference import Difference
from .text import TextFile
from .utils.file import File
from .utils.command import Command
......@@ -50,3 +51,23 @@ class PgpFile(File):
Pgpdump, self.path, other.path, source='pgpdump'
)
]
class PgpSignature(TextFile):
DESCRIPTION = "PGP signatures"
FILE_TYPE_RE = re.compile(r'^PGP signature\b')
def compare(self, other, source=None):
# Don't display signatures as hexdumps; use TextFile's comparisons...
difference = super().compare(other, source)
# ... but attach pgpdump of outout
difference.add_details(
[
Difference.from_command(
Pgpdump, self.path, other.path, source='pgpdump'
)
]
)
return difference
......@@ -40,7 +40,7 @@ def order_only_difference(unified_diff):
class TextFile(File):
DESCRIPTION = "text files"
FILE_TYPE_RE = re.compile(r'(?:\btext\b|^PGP signature Signature)')
FILE_TYPE_RE = re.compile(r'\btext\b')
@property
def encoding(self):
......
......@@ -19,7 +19,7 @@
import pytest
from diffoscope.comparators.pgp import PgpFile
from diffoscope.comparators.pgp import PgpFile, PgpSignature
from ..utils.data import load_fixture, get_data
from ..utils.tools import skip_unless_tools_exist
......@@ -27,6 +27,8 @@ from ..utils.nonexisting import assert_non_existing
pgp1 = load_fixture('test1.pgp')
pgp2 = load_fixture('test2.pgp')
signature1 = load_fixture('test1.asc')
signature2 = load_fixture('test2.asc')
def test_identification(pgp1):
......@@ -52,3 +54,16 @@ def test_diff(differences):
@skip_unless_tools_exist('pgpdump')
def test_compare_non_existing(monkeypatch, pgp1):
assert_non_existing(monkeypatch, pgp1, has_null_source=False)
def test_pgp_signature_identification(signature1, signature2):
assert isinstance(signature1, PgpSignature)
assert isinstance(signature2, PgpSignature)
@skip_unless_tools_exist('pgpdump')
def test_pgp_signature(signature1, signature2):
difference = signature1.compare(signature2)
assert difference.unified_diff == get_data('pgp_signature_expected_diff')
assert difference.details[0].source1 == 'pgpdump'
assert len(difference.details) == 1
......@@ -96,17 +96,3 @@ def test_ordering_differences(text_order1, text_order2):
difference = text_order1.compare(text_order2)
assert difference.comments == ['ordering differences only']
assert difference.unified_diff == get_data('text_order_expected_diff')
signature1 = load_fixture('test1.asc')
signature2 = load_fixture('test2.asc')
def test_gpg_signature_identification(signature1, signature2):
assert isinstance(signature1, TextFile)
assert isinstance(signature2, TextFile)
def test_gpg_signature(signature1, signature2):
difference = signature1.compare(signature2)
assert difference.unified_diff == get_data('text_asc_expected_diff')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment