From d9345d8836d295a205eab19ce9e969bcc9a35b42 Mon Sep 17 00:00:00 2001 From: Jade Lovelace Date: Mon, 10 Jun 2024 17:04:54 -0700 Subject: [PATCH] tests: verify that NIX_DAEMON_PACKAGE's version looks like a version Followup to https://gerrit.lix.systems/c/lix/+/1417 to ensure that this parser will never take something that doesn't look like a version. It turns out this problem is less alarming than initially thought because it only applies to the testsuite in a non-default mode. Change-Id: I26aba24aaf0215f2b782966314b94784db766266 --- tests/functional/common/vars-and-functions.sh.in | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/functional/common/vars-and-functions.sh.in b/tests/functional/common/vars-and-functions.sh.in index bd1990973..bfc4fbc44 100644 --- a/tests/functional/common/vars-and-functions.sh.in +++ b/tests/functional/common/vars-and-functions.sh.in @@ -144,11 +144,15 @@ if [[ $(uname) == Linux ]] && [[ -L /proc/self/ns/user ]] && unshare --user true fi isDaemonNewer () { - [[ -n "${NIX_DAEMON_PACKAGE:-}" ]] || return 0 - local requiredVersion="$1" - local versionOutput=$($NIX_DAEMON_PACKAGE/bin/nix daemon --version) - local daemonVersion=${versionOutput##* } - [[ $(nix eval --expr "builtins.compareVersions ''$daemonVersion'' ''$requiredVersion''") -ge 0 ]] + [[ -n "${NIX_DAEMON_PACKAGE:-}" ]] || return 0 + local requiredVersion="$1" + local versionOutput + versionOutput=$("$NIX_DAEMON_PACKAGE/bin/nix" daemon --version) + local daemonVersion=${versionOutput##* } + if [[ ! $daemonVersion =~ [[:digit:]]+\.[[:digit:]]+\..* ]]; then + fail "Daemon version '$daemonVersion' does not look plausible, this is a testsuite bug!" + fi + [[ $(nix eval --expr "builtins.compareVersions ''$daemonVersion'' ''$requiredVersion''") -ge 0 ]] } skipTest () {