Debian Codegraph @

python/tests/testsigs/unit/test_signchanges.py

raw
1 # SPDX-FileCopyrightText: Peter Pentchev <[email protected]>
2 # SPDX-License-Identifier: GPL-2.0-or-later
3 """Unit tests for the `debsigs-signchanges` tool."""
4
5 from __future__ import annotations
6
7 import subprocess # noqa: S404
8 import typing
9
10 import pytest
11
12 from . import util
13 from .util import test_cfg # noqa: F401 # pytest fixture
14
15
16 if typing.TYPE_CHECKING:
17 from typing import Final
18
19
20 def test_sign(test_cfg: util.ConfigAggr) -> None: # noqa: F811 # pytest fixture
21 """Sign files in different ways."""
22 if not test_cfg.has_all_features(
23 {"cmd-list": "1", "cmd-sign": "1", "i-gpg": "1", "tool-signchanges": "0.1"},
24 ):
25 pytest.skip("No `debsigs-signchanges` or `debsigs --list` support")
26
27 with test_cfg.cfg_with_tempd() as cfg:
28 pub_key: Final = test_cfg.pub_key
29 changes_orig: Final = test_cfg.changes_orig
30
31 changes_signed: Final = changes_orig.copy_to(cfg.path.work)
32 assert changes_signed.get_different_files(cfg, changes_orig) == []
33 for deb in changes_signed.debs:
34 assert util.debsigs_list(cfg, deb) == []
35
36 sign_key: Final = util.get_signing_subkey(pub_key)
37 env_with_path: Final = dict(cfg.env)
38 env_with_path["PATH"] = f"{cfg.prog.debsigs.parent}:{env_with_path['PATH']}"
39 if "DEBSIGSSIG" in env_with_path:
40 del env_with_path["DEBSIGSSIG"]
41 env_with_path["DEBSIGSOPTIONS"] = f"--default-key={sign_key.key_id}"
42
43 subprocess.check_call( # noqa: S603
44 [cfg.prog.debsigs.parent / "debsigs-signchanges", changes_signed.path],
45 cwd=cfg.path.work,
46 env=env_with_path,
47 )
48
49 changes_signed.verify(cfg)
50 assert changes_signed.get_different_files(cfg, changes_orig) == sorted(
51 deb.name for deb in changes_signed.debs
52 )
53
54 for deb in changes_signed.debs:
55 lines_maint_only = util.debsigs_list(cfg, deb)
56 match lines_maint_only:
57 case [single] if single.sig_type == "maint" and single.key_id == sign_key.key_id:
58 pass
59
60 case _:
61 raise AssertionError(repr((changes_signed, deb, lines_maint_only)))