1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
#
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2020 Chris Lamb <lamby@debian.org>
#
# diffoscope is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# diffoscope is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
import subprocess
import pytest
from diffoscope.comparators.binary import FilesystemFile
from diffoscope.comparators.openssl import Pkcs7File
from diffoscope.comparators.utils.specialize import specialize
from ..utils.tools import skip_unless_tools_exist
def pkcs7_fixture(prefix):
@pytest.fixture
def inner(tmpdir):
crt = str(tmpdir.join("{}.crt".format(prefix)))
pem = str(tmpdir.join("{}.pem".format(prefix)))
p7c = str(tmpdir.join("{}.p7c".format(prefix)))
subprocess.check_call(
(
"openssl",
"req",
"-x509",
"-newkey",
"rsa:4096",
"-keyout",
pem,
"-out",
crt,
"-days",
"365",
"-nodes",
"-subj",
"/CN=localhost",
)
)
subprocess.check_call(
(
"openssl",
"crl2pkcs7",
"-nocrl",
"-certfile",
crt,
"-out",
p7c,
"-certfile",
pem,
)
)
return specialize(FilesystemFile(p7c))
return inner
pkcs71 = pkcs7_fixture("test1")
pkcs72 = pkcs7_fixture("test2")
@skip_unless_tools_exist("openssl")
def test_identification(pkcs71):
assert isinstance(pkcs71, Pkcs7File)
@skip_unless_tools_exist("openssl")
def test_no_differences(pkcs71):
difference = pkcs71.compare(pkcs71)
assert difference is None
@pytest.fixture
def differences(pkcs71, pkcs72):
return pkcs71.compare(pkcs72).details
@skip_unless_tools_exist("openssl")
def test_differences(differences):
# Don't test exact unified diff; the signatures generated in
# `pkcs7_fixture` are non-deterministic.
assert "notAfter:" in differences[0].unified_diff
assert "serialNumber:" in differences[0].unified_diff
|