Skip to content

Commit 92bffc1

Browse files
committed
fix(fail2ban, needs-restarting, rpm-updates): pad args.TEST defensively
All three plugins store their test fixtures in a multi-file layout (one file per subprocess call, e.g. fail2ban has -ping, -status, -status-<jail>; rpm-updates has -upgrades, -installed, -updateinfo; needs-restarting has -reboothint, -services, -needrestart) and splice the stderr path and the expected return code into the lib.lftest.test() call by hand: lib.lftest.test([args.TEST[0] + '-ping', args.TEST[1], args.TEST[2]]) That direct index access crashes with IndexError when the user passes --test=path without trailing commas, because lib.args.csv splits on commas and leaves a 1-element list. lib.lftest.test() itself already pads to (stdout, stderr, retc) defensively, but these three plugins bypass that by consuming args.TEST[1] and args.TEST[2] before the call. Minimal fix: pad args.TEST to 3 elements once at main() entry so the hardcoded indices can't go out of range, and the splice into the per-command fixture name still works unchanged. Multi-file fixture convention stays, unlike in strongswan-connections where it was redundant and collapsed into a single JSON file. The three plugins here legitimately need separate fixtures per subprocess call. Smoke-test: running each plugin with --test=<base> (no trailing commas) no longer crashes.
1 parent 0369070 commit 92bffc1

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

check-plugins/fail2ban/fail2ban

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ def main():
9090
except SystemExit:
9191
sys.exit(STATE_UNKNOWN)
9292

93+
# Pad args.TEST to 3 elements so the per-command fixture
94+
# loads below that splice `args.TEST[1]` and `args.TEST[2]`
95+
# into custom lib.lftest.test() calls do not go out of range
96+
# when the user passes `--test=path` without trailing commas.
97+
if args.TEST is not None:
98+
while len(args.TEST) < 3:
99+
args.TEST.append('')
100+
93101
# fetch data
94102
# fail2ban-client ping
95103
if args.TEST is None:

check-plugins/needs-restarting/needs-restarting

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ def main():
7272
except SystemExit:
7373
sys.exit(STATE_UNKNOWN)
7474

75+
# Pad args.TEST to 3 elements so the per-command fixture
76+
# loads below that splice `args.TEST[1]` and `args.TEST[2]`
77+
# into custom lib.lftest.test() calls do not go out of range
78+
# when the user passes `--test=path` without trailing commas.
79+
if args.TEST is not None:
80+
while len(args.TEST) < 3:
81+
args.TEST.append('')
82+
7583
# init some vars
7684
if args.TEST_OS_FAMILY:
7785
distro = {'os_family': args.TEST_OS_FAMILY}

check-plugins/rpm-updates/rpm-updates

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,15 @@ def main():
586586
except SystemExit:
587587
sys.exit(STATE_UNKNOWN)
588588

589+
# Pad args.TEST to 3 elements so the `get_updates()` /
590+
# `get_updateinfo()` helpers below that splice `args.TEST[1]`
591+
# and `args.TEST[2]` into custom lib.lftest.test() calls do not
592+
# go out of range when the user passes `--test=path` without
593+
# trailing commas.
594+
if args.TEST is not None:
595+
while len(args.TEST) < 3:
596+
args.TEST.append('')
597+
589598
# fetch data
590599

591600
# get the list of installed software

0 commit comments

Comments
 (0)