From 93671ef571eb2201f745d068df6c518f0f2d2e96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lesimple?= Date: Mon, 11 Aug 2025 16:39:54 +0000 Subject: [PATCH] fix: tests: more robust sshd reloading across OSes --- tests/functional/tests.d/900-strict-checking.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/functional/tests.d/900-strict-checking.sh b/tests/functional/tests.d/900-strict-checking.sh index d9fce2c..2db14c1 100644 --- a/tests/functional/tests.d/900-strict-checking.sh +++ b/tests/functional/tests.d/900-strict-checking.sh @@ -22,10 +22,14 @@ testsuite_strict_checking() retvalshouldbe 255 contain "Permanently added" - # change the remote hostkeys, also send HUP to force sshd to take the change into account (Ubuntu 24+ at least), - # don't check return value as we'll kill our own session with pkill, as a collateral damage. - # FreeBSD: -a includes our process tree, otherwise this shadows sshd. it'll kill our current session so don't check for a return code - run change_host_keys $r0 "\"find /etc/ssh/ -type f -name 'ssh_host_*' -delete; ssh-keygen -A; test -e /bin/freebsd-version && pkill -HUP -a -f sshd: || pkill -HUP sshd\"" + # change the remote hostkeys, and get the proper sshd PID so that we can force it to reload + success change_host_keys $r0 "\"find /etc/ssh/ -type f -name 'ssh_host_*key*' -print -delete; ssh-keygen -A; ps faxu; printf %s SSHD_PIDS=; ps ax -o pid,args | grep -E '^ *[0-9]+ +(sshd: .+listener|/usr/sbin/sshd)' | awk '{print \\\$1}' | tr '\\\n' ' '\"" + contain 'generating new host keys' + get_stdout + local sshd_pids + sshd_pids=$(get_stdout | grep SSHD_PIDS= | cut -d= -f2-) + + success reload_target_sshd $r0 "\"kill -HUP $sshd_pids\"" # set bastion ssh_client config to StrictHostKeyChecking yes sshclientconfigchg 's=StrictHostKeyChecking.*=StrictHostKeyChecking\\\\x20yes=g'