From 940d15c46be812821f134fd7d6333088445b914c Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sun, 9 Nov 2025 22:59:06 +0100 Subject: [PATCH] Appease the linters --- INSTALL.md | 15 ++++++++----- src/ed25519/ge.c | 6 +++--- src/invitation.c | 1 + src/sptps_keypair.c | 4 ++-- src/utils.c | 32 ++++++++++++++-------------- test/integration/bind_port.py | 1 + test/integration/cmd_fsck.py | 2 +- test/integration/cmd_keys.py | 12 +++++++++-- test/integration/device_fd.py | 2 +- test/integration/device_multicast.py | 3 ++- test/integration/device_tap.py | 6 ++++-- test/integration/proxy.py | 2 +- test/integration/testlib/check.py | 13 +++++------ test/integration/testlib/proc.py | 2 +- test/integration/variables.py | 1 + 15 files changed, 61 insertions(+), 41 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 7fbc8b1b..742cdb3e 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -52,11 +52,16 @@ integration test suite: ## Linux -Depending on the distribution, one of the following commands can be used to install all dependencies: -- Arch Linux: `sudo pacman --needed --sync base-devel meson ninja pkg-config openssl ncurses readline zlib lzo lz4 texinfo diffutils procps socat openbsd-netcat` -- Debian: `sudo apt install meson ninja-build pkg-config build-essential libssl-dev libncurses-dev libreadline-dev zlib1g-dev liblzo2-dev liblz4-dev texinfo diffutils procps socat netcat-openbsd` -- Alpine Linux: `doas apk add meson ninja pkgconf build-base linux-headers openssl-dev ncurses-dev readline-dev zlib-dev lzo-dev lz4-dev texinfo diffutils procps-ng socat netcat-openbsd` -- Fedora: `sudo dnf install meson ninja-build pkgconf-pkg-config @development-tools openssl-devel ncurses-devel readline-devel zlib-devel lzo-devel lz4-devel texinfo diffutils procps-ng socat netcat` +Depending on the distribution, one of the following commands can be used to +install all dependencies: +- Arch Linux: + `sudo pacman --needed --sync base-devel meson ninja pkg-config openssl ncurses readline zlib lzo lz4 texinfo diffutils procps socat openbsd-netcat` +- Debian: + `sudo apt install meson ninja-build pkg-config build-essential libssl-dev libncurses-dev libreadline-dev zlib1g-dev liblzo2-dev liblz4-dev texinfo diffutils procps socat netcat-openbsd` +- Alpine Linux: + `doas apk add meson ninja pkgconf build-base linux-headers openssl-dev ncurses-dev readline-dev zlib-dev lzo-dev lz4-dev texinfo diffutils procps-ng socat netcat-openbsd` +- Fedora: + `sudo dnf install meson ninja-build pkgconf-pkg-config @development-tools openssl-devel ncurses-devel readline-devel zlib-devel lzo-devel lz4-devel texinfo diffutils procps-ng socat netcat` ## Windows diff --git a/src/ed25519/ge.c b/src/ed25519/ge.c index ca8c39b5..a69ed9d7 100644 --- a/src/ed25519/ge.c +++ b/src/ed25519/ge.c @@ -132,11 +132,11 @@ void ge_double_scalarmult_vartime(ge_p2 *r, const unsigned char *a, const ge_p3 static const fe d = { -10913610, 13857413, -15372611, 6949391, 114729, -8787816, -6275908, -3247719, -18696448, -12055116 - }; +}; static const fe sqrtm1 = { -32595792, -7943725, 9377950, 3500415, 12389472, -272473, -25146209, -2005654, 326686, 11406482 - }; +}; int ge_frombytes_negate_vartime(ge_p3 *h, const unsigned char *s) { fe u; @@ -297,7 +297,7 @@ r = p static const fe d2 = { -21827239, -5839606, -30745221, 13898782, 229458, 15978800, -12551817, -6495438, 29715968, 9444199 - }; +}; void ge_p3_to_cached(ge_cached *r, const ge_p3 *p) { fe_add(r->YplusX, p->Y, p->X); diff --git a/src/invitation.c b/src/invitation.c index 46891a3c..ecbf1fa7 100644 --- a/src/invitation.c +++ b/src/invitation.c @@ -1326,6 +1326,7 @@ int cmd_join(int argc, char *argv[]) { struct addrinfo *aip = NULL; next: + if(!aip) { aip = ai; } else { diff --git a/src/sptps_keypair.c b/src/sptps_keypair.c index 97d51895..09454f80 100644 --- a/src/sptps_keypair.c +++ b/src/sptps_keypair.c @@ -40,8 +40,8 @@ void logger(debug_t level, int priority, const char *format, ...) { static void usage(void) { fprintf(stderr, "Usage: %s [options] private_key_file public_key_file\n\n", program_name); fprintf(stderr, "Valid options are:\n" - " --help Display this help and exit.\n" - "\n"); + " --help Display this help and exit.\n" + "\n"); fprintf(stderr, "Report bugs to tinc@tinc-vpn.org.\n"); } diff --git a/src/utils.c b/src/utils.c index 3a3030d1..47b2a5d7 100644 --- a/src/utils.c +++ b/src/utils.c @@ -28,22 +28,22 @@ static const char base64_original[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmno static const char base64_urlsafe[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; static const char base64_decode[256] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, 62, -1, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, - -1, 0, 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, -1, -1, -1, -1, 63, - -1, 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, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - }; + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, 62, -1, 63, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, + -1, 0, 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, -1, -1, -1, -1, 63, + -1, 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, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, +}; static uint8_t charhex2bin(char c) { uint8_t cu = (uint8_t) c; diff --git a/test/integration/bind_port.py b/test/integration/bind_port.py index 11fbc4a3..5ebaefd0 100755 --- a/test/integration/bind_port.py +++ b/test/integration/bind_port.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# pylint: disable=unreachable """Test binding to ports on localhost.""" diff --git a/test/integration/cmd_fsck.py b/test/integration/cmd_fsck.py index e3dfa437..fc8171f2 100755 --- a/test/integration/cmd_fsck.py +++ b/test/integration/cmd_fsck.py @@ -107,7 +107,7 @@ def extract_pem(config: str) -> T.List[str]: return result if key: result.append(line) - raise Exception("key not found") + raise RuntimeError("key not found") def replace_line(file_path: str, prefix: str, replace: str = "") -> None: diff --git a/test/integration/cmd_keys.py b/test/integration/cmd_keys.py index 079a5036..825f079e 100755 --- a/test/integration/cmd_keys.py +++ b/test/integration/cmd_keys.py @@ -4,6 +4,7 @@ """Test key management commands.""" import os +import typing from testlib import check, util from testlib.log import log @@ -23,6 +24,10 @@ def try_rsa_keys(priv_path: str, pub_path: str) -> None: import cryptography # type: ignore from cryptography.hazmat.primitives import hashes, serialization # type: ignore from cryptography.hazmat.primitives.asymmetric import padding # type: ignore + from cryptography.hazmat.primitives.asymmetric.rsa import ( + RSAPrivateKey, + RSAPublicKey, + ) # type: ignore except ImportError: log.info("cryptography module missing or broken, skipping key checks") return @@ -35,8 +40,11 @@ def try_rsa_keys(priv_path: str, pub_path: str) -> None: log.info("loading keys from (%s, %s)", priv_path, pub_path) with open(priv_path, "rb") as priv, open(pub_path, "rb") as pub: key_pair = ( - serialization.load_pem_private_key(priv.read(), password=None), - serialization.load_pem_public_key(pub.read()), + typing.cast( + RSAPrivateKey, + serialization.load_pem_private_key(priv.read(), password=None), + ), + typing.cast(RSAPublicKey, serialization.load_pem_public_key(pub.read())), ) s_pad = padding.PSS( diff --git a/test/integration/device_fd.py b/test/integration/device_fd.py index 01955468..70b5072e 100755 --- a/test/integration/device_fd.py +++ b/test/integration/device_fd.py @@ -13,7 +13,7 @@ from testlib.log import log from testlib.test import Test from testlib.proc import Script -JUNK_FRAME = b"\xFF" * 80 +JUNK_FRAME = b"\xff" * 80 def start_fd_server(unix: socket.socket, payload: bytes, file_desc: int) -> None: diff --git a/test/integration/device_multicast.py b/test/integration/device_multicast.py index 1b46c42c..97dd1681 100755 --- a/test/integration/device_multicast.py +++ b/test/integration/device_multicast.py @@ -19,6 +19,8 @@ PORT = 38245 class MulticastSupport(enum.Enum): + """Enum describing level of support for multicast.""" + NO = 0 BLOCKED = 1 YES = 2 @@ -104,7 +106,6 @@ def test_device_multicast(ctx: Test) -> None: test_rx_tx(foo) elif multicast_support == MulticastSupport.BLOCKED: log.info("multicast blocked") - pass else: log.info("multicast not supported") test_no_mcast_support(foo) diff --git a/test/integration/device_tap.py b/test/integration/device_tap.py index 07eaf5ff..9449ae95 100755 --- a/test/integration/device_tap.py +++ b/test/integration/device_tap.py @@ -30,8 +30,10 @@ def make_up(node: str, address: str) -> str: return f""" import subprocess as subp subp.run(['ip', 'link', 'set', 'dev', '{node}', 'netns', '{node}'], check=True) - subp.run(['ip', 'netns', 'exec', '{node}', 'ip', 'addr', 'add', 'dev', '{node}', '{address}/24'], check=True) - subp.run(['ip', 'netns', 'exec', '{node}', 'ip', 'link', 'set', '{node}', 'up'], check=True) + subp.run(['ip', 'netns', 'exec', '{node}', 'ip', 'addr', 'add', 'dev', '{node}', + '{address}/24'], check=True) + subp.run(['ip', 'netns', 'exec', '{node}', 'ip', 'link', 'set', '{node}', 'up'], + check=True) """ diff --git a/test/integration/proxy.py b/test/integration/proxy.py index c0e79710..3b227047 100755 --- a/test/integration/proxy.py +++ b/test/integration/proxy.py @@ -402,7 +402,7 @@ def test_proxy(ctx: Test, handler: T.Type[ProxyServer], user="", passw="") -> No foo.cmd("set", f"{bar}.Port", str(bar.port)) with ThreadingTCPServer(("127.0.0.1", 0), handler) as server: - _, port = server.server_address + _, port, *_ = server.server_address worker = Thread(target=server.serve_forever) worker.start() diff --git a/test/integration/testlib/check.py b/test/integration/testlib/check.py index 7f70b99f..651822c6 100755 --- a/test/integration/testlib/check.py +++ b/test/integration/testlib/check.py @@ -8,9 +8,10 @@ from .log import log Val = T.TypeVar("Val") Num = T.TypeVar("Num", int, float) +AnyStr = T.TypeVar("AnyStr", str, bytes) -def blank(value: T.AnyStr) -> None: +def blank(value: AnyStr) -> None: """Check that value is an empty or blank string.""" if not isinstance(value, str) or value.strip(): raise ValueError(f'expected "{value!r}" to be a blank string') @@ -52,7 +53,7 @@ def equals(expected: Val, actual: Val) -> None: raise ValueError(f'expected "{expected}", got "{actual}"') -def has_prefix(text: T.AnyStr, prefix: T.AnyStr) -> None: +def has_prefix(text: AnyStr, prefix: AnyStr) -> None: """Check that text has prefix.""" if not text.startswith(prefix): raise ValueError(f"expected {text!r} to start with {prefix!r}") @@ -70,7 +71,7 @@ def in_range(value: Num, gte: Num, lte: Num) -> None: raise ValueError(f"value {value} must be between {gte} and {lte}") -def lines(text: T.AnyStr, num: int) -> None: +def lines(text: AnyStr, num: int) -> None: """Check that text splits into `num` lines.""" rows = text.splitlines() if len(rows) != num: @@ -92,7 +93,7 @@ def not_in(needle: Val, *haystacks: T.Container[Val]) -> None: raise ValueError(f'expected all "{haystacks}" NOT to include "{needle}"') -def _read_content(path: T.Union[str, os.PathLike], search: T.AnyStr) -> T.AnyStr: +def _read_content(path: T.Union[str, os.PathLike], search: AnyStr) -> AnyStr: """Read text or binary content, depending on the type of search argument.""" if isinstance(search, str): mode, enc = "r", "utf-8" @@ -102,12 +103,12 @@ def _read_content(path: T.Union[str, os.PathLike], search: T.AnyStr) -> T.AnyStr return f.read() -def in_file(path: T.Union[str, os.PathLike], text: T.AnyStr) -> None: +def in_file(path: T.Union[str, os.PathLike], text: AnyStr) -> None: """Check that file contains a string.""" is_in(text, _read_content(path, text)) -def not_in_file(path: T.Union[str, os.PathLike], text: T.AnyStr) -> None: +def not_in_file(path: T.Union[str, os.PathLike], text: AnyStr) -> None: """Check that file does not contain a string.""" not_in(text, _read_content(path, text)) diff --git a/test/integration/testlib/proc.py b/test/integration/testlib/proc.py index 970c80cc..dab335ad 100755 --- a/test/integration/testlib/proc.py +++ b/test/integration/testlib/proc.py @@ -240,7 +240,7 @@ class Tinc: self, *args: str, code: T.Optional[int] = 0, - stdin: T.Optional[T.AnyStr] = None, + stdin: T.Optional[str | bytes] = None, timeout: T.Optional[int] = None, ) -> T.Tuple[str, str]: """Run command through tinc, writes `stdin` to it (if the argument is not None), diff --git a/test/integration/variables.py b/test/integration/variables.py index b42fbf5e..9ecca066 100755 --- a/test/integration/variables.py +++ b/test/integration/variables.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# pylint: disable=invalid-name """Test tinc and tincd configuration variables.""" -- 2.47.3