From patchwork Sun Jun 16 16:02:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 7863 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4W2HqP3Ggxz3ws3 for ; Sun, 16 Jun 2024 16:03:13 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4W2HqJ1HsMz1X1; Sun, 16 Jun 2024 16:03:08 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4W2HqJ0d8tz33Fr; Sun, 16 Jun 2024 16:03:08 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4W2HqG5gXmz2xtd for ; Sun, 16 Jun 2024 16:03:06 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4W2HqF4dNpz2sm; Sun, 16 Jun 2024 16:03:05 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1718553785; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BNMPKb7BeG81zVS+iNYzcnnQGiMAOeIWTlcN/bs7zdU=; b=fkczhbu1abcupUFNJ6B4pjeECmLsg9a9ksAoDInXmSUI7GH5HodaEWRfqXZLuM/n58wr8q NBYj9l1KefIXMhBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1718553785; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BNMPKb7BeG81zVS+iNYzcnnQGiMAOeIWTlcN/bs7zdU=; b=dRV9OkJuuvbfpwvBM3pjtAAi7zhSdQdLN4n0BijtEi49nHfpzTYwAS3Quj8JaomUwtbJnF K2oXkf3PvEPGMKdUye4/ijvUhis4Gade279CwKJ33AS2UlkZhVKa2KPBZ+AFdapXHDVjry jQvcFExD+tVxJJ6oAGAtrbQxNKk3OiYwlzxE8w3IUoa6KGfLmrBuhdBWUlhQFTbofXDNE7 IXAtgYtUxjAx7jEtTYTEYTsroTbfjT6Bs5mMUCd+JEe3GWmaumNAD6dWvR6epPQSiVNwMg SvjDR68RW2eAP82ynF15GyG8IOfAQ86+A+0iH3Q+qNt3oPkOYu0EiNQXZgv3+A== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH v2 01/18] tests: Add bash lib Date: Sun, 16 Jun 2024 18:02:28 +0200 Message-Id: <20240616160245.18865-2-jonatan.schlag@ipfire.org> In-Reply-To: <20240616160245.18865-1-jonatan.schlag@ipfire.org> References: <20240616160245.18865-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: KNBGJPG4JZILZB5FF6QX2GKRVVOVNFUB X-Message-ID-Hash: KNBGJPG4JZILZB5FF6QX2GKRVVOVNFUB X-MailFrom: jonatan.schlag@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: This allows use to write test with less effort as we can reuse functions Signed-off-by: Jonatan Schlag --- tests/lib.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/lib.sh diff --git a/tests/lib.sh b/tests/lib.sh new file mode 100644 index 000000000..dd5e3f535 --- /dev/null +++ b/tests/lib.sh @@ -0,0 +1,27 @@ +#!/usr/bin/bash + +# Get the path of this file. +# This ist rather complex as we do not want the calling script file +# That why we use BASH_SOURCE[0] +LIB_DIR="$(readlink -f "${BASH_SOURCE[0]}")" +# In LIB_DIR is currently saved the path to this file you are currently reading +# but we need the directory where it is located so: +LIB_DIR="$(dirname "${LIB_DIR}")" + + +. ${LIB_DIR}/lib_color.sh + +test_command() { + + if ! "$@" ; then + echo -e "${CLR_RED_BG} Test failed: ${*} ${CLR_RESET}" + return 1 + else + echo -e "${CLR_GREEN_BG} Test succeded: ${*} ${CLR_RESET}" + return 0 + fi +} + +var_has_value() { + [[ "${!1}" == "${2}" ]] +} From patchwork Sun Jun 16 16:02:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 7864 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4W2HqW0Qn4z3ws3 for ; Sun, 16 Jun 2024 16:03:19 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4W2HqL2WcZz5Zn; Sun, 16 Jun 2024 16:03:10 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4W2HqL208bz33Fr; Sun, 16 Jun 2024 16:03:10 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4W2HqH6dfXz2xtd for ; Sun, 16 Jun 2024 16:03:07 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4W2HqH3fCcz1X1; Sun, 16 Jun 2024 16:03:07 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1718553787; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4URYk5JjRqZEpqXWoJiqlJ2ndlrwZAmekR/9FP+oBGo=; b=HD0UxSHhvdwzAYkkGrpVFVlwdKYqiCPoPHiiXTqfs5Y+6wrNDL/RfCskjZUHWR1p8cb3Vv 1EEKxenJ/aKsWjBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1718553787; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4URYk5JjRqZEpqXWoJiqlJ2ndlrwZAmekR/9FP+oBGo=; b=eI3v90UdMYG2U2JuTluGlNMxCXzjifePZ4IY5TC61saBun84YXycHgk8WcPWDBzRG1BbFA 0zK6fvOpMCbzyyBUAVpO702oVPXos5bqrZMVtLNSOiz+omNjwM1W+mPOXVHny7cBU2W04J kHTodDi+SdEFx+H5mBfTlPN122VFVnd644sQC3wVYopef5rpWWY4fxNn/dD7+vT2hcv95s BKa/fy9JUsEwYbHkAiIUsaH3AXrhWcfWp3IsgrJZ//qHUt7191ov0cxsuzzce+QHyF+TUN eyyUVEv5WTEiJmOcfyu7vUhNBosNua34vQlqhsS4FJSFPbMXaJHecPSfBEhRxg== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH v2 02/18] tests/lib.sh: Add function test_value_in_array Date: Sun, 16 Jun 2024 18:02:29 +0200 Message-Id: <20240616160245.18865-3-jonatan.schlag@ipfire.org> In-Reply-To: <20240616160245.18865-1-jonatan.schlag@ipfire.org> References: <20240616160245.18865-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: KFTFGH5HCCKLK7FC5UDFW2CN6O46S4PC X-Message-ID-Hash: KFTFGH5HCCKLK7FC5UDFW2CN6O46S4PC X-MailFrom: jonatan.schlag@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Test if a given array has the specified value stored under key. ! does not work here to access the array by variable name. So the solution here is: https://unix.stackexchange.com/questions/60584/how-to-use-a-variable-as-part-of-an-array-name/60585#60585 Signed-off-by: Jonatan Schlag --- tests/lib.sh | 14 +++++++++++++ .../src/initscripts/system/functions/test2.sh | 21 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100755 tests/src/initscripts/system/functions/test2.sh diff --git a/tests/lib.sh b/tests/lib.sh index dd5e3f535..716922024 100644 --- a/tests/lib.sh +++ b/tests/lib.sh @@ -25,3 +25,17 @@ test_command() { var_has_value() { [[ "${!1}" == "${2}" ]] } + +test_value_in_array() { + local -n array="${1}" + local key="${2}" + local value="${3}" + + if [[ "${array[${key}]}" == "${value}" ]] ; then + echo -e "${CLR_GREEN_BG}Test succeded: The array '${1}' contains the value '${value}' under the key '${key}' ${CLR_RESET}" + return 0 + else + echo -e "${CLR_RED_BG}Test failed: The array '${1}' contains the value '${array[${key}]}' under the key '${key} and not '${value}' ${CLR_RESET}" + return 1 + fi +} diff --git a/tests/src/initscripts/system/functions/test2.sh b/tests/src/initscripts/system/functions/test2.sh new file mode 100755 index 000000000..a568ed2a4 --- /dev/null +++ b/tests/src/initscripts/system/functions/test2.sh @@ -0,0 +1,21 @@ +#!/usr/bin/bash + +SCRIPT_PATH="$(dirname "$(readlink -f "$0")")" + +ROOT="$(readlink -f "${SCRIPT_PATH}/../../../../..")" + +. ${ROOT}/tests/lib.sh + +. ${ROOT}/src/initscripts/system/functions + +# read the date in +readhash "CONFIG" "${SCRIPT_PATH}/data/1" + +# test if we read the correct data +test_that_key_in_arry_has_value "CONFIG" "RED_DHCP_HOSTNAME" "ipfire" +test_that_key_in_arry_has_value "CONFIG" "BLUE_MACADDR" "bc:30:7d:58:6b:e3" + +test_that_output_is "${SCRIPT_PATH}/data/1_output_stdout" "1" readhash "CONFIG" "${SCRIPT_PATH}/data/1" +test_that_output_is "${SCRIPT_PATH}/data/1_output_stderr" "2" readhash "CONFIG" "${SCRIPT_PATH}/data/1" + + From patchwork Sun Jun 16 16:02:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 7865 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4W2HqX4zRCz3ws3 for ; Sun, 16 Jun 2024 16:03:20 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4W2HqP6NrFz4X5; Sun, 16 Jun 2024 16:03:13 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4W2HqN3k78z33Fq; Sun, 16 Jun 2024 16:03:12 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4W2HqK3YkSz33Fq for ; Sun, 16 Jun 2024 16:03:09 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4W2HqJ4KFZz5mY; Sun, 16 Jun 2024 16:03:08 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1718553788; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7OEw25GAv+5h1b26YgnvzVlqNAkLaj1W2htfKTuI84g=; b=eCEJ2d4TL9FxqiOxQKcKn5ztaNIlNfWPLdpFh0cTWoP9/72KGLNRIlkaL1V6c2Wjmihp3k mzPU3My3iXz0mhBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1718553788; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7OEw25GAv+5h1b26YgnvzVlqNAkLaj1W2htfKTuI84g=; b=wZeR4G9zMPyc20vW4DKZkkg19iCDebrUu/DOV60m+nNOGztvypROcciamyzdDeH0n67KUK 2J/6WSo9AZRM0M4a8k62chTfkQsh11bJmfCZWTZqo/sAIMYacyK4hrAiepBBDGwmY5aFvz g9SYDDcBLMcZyD1qGgIZ6gnCHlwASZ+YDcky1ogOLHfBYCwFktMsAq/CorvNCZrJhCJg/5 sgiT5A0IRktUVsJOE1LiktYf+brUaFJXfd6+7+CZoAJGAB+zpzyNqISo7poSZfpK1bRwL+ 3SFB9DhGXq8sQU36N+20ZJayY0+przieHbKeAag8VUl8ZYEx44BcKnuPZ4IMiQ== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH v2 03/18] tests/lib.sh: Add check if variable exists to test_value_in_array Date: Sun, 16 Jun 2024 18:02:30 +0200 Message-Id: <20240616160245.18865-4-jonatan.schlag@ipfire.org> In-Reply-To: <20240616160245.18865-1-jonatan.schlag@ipfire.org> References: <20240616160245.18865-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: WMDUB3DC6XAVUAAXATJJPLHBRHITUMWP X-Message-ID-Hash: WMDUB3DC6XAVUAAXATJJPLHBRHITUMWP X-MailFrom: jonatan.schlag@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: We cannot use [ -v ] here as this does not work. We need to check if the array is correctly declared. Signed-off-by: Jonatan Schlag --- tests/lib.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/lib.sh b/tests/lib.sh index 716922024..4fce151f8 100644 --- a/tests/lib.sh +++ b/tests/lib.sh @@ -28,9 +28,18 @@ var_has_value() { test_value_in_array() { local -n array="${1}" + local arrayname="${1}" local key="${2}" local value="${3}" + # `declare -p` print out how the variable with the name $arrayname was declared + # If the array was not declared as indexed or associative array we fail. We cannot check for a value in an array if + # we were not given array. + if [[ ! "$(declare -p "${arrayname}")" =~ "declare -a" && ! "$(declare -p "${arrayname}")" =~ "declare -A" ]]; then + echo -e "${CLR_RED_BG}Test failed: The array '${1}' does not exists. The variable is not set.${CLR_RESET}'" + return 1 + fi + if [[ "${array[${key}]}" == "${value}" ]] ; then echo -e "${CLR_GREEN_BG}Test succeded: The array '${1}' contains the value '${value}' under the key '${key}' ${CLR_RESET}" return 0 From patchwork Sun Jun 16 16:02:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 7866 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hqd4JZ5z3ws3 for ; Sun, 16 Jun 2024 16:03:25 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4W2HqV1Lvpz5W9; Sun, 16 Jun 2024 16:03:18 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4W2HqN51c8z33Fv; Sun, 16 Jun 2024 16:03:12 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4W2HqL30QXz33FL for ; Sun, 16 Jun 2024 16:03:10 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4W2HqK4PDfz5gB; Sun, 16 Jun 2024 16:03:09 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1718553789; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VDlmZXGoBGCQG9MudnMCcWQSn8nQvTNueWreNUJtXFg=; b=M7InXM34+Jzwh5i24ep7hqDqpORlpus1YWV+8bbI0Yi0bmOOgwJYApFc/HNBiS8Tup8EQJ 4edb3LYaVgNQqcAw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1718553789; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VDlmZXGoBGCQG9MudnMCcWQSn8nQvTNueWreNUJtXFg=; b=vibZ1VxuYStTe3PfxheEE6juHyq56x9Nln4AI0Mf+qXq8lG4oh7maeCvz38QV5excpOXT1 Qsg1xJkIIGC8oPD4bm+IgoRGEEqDf9JhDV4LVVW2P/x7fgvlpE+KEsC/LgN00bvpKohAtv 6j8u8A9DT3ilbuCM+UqbiDsM9ymg92BLSUFQHq9JvfygdPaFdwwAANIUOjMZEB/7mXlW+m j38TDHsHXIjWxGY9KX/MGvX4Jne+xD8OED/KORWpqewGdnqUrocYHUoP8FRTpJkkDeMwcz u8100cNPnj3TlpW6k4NK2RateAe3DhdwvCgByGKnBoxm2ZXKlukoBK4AkpUNEg== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH v2 04/18] tests/lib.sh: Add logging functions Date: Sun, 16 Jun 2024 18:02:31 +0200 Message-Id: <20240616160245.18865-5-jonatan.schlag@ipfire.org> In-Reply-To: <20240616160245.18865-1-jonatan.schlag@ipfire.org> References: <20240616160245.18865-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: KAJFCM5MRQYVOAIL4AEC5PF3AQOW45DC X-Message-ID-Hash: KAJFCM5MRQYVOAIL4AEC5PF3AQOW45DC X-MailFrom: jonatan.schlag@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: So we can change the style of our log messages better. Signed-off-by: Jonatan Schlag --- tests/lib.sh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/lib.sh b/tests/lib.sh index 4fce151f8..e462f4add 100644 --- a/tests/lib.sh +++ b/tests/lib.sh @@ -11,13 +11,21 @@ LIB_DIR="$(dirname "${LIB_DIR}")" . ${LIB_DIR}/lib_color.sh +log_test_failed(){ + echo -e "${CLR_RED_BG}Test failed: ${*}${CLR_RESET}'" +} + +log_test_succeded(){ + echo -e "${CLR_GREEN_BG}Test succeded: ${*}${CLR_RESET}" +} + test_command() { if ! "$@" ; then - echo -e "${CLR_RED_BG} Test failed: ${*} ${CLR_RESET}" + log_test_failed "${*}" return 1 else - echo -e "${CLR_GREEN_BG} Test succeded: ${*} ${CLR_RESET}" + log_test_succeded "${*}" return 0 fi } @@ -36,15 +44,15 @@ test_value_in_array() { # If the array was not declared as indexed or associative array we fail. We cannot check for a value in an array if # we were not given array. if [[ ! "$(declare -p "${arrayname}")" =~ "declare -a" && ! "$(declare -p "${arrayname}")" =~ "declare -A" ]]; then - echo -e "${CLR_RED_BG}Test failed: The array '${1}' does not exists. The variable is not set.${CLR_RESET}'" + log_test_failed "The array '${1}' does not exists. The variable is not set." return 1 fi if [[ "${array[${key}]}" == "${value}" ]] ; then - echo -e "${CLR_GREEN_BG}Test succeded: The array '${1}' contains the value '${value}' under the key '${key}' ${CLR_RESET}" + log_test_succeded "The array '${1}' contains the value '${value}' under the key '${key}'" return 0 else - echo -e "${CLR_RED_BG}Test failed: The array '${1}' contains the value '${array[${key}]}' under the key '${key} and not '${value}' ${CLR_RESET}" + log_test_failed "The array '${1}' contains the value '${array[${key}]}' under the key '${key} and not '${value}'" return 1 fi } From patchwork Sun Jun 16 16:02:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 7867 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hqf2RKgz3wy2 for ; Sun, 16 Jun 2024 16:03:26 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4W2Hqc43rfz5nc; Sun, 16 Jun 2024 16:03:24 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4W2HqX72LMz33Fw; Sun, 16 Jun 2024 16:03:20 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4W2HqV1d02z2xtd for ; Sun, 16 Jun 2024 16:03:18 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4W2HqL69BJz5n3; Sun, 16 Jun 2024 16:03:10 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1718553790; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5A+6p0t/W5Mf97oqBDCzkPZlVyEgKT4bvPxZBU+kDtY=; b=pFkPub+XLrwZ/nMBAwLIv12XTt+SqMVx2hP7NsMMn5d0/mtaGOXuBrhq2ZBbBFDLe3e66w T7piI/yL9+fMQ9BQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1718553790; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5A+6p0t/W5Mf97oqBDCzkPZlVyEgKT4bvPxZBU+kDtY=; b=bFtgY0QbroFpE0p1Gs/rz0Aijsec8H57U8iL5PiIR5X8qrXy+S7mM+rYyPuITG5ecUNXJh +8pBYUezGO6cqVadLqQkCyNmegAIS1+rkEw0XqPO2RyTQCocy7IkrbXLccW8kvorJSKipd mUbNQUbFpi6FPnCV5ut1zxWaigy4qcBhZS3VmqqnTyFQaCjqF6AuN5D1QijSiyi5ZzFxff 3r1aOMPlMo95Cm51KyNfpIN3TZ3AJT3SzsBJwrGs6Mpd/We+Y+L2OfnOtYjJb0OUZuofQc LWG/DlOgJnsEBQoNGPuNLChW2BZhmvx/q66QOIrL33oDUNhdyUDTCzobLvZhRQ== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH v2 05/18] tests/lib.sh: adjust to pytest logging style Date: Sun, 16 Jun 2024 18:02:32 +0200 Message-Id: <20240616160245.18865-6-jonatan.schlag@ipfire.org> In-Reply-To: <20240616160245.18865-1-jonatan.schlag@ipfire.org> References: <20240616160245.18865-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: 2J6PTWAIT7VOHBNQ6ESOLN5F536GNLXN X-Message-ID-Hash: 2J6PTWAIT7VOHBNQ6ESOLN5F536GNLXN X-MailFrom: jonatan.schlag@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Black on white is still the best to read. So we only style FAILED or PASSED in green or red. This is also tested with different background colors. As we only style PASSED or FAILED it works without any problems Signed-off-by: Jonatan Schlag --- tests/lib.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/lib.sh b/tests/lib.sh index e462f4add..f49a94748 100644 --- a/tests/lib.sh +++ b/tests/lib.sh @@ -12,11 +12,11 @@ LIB_DIR="$(dirname "${LIB_DIR}")" . ${LIB_DIR}/lib_color.sh log_test_failed(){ - echo -e "${CLR_RED_BG}Test failed: ${*}${CLR_RESET}'" + echo -e "${CLR_RED_R}FAILED:${CLR_RESET} ${*}" } log_test_succeded(){ - echo -e "${CLR_GREEN_BG}Test succeded: ${*}${CLR_RESET}" + echo -e "${CLR_GREEN_R}PASSED:${CLR_RESET} ${*}" } test_command() { From patchwork Sun Jun 16 16:02:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 7868 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hqg61fQz3ws3 for ; Sun, 16 Jun 2024 16:03:27 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4W2Hqc6KY7z3tL; Sun, 16 Jun 2024 16:03:24 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4W2HqY1GqYz33G2; Sun, 16 Jun 2024 16:03:21 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4W2HqW0by2z2xtd for ; Sun, 16 Jun 2024 16:03:19 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4W2HqP1txqz5g4; Sun, 16 Jun 2024 16:03:13 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1718553793; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ws7xV8FM5OZxfsTlvvZ2u7V5awT6lq9LDxLjlMoc/Uc=; b=b7uafPOzeLu0II0kOQq2YjfdlZWg/QYX4fba6kU9Elt4WwrThCaYpqz0R+BeUVYtdOq4hQ G5G7hUowu48azOBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1718553793; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ws7xV8FM5OZxfsTlvvZ2u7V5awT6lq9LDxLjlMoc/Uc=; b=aP3Yqg9sQDNKciRsFrLON2eyCufTJ5tDA+vSDc37saJkF3JcGA3BDROKtGcMfjSy4CgL6I +ataJ6J1rQRw6MyzSUc6dHo79xJ4KOuow9JtQ/GjWhiK9GrzyqVhVHthD4WtM8Wxn7nlZo oQYOryKRdyAhBCCNdNk4EUPgl2pqBSyBEwxdCCCjj1zf83Xzgx8QRkjv+Wd/4kbC1HiIgv pRe2M2Ozy5VHQXajAIaNzBE/QSl1EMjzDYqB05BdQDj+Pj2x6kKF4K7z0nuwtCKDJ0+JJB mNnLSNObarhbSPhrgzMKWLW1GPG0uDRk6096j/goDAuNhbog7+am89z8/rlpXg== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH v2 06/18] test_value_in_array: Check if the key is defined Date: Sun, 16 Jun 2024 18:02:33 +0200 Message-Id: <20240616160245.18865-7-jonatan.schlag@ipfire.org> In-Reply-To: <20240616160245.18865-1-jonatan.schlag@ipfire.org> References: <20240616160245.18865-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: CYPOVSEIFOHFY7EYL2T6ECBS2E53VIO5 X-Message-ID-Hash: CYPOVSEIFOHFY7EYL2T6ECBS2E53VIO5 X-MailFrom: jonatan.schlag@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Signed-off-by: Jonatan Schlag --- tests/lib.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/lib.sh b/tests/lib.sh index f49a94748..af8c632cf 100644 --- a/tests/lib.sh +++ b/tests/lib.sh @@ -48,6 +48,14 @@ test_value_in_array() { return 1 fi + # If key is not defined we return _ + # If the key is defined we return nothing + # See also https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html + if [[ "${array["${key}"]+_}" == "" ]]; then + log_test_failed "The array does not contain the key '${key}', valid keys are: ${!array[*]}" + return 1 + fi + if [[ "${array[${key}]}" == "${value}" ]] ; then log_test_succeded "The array '${1}' contains the value '${value}' under the key '${key}'" return 0 From patchwork Sun Jun 16 16:02:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 7870 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hqj0GrCz3ws3 for ; Sun, 16 Jun 2024 16:03:29 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4W2Hqd2LrRz5nP; Sun, 16 Jun 2024 16:03:25 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4W2Hqb3kq1z33G5; Sun, 16 Jun 2024 16:03:23 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4W2HqW3T72z33Fq for ; Sun, 16 Jun 2024 16:03:19 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4W2HqS1k6Nz5nN; Sun, 16 Jun 2024 16:03:16 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1718553796; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hlJ+DF2XKYgivlSkbMfQ0MkU5Oo6ky7KBk0VlXzs+Mw=; b=7SvFAOVOlcOZXXgn7n5hp/3s5sSA9faGgMHBEAMx3OGmM/Ym+099izaJ0o6BimdLH5eoN7 fgU2/SRoxsdSPaAQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1718553796; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hlJ+DF2XKYgivlSkbMfQ0MkU5Oo6ky7KBk0VlXzs+Mw=; b=f6L4YVS/+/zflPK8oEz4lITIoMBJTwDD8w1aokE5SZyfb20Zmcn+MDotmz5jMonTYfTNze OXd9ofbC5GV2fNuDUTCSak1l1D62EwGJOCjheMkDT4YBCF119IpVu5EgWKffrTrw2hHvdZ tFy8Gsga6pZtIAVT26Of/zApLfqcjDAS+d/JD3dMQHJt8yhQ5GUh+5ZgM6W3IAJPSgwhdJ ZI6H4gFG+Y0vxRmPX7zPnLr1EnisWzP8sDeqKiOyqGP6bM/cAYtpJmU0RdggCzZZ8woTvb rgRk8W2lV6EZh6afvVH8g7759ILs191BoF3BKShIR5p7zih7Mo/zoFdirPKzGQ== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH v2 07/18] tests: Add function to test the ouput of a bash function Date: Sun, 16 Jun 2024 18:02:34 +0200 Message-Id: <20240616160245.18865-8-jonatan.schlag@ipfire.org> In-Reply-To: <20240616160245.18865-1-jonatan.schlag@ipfire.org> References: <20240616160245.18865-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: 7EE6TH4334ZW26NFSNDDKLDMZPEAV7EG X-Message-ID-Hash: 7EE6TH4334ZW26NFSNDDKLDMZPEAV7EG X-MailFrom: jonatan.schlag@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Signed-off-by: Jonatan Schlag --- tests/lib.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/lib.sh b/tests/lib.sh index af8c632cf..4110ed2d8 100644 --- a/tests/lib.sh +++ b/tests/lib.sh @@ -64,3 +64,32 @@ test_value_in_array() { return 1 fi } + +test_that_output_is(){ + local reference_output_file="${1}" + local file_descriptor="${2}" + shift + shift + + local command="$@" + + local temp="$(mktemp)" + + case "${file_descriptor}" in + "stdout"|"1") + $command 1> "${temp}" 2>/dev/null + ;; + "stderr"|"2") + $command 2> "${temp}" 1>/dev/null + ;; + esac + + if diff -u "${temp}" "${reference_output_file}" &> /dev/null; then + log_test_succeded "The output of command '${command}' on file descriptor '${file_descriptor}' is equal to the reference output." + else + log_test_failed "The output of command '${command}' on file descriptor '${file_descriptor}' is unequal to the reference output." + diff -u --color "${reference_output_file}" "${temp}" + fi + + rm "${temp}" +} From patchwork Sun Jun 16 16:02:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 7869 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hqh1vM9z3wy2 for ; Sun, 16 Jun 2024 16:03:28 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4W2Hqc6V83z5nh; Sun, 16 Jun 2024 16:03:24 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4W2HqZ2R6Rz33Fq; Sun, 16 Jun 2024 16:03:22 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4W2HqW3QDSz33Fh for ; Sun, 16 Jun 2024 16:03:19 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4W2HqV2wKTz5nY; Sun, 16 Jun 2024 16:03:18 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1718553798; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K+R69oApYUegk2dlnzkfAjG7DEKYJubT8Ru2E0NP7nk=; b=kC3TXWwpPhdH5fGF0Na6akaaxSvebMX4SjTDUkMEDFW6cc6KMH/ghKfVTpTl7ZtS74afg1 jYP8P2RBlSwzFpBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1718553798; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K+R69oApYUegk2dlnzkfAjG7DEKYJubT8Ru2E0NP7nk=; b=BQqdYc1wuRKd5/XacMO/lGUx53Uq4kyjxHVMvehgTBqfqa2XxFh8s/lT6vxkm+Pr7l/FsJ Q4RVh8R7l+vOGCsCuQldUJsa5PXVsEqdI1S65T8QFbv5P1oY7UAnivcTyos7Lwdx1kd6TU sxE3cAR8YtoZIsRTzijRamLYVAzBIu19Bc/OA6GB2seXqGfWGIH3IFilbrwflTmr8WsElW 2lej6KKbemlSdgwQVPERuZ/OoqPbloK67chKpuXw0lNwU6FL85n7MKYb4WOjULj2aowRxX AvRHzeyOvRdm2AuL7QT7yqmLO0hosd1PpVp7Ag/ccrtH6c1S7sRxQTPRIwxb/w== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH v2 08/18] test: Add functions test_that_array_is_defined Date: Sun, 16 Jun 2024 18:02:35 +0200 Message-Id: <20240616160245.18865-9-jonatan.schlag@ipfire.org> In-Reply-To: <20240616160245.18865-1-jonatan.schlag@ipfire.org> References: <20240616160245.18865-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: LJQPDQ3PFWERCEAMZRX3NU47WWNGOUYW X-Message-ID-Hash: LJQPDQ3PFWERCEAMZRX3NU47WWNGOUYW X-MailFrom: jonatan.schlag@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: we need this check in multiple places so it makes sense to move this to a separate function. Signed-off-by: Jonatan Schlag --- tests/lib.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/lib.sh b/tests/lib.sh index 4110ed2d8..32481b6a5 100644 --- a/tests/lib.sh +++ b/tests/lib.sh @@ -34,11 +34,8 @@ var_has_value() { [[ "${!1}" == "${2}" ]] } -test_value_in_array() { - local -n array="${1}" +test_that_array_is_defined() { local arrayname="${1}" - local key="${2}" - local value="${3}" # `declare -p` print out how the variable with the name $arrayname was declared # If the array was not declared as indexed or associative array we fail. We cannot check for a value in an array if @@ -46,7 +43,19 @@ test_value_in_array() { if [[ ! "$(declare -p "${arrayname}")" =~ "declare -a" && ! "$(declare -p "${arrayname}")" =~ "declare -A" ]]; then log_test_failed "The array '${1}' does not exists. The variable is not set." return 1 + else + log_test_succeded "The array '${1}' is defined." + return 0 fi +} + +test_value_in_array() { + local -n array="${1}" + local arrayname="${1}" + local key="${2}" + local value="${3}" + + test_that_array_is_defined "${arrayname}" || return 1 # If key is not defined we return _ # If the key is defined we return nothing From patchwork Sun Jun 16 16:02:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 7871 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hqj4WLqz3x1l for ; Sun, 16 Jun 2024 16:03:29 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4W2Hqf5Y8Xz5gZ; Sun, 16 Jun 2024 16:03:26 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4W2Hqf52M1z33Fy; Sun, 16 Jun 2024 16:03:26 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hqc4D1Qz33G6 for ; Sun, 16 Jun 2024 16:03:24 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4W2HqW6hw5z2rM; Sun, 16 Jun 2024 16:03:19 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1718553799; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xa/td31rfHus12evJi6wGw+9gZxBdAWE35arV842exE=; b=9CHuT7g3Nmw20XAfTZXIeiEuKcVvh1iJQjgPwzhbZYIco0f/a0Y2DZsRejYZlgHIF10Ui5 kTiNM14n11xeF6DA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1718553799; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xa/td31rfHus12evJi6wGw+9gZxBdAWE35arV842exE=; b=faHxgOT+BwqCV1aSBDz1EPXq7+4v48AxxHXAqlev2WFo7kTQZRJyCIXZ0Dc/zrVHoUsC1U 0bzelOp53mFA4PWRmZZm5T1cvW5Kt3Mc4dGt2R1KeuFG17mCHcjw3WVOO+ko2tUPpBpAAJ CBs3x0QP7o/asaEQ8Rs4KCVhNGQAIaeVXVgBWrLDhZJSLAylLxm4G4l5KangxXULdciCrh w4rBXUdlVi93dg2snUT+f3GHGNXUCXyRCIWf/dZohJtSse6AWvt1hphZdarmQgeh3jpA/b m2qFGmrERBM2djqIHXjASTx5mtbxuaTvmc0hSm9W8hYfXccrDv2KUqD99SoXOg== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH v2 09/18] tests: Add functions test_that_array_doesnt_have_key Date: Sun, 16 Jun 2024 18:02:36 +0200 Message-Id: <20240616160245.18865-10-jonatan.schlag@ipfire.org> In-Reply-To: <20240616160245.18865-1-jonatan.schlag@ipfire.org> References: <20240616160245.18865-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: 5YDEOPCQ2FM73CZOIIXZHSC7NNDXAGBB X-Message-ID-Hash: 5YDEOPCQ2FM73CZOIIXZHSC7NNDXAGBB X-MailFrom: jonatan.schlag@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Apparently we can set way more keys then I expected. So we need a function to check that we do not set certain key. Some keys need to be skipped. Signed-off-by: Jonatan Schlag --- tests/lib.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/lib.sh b/tests/lib.sh index 32481b6a5..bb06e11c2 100644 --- a/tests/lib.sh +++ b/tests/lib.sh @@ -74,6 +74,24 @@ test_value_in_array() { fi } +test_that_array_doesnt_have_key() { + local -n array="${1}" + local arrayname="${1}" + local key="${2}" + + test_that_array_is_defined "${arrayname}" || return 1 + + if [[ "${array["${key}"]+_}" == "_" ]]; then + log_test_failed "The array '${arrayname}' does contain the key '${key}'." + return 1 + else + log_test_succeded "The array '${arrayname}' does not contain the key '${key}'" + return 0 + fi + +} + + test_that_output_is(){ local reference_output_file="${1}" local file_descriptor="${2}" From patchwork Sun Jun 16 16:02:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 7872 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hqk2tybz3wy2 for ; Sun, 16 Jun 2024 16:03:30 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4W2Hqf6pQGz5nN; Sun, 16 Jun 2024 16:03:26 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4W2Hqf6JwTz33G2; Sun, 16 Jun 2024 16:03:26 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hqc55pMz33G6 for ; Sun, 16 Jun 2024 16:03:24 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4W2HqY1nD1z5Yr; Sun, 16 Jun 2024 16:03:21 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1718553801; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RyiJ+hul3DJVtMDvj/x2rAo0V3/09xYaFSYwy26odvo=; b=HLHgw0sqk6I/9FI8p/sfjtnUYPpuroQBL8L0HVPnATtMuxSUUjkMAwQ7wHVB+aplfFXU0Q VkR+3geeFMovhUDw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1718553801; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RyiJ+hul3DJVtMDvj/x2rAo0V3/09xYaFSYwy26odvo=; b=idNDx0vB1hh218ihB9P8bIZixiId0/10Njdp7sBygFj/laUDTDden9KYvUpQ4SBBqgwPUe Y3k2rOaebT4pTV7Iaj/3WnZSNkRgr0NhvqVtzL3R6fDfG56OWSy8oL06uv1M/6QUlnAmEK 5Q65/tmsifuoAoHfzQTsXdIFeASTikwP1XEj6XYQnBGl0pttRWupBa+KTvW6CWr8HwKeJs UhWqFRROMEcM84ITK44v2fftiV9v3oY6kjSIVFcpxCJ1x4fjZtIgQB4dXLhbdbNOL0gqo2 xelkduuYJgQAeyJPipl6Tm/MA12Ft4CMZAVdGzl24KVNAUeG5RCEKksAo4Dc1w== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH v2 10/18] initscript functions: add readhash Date: Sun, 16 Jun 2024 18:02:37 +0200 Message-Id: <20240616160245.18865-11-jonatan.schlag@ipfire.org> In-Reply-To: <20240616160245.18865-1-jonatan.schlag@ipfire.org> References: <20240616160245.18865-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: 6X3D7ROHLJZXHATOQXWH33OIAXVMAJXE X-Message-ID-Hash: 6X3D7ROHLJZXHATOQXWH33OIAXVMAJXE X-MailFrom: jonatan.schlag@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: To avoid the usage of eval and to store the config in an key value array, we introduce an new function. The tests only check if we read the correct value to the correct variable. One comment on the implementation as this has created some headache: >From https://www.gnu.org/software/bash/manual/bash.html#Bourne-Shell-Builtins "When used in a function, declare makes each name local, as with the local command, unless the -g option is used." So we need to use -g here Signed-off-by: Jonatan Schlag --- src/initscripts/system/functions | 15 +++++++++++++++ tests/src/initscripts/system/functions/data/1 | 17 +++++++++++++++++ tests/src/initscripts/system/functions/test.sh | 16 ++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 tests/src/initscripts/system/functions/data/1 create mode 100755 tests/src/initscripts/system/functions/test.sh diff --git a/src/initscripts/system/functions b/src/initscripts/system/functions index b610143ab..44ce999d3 100644 --- a/src/initscripts/system/functions +++ b/src/initscripts/system/functions @@ -891,3 +891,18 @@ volume_fs_type() { stat -f --format="%T" ${1} } + +readhash() { + local array="${1}" + local file="${2}" + + declare -A -g "${array}" + + local line + while read -r line; do + local key="${line%=*}" + local val="${line#*=}" + + printf -v "${array}[${key}]" "%s" "${val}" + done < "${file}" +} diff --git a/tests/src/initscripts/system/functions/data/1 b/tests/src/initscripts/system/functions/data/1 new file mode 100644 index 000000000..8aca9422b --- /dev/null +++ b/tests/src/initscripts/system/functions/data/1 @@ -0,0 +1,17 @@ +CONFIG_TYPE=3 +GREEN_DEV=green0 +GREEN_MACADDR=00:c0:08:8a:a0:47 +GREEN_DRIVER=r8175 +RED_DEV=red0 +RED_MACADDR=00:c0:08:8a:a0:56 +RED_DRIVER=r8283 +BLUE_DEV='blue0 net0' +BLUE_MACADDR=bc:30:7d:58:6b:e3 +BLUE_DRIVER=rt2800 +RED_DHCP_HOSTNAME=ipfire +RED_DHCP_FORCE_MTU= +RED_ADDRESS=0.0.0.0 +RED_NETMASK=0.0.0.0 +RED_TYPE=PPPOE +RED_NETADDRESS=0.0.0.0 + diff --git a/tests/src/initscripts/system/functions/test.sh b/tests/src/initscripts/system/functions/test.sh new file mode 100755 index 000000000..dbb2d8a62 --- /dev/null +++ b/tests/src/initscripts/system/functions/test.sh @@ -0,0 +1,16 @@ +#!/usr/bin/bash + +SCRIPT_PATH="$(dirname "$(readlink -f "$0")")" + +ROOT="$(readlink -f "${SCRIPT_PATH}/../../../../..")" + +. ${ROOT}/tests/lib.sh + +. ${ROOT}/src/initscripts/system/functions + +# read the date in +readhash "CONFIG" "${SCRIPT_PATH}/data/1" + +# test if we read the correct data +test_value_in_array "CONFIG" "RED_DHCP_HOSTNAME" "ipfire" +test_value_in_array "CONFIG" "BLUE_MACADDR" "bc:30:7d:58:6b:e3" From patchwork Sun Jun 16 16:02:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 7873 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hql1Zqzz3ws3 for ; Sun, 16 Jun 2024 16:03:31 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4W2Hqh0vJ2z5mk; Sun, 16 Jun 2024 16:03:28 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4W2Hqh0NRcz33Fr; Sun, 16 Jun 2024 16:03:28 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hqd1Dbrz33FL for ; Sun, 16 Jun 2024 16:03:25 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4W2HqZ5GJ3z2Yw; Sun, 16 Jun 2024 16:03:22 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1718553802; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=94wlPYYqZR65s0IGT1Jcr5skhYfsKNk0r2MObxyVxSA=; b=91y/RiOqj4JP+ueb8Pzn00r/+r8R5MtqmuLX24dB457qLsUZs5FMlxtZiJgUEzl56Di49H 3amf+Ol0P8cD1LCg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1718553802; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=94wlPYYqZR65s0IGT1Jcr5skhYfsKNk0r2MObxyVxSA=; b=JSwzcaMlsrib/hghe2mIyvLGYItoGhgpFVmY8VdozZvrnFo4qUW0v/O5aZlkRVK5t7+4Fq yqGni+D7sxx2oO2gP7gMohLgr7DCCT4dGoV8p6z2bKOJOFS6CjD2g2/2PrfI/BUZ7SVp32 0MzV5ywCnvv0Gtc1UNZc1U+EqhsoIicq7V5tXunqOSKfM3JhtYjqsrMi/J3D0itoGBfq5E p3H1A2u7vEac9xECp4UYZsCfmZprZ+3whapoHnz+z5123L7ccil6D/FiPG0sp1kNwiqIVu noInVnWHK8GuVg5HevqUiWtJuYOTQVIB7UDA7Ubk5SDSEVEAa8ImhxhIyGMrpA== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH v2 11/18] initscript fkt: ignore blank lines in readhash Date: Sun, 16 Jun 2024 18:02:38 +0200 Message-Id: <20240616160245.18865-12-jonatan.schlag@ipfire.org> In-Reply-To: <20240616160245.18865-1-jonatan.schlag@ipfire.org> References: <20240616160245.18865-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: TFYYEBKWLJXRS4R2XYB3UDUEX3FWSBGS X-Message-ID-Hash: TFYYEBKWLJXRS4R2XYB3UDUEX3FWSBGS X-MailFrom: jonatan.schlag@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Signed-off-by: Jonatan Schlag --- src/initscripts/system/functions | 6 ++++++ tests/src/initscripts/system/functions/data/1_output_stderr | 0 tests/src/initscripts/system/functions/data/1_output_stdout | 0 tests/src/initscripts/system/functions/test.sh | 3 +++ 4 files changed, 9 insertions(+) create mode 100644 tests/src/initscripts/system/functions/data/1_output_stderr create mode 100644 tests/src/initscripts/system/functions/data/1_output_stdout diff --git a/src/initscripts/system/functions b/src/initscripts/system/functions index 44ce999d3..3f01be9e0 100644 --- a/src/initscripts/system/functions +++ b/src/initscripts/system/functions @@ -900,6 +900,12 @@ readhash() { local line while read -r line; do + + # Skip Blank Lines + if [[ ${line} =~ ^[[:space:]]*$ ]]; then + continue + fi + local key="${line%=*}" local val="${line#*=}" diff --git a/tests/src/initscripts/system/functions/data/1_output_stderr b/tests/src/initscripts/system/functions/data/1_output_stderr new file mode 100644 index 000000000..e69de29bb diff --git a/tests/src/initscripts/system/functions/data/1_output_stdout b/tests/src/initscripts/system/functions/data/1_output_stdout new file mode 100644 index 000000000..e69de29bb diff --git a/tests/src/initscripts/system/functions/test.sh b/tests/src/initscripts/system/functions/test.sh index dbb2d8a62..751be6884 100755 --- a/tests/src/initscripts/system/functions/test.sh +++ b/tests/src/initscripts/system/functions/test.sh @@ -14,3 +14,6 @@ readhash "CONFIG" "${SCRIPT_PATH}/data/1" # test if we read the correct data test_value_in_array "CONFIG" "RED_DHCP_HOSTNAME" "ipfire" test_value_in_array "CONFIG" "BLUE_MACADDR" "bc:30:7d:58:6b:e3" + +test_that_output_is "${SCRIPT_PATH}/data/1_output_stdout" "1" readhash "CONFIG" "${SCRIPT_PATH}/data/1" +test_that_output_is "${SCRIPT_PATH}/data/1_output_stderr" "2" readhash "CONFIG" "${SCRIPT_PATH}/data/1" From patchwork Sun Jun 16 16:02:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 7874 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hql71ZPz3x1l for ; Sun, 16 Jun 2024 16:03:31 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4W2Hqj1xYcz5mZ; Sun, 16 Jun 2024 16:03:29 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4W2Hqj1Sjnz33Fy; Sun, 16 Jun 2024 16:03:29 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hqd5cBvz33Fq for ; Sun, 16 Jun 2024 16:03:25 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4W2Hqc6yHYz4XG; Sun, 16 Jun 2024 16:03:24 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1718553805; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LxemwrvfhcWJzhSOl4YSPOPEH0qR9p5fRQjXq3aVVas=; b=zfEXGjrNn+zrncrCIecieqPctwUtuMc7EY/pfYh9G7riOo8XUloR1eljUlQeqEtiDJ1gdM +bhuwhf9VOqPiqCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1718553805; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LxemwrvfhcWJzhSOl4YSPOPEH0qR9p5fRQjXq3aVVas=; b=JZKt9GQjUruUNmuimIUf5h1GTngRyNxirXZDd/4DLWlN7B+EoDIaPGIaDXJolJS29FVioo xRw+Z4fY+T5OrXyGVJOHOTK+QNX6YwG2xKD6BwdfSkINSA/d1xKZvPxLf4KIjHl0SrE7w3 NhWwKBv/mKfGM/nNlm3PIXsqwswPXpdwPahWrqFZYuL+CrSAYLrjfQ0Ly88l6rMQO53FZm cAvPy8gWEex5XWe3of5LoZFgbu7Im3UDo5dpt2rbfB3r+OVnmOnKPoKavGxTQ/HkNmY2tT quWHe4pV20VneGFh5iNKQJPj7z7QK62Byf609On3P/oG3pAA1rZYtyDY/KWHYA== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH v2 12/18] initscripts fkt: Ignore comments in readhash Date: Sun, 16 Jun 2024 18:02:39 +0200 Message-Id: <20240616160245.18865-13-jonatan.schlag@ipfire.org> In-Reply-To: <20240616160245.18865-1-jonatan.schlag@ipfire.org> References: <20240616160245.18865-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: PQNZWVOWM2XGNME5FEAAZPDL334UPZBT X-Message-ID-Hash: PQNZWVOWM2XGNME5FEAAZPDL334UPZBT X-MailFrom: jonatan.schlag@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: As '#Another Comment' is a valid key we test this change by checking if the comments do not end up as keys in our array. Signed-off-by: Jonatan Schlag --- src/initscripts/system/functions | 5 +++++ tests/src/initscripts/system/functions/data/1 | 3 +++ tests/src/initscripts/system/functions/test.sh | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/src/initscripts/system/functions b/src/initscripts/system/functions index 3f01be9e0..6107463fc 100644 --- a/src/initscripts/system/functions +++ b/src/initscripts/system/functions @@ -906,6 +906,11 @@ readhash() { continue fi + # Skip Comments + if [[ ${line} =~ ^#.*$ ]]; then + continue + fi + local key="${line%=*}" local val="${line#*=}" diff --git a/tests/src/initscripts/system/functions/data/1 b/tests/src/initscripts/system/functions/data/1 index 8aca9422b..c75620b6b 100644 --- a/tests/src/initscripts/system/functions/data/1 +++ b/tests/src/initscripts/system/functions/data/1 @@ -5,6 +5,7 @@ GREEN_DRIVER=r8175 RED_DEV=red0 RED_MACADDR=00:c0:08:8a:a0:56 RED_DRIVER=r8283 +# Another Comment BLUE_DEV='blue0 net0' BLUE_MACADDR=bc:30:7d:58:6b:e3 BLUE_DRIVER=rt2800 @@ -15,3 +16,5 @@ RED_NETMASK=0.0.0.0 RED_TYPE=PPPOE RED_NETADDRESS=0.0.0.0 +# Comment for testing + # Comment for testing Comments with spaces before diff --git a/tests/src/initscripts/system/functions/test.sh b/tests/src/initscripts/system/functions/test.sh index 751be6884..915f098a0 100755 --- a/tests/src/initscripts/system/functions/test.sh +++ b/tests/src/initscripts/system/functions/test.sh @@ -15,5 +15,11 @@ readhash "CONFIG" "${SCRIPT_PATH}/data/1" test_value_in_array "CONFIG" "RED_DHCP_HOSTNAME" "ipfire" test_value_in_array "CONFIG" "BLUE_MACADDR" "bc:30:7d:58:6b:e3" +# Test that comments are skipped +# apparently the way we read the file strips the whitespace, so the key does not contain any whitespace either +test_that_array_doesnt_have_key "CONFIG" "# Another Comment" +test_that_array_doesnt_have_key "CONFIG" "# Comment for testing" +test_that_array_doesnt_have_key "CONFIG" "# Comment for testing Comments with spaces before" + test_that_output_is "${SCRIPT_PATH}/data/1_output_stdout" "1" readhash "CONFIG" "${SCRIPT_PATH}/data/1" test_that_output_is "${SCRIPT_PATH}/data/1_output_stderr" "2" readhash "CONFIG" "${SCRIPT_PATH}/data/1" From patchwork Sun Jun 16 16:02:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 7875 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hqm5yfVz3wy2 for ; Sun, 16 Jun 2024 16:03:32 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4W2Hql3b5Gz5gB; Sun, 16 Jun 2024 16:03:31 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4W2Hql36Ffz33G0; Sun, 16 Jun 2024 16:03:31 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hqf1tKtz33FL for ; Sun, 16 Jun 2024 16:03:26 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4W2Hqf0d7Bz5mZ; Sun, 16 Jun 2024 16:03:26 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1718553806; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OdFiA/IhjpXpzLtAYV3+sC9oPOkPO5cAWidy/qB7+V0=; b=g3pnXPrZ+c3vn1WlHjduo3DE99XMeo9y/CqB2BkVBiYBI3uULjIet+qZzAHglZtApPaaLB RSDH7IdcGgnKQ/BA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1718553806; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OdFiA/IhjpXpzLtAYV3+sC9oPOkPO5cAWidy/qB7+V0=; b=OklrJtX8EACR9zRdE5p8pQfpcJ2SEewMn49dg/aMyNaini4sxXy8oW6jv24e7Ve6yNXwjc eXUHvIsJKW2V7Eu8YAhq47xi6yVYntwC5egvXKPcBwUPx+7i9PWXhvIgq+VETwfhojZgdi lA7N+/3EaB62tgGhJaOPb9xkRbdG3MDLa6qb9mSwv6FCtmj3dKLIyHpOOSss8Bp5e5mIqc 3xPTaWLkqtngqNZ99mPyKbQGTp7RYpmCKIZ7d7VzARVG98yXffA5W1MHnbAqpqnf5CdaVe CyYK1AW1vW1cWvlz2m30k9tw384il+tIkzvqUEN8UU0MjVle7AL9PJEUOUFArg== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH v2 13/18] initscripts fkt: ignore invalid keys in readhash Date: Sun, 16 Jun 2024 18:02:40 +0200 Message-Id: <20240616160245.18865-14-jonatan.schlag@ipfire.org> In-Reply-To: <20240616160245.18865-1-jonatan.schlag@ipfire.org> References: <20240616160245.18865-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: 5MLKF62XJ6MFCE6NZYKFSXQV7WZHRRIP X-Message-ID-Hash: 5MLKF62XJ6MFCE6NZYKFSXQV7WZHRRIP X-MailFrom: jonatan.schlag@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Signed-off-by: Jonatan Schlag --- src/initscripts/system/functions | 6 ++++++ tests/src/initscripts/system/functions/data/2 | 20 +++++++++++++++++++ .../system/functions/data/2_output_stderr | 4 ++++ .../system/functions/data/2_output_stdout | 0 .../src/initscripts/system/functions/test.sh | 16 +++++++++++++++ 5 files changed, 46 insertions(+) create mode 100644 tests/src/initscripts/system/functions/data/2 create mode 100644 tests/src/initscripts/system/functions/data/2_output_stderr create mode 100644 tests/src/initscripts/system/functions/data/2_output_stdout diff --git a/src/initscripts/system/functions b/src/initscripts/system/functions index 6107463fc..bbcfab95d 100644 --- a/src/initscripts/system/functions +++ b/src/initscripts/system/functions @@ -914,6 +914,12 @@ readhash() { local key="${line%=*}" local val="${line#*=}" + # Skip lines with an invalid key + if ! [[ ${key} =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]]; then + echo "Invalid key '${key}'" >&2 + continue + fi + printf -v "${array}[${key}]" "%s" "${val}" done < "${file}" } diff --git a/tests/src/initscripts/system/functions/data/2 b/tests/src/initscripts/system/functions/data/2 new file mode 100644 index 000000000..3e1a7028b --- /dev/null +++ b/tests/src/initscripts/system/functions/data/2 @@ -0,0 +1,20 @@ +CONFIG_TYPE=3 +GREEN_DEV=green0 +GREEN_MACADDR=00:c0:08:8a:a0:47 +GREEN_DRIVER=r8175 +-RED_DEV=red0 +RE??D_MACADDR=00:c0:08:8a:a0:56 +RED&&_DRIVER=r8283 +# Another Comment +0BLUE_DEV='blue0 net0' +BLUE_MACADDR=bc:30:7d:58:6b:e3 +BLUE_DRIVER=rt2800 +RED_DHCP_HOSTNAME=ipfire +RED_DHCP_FORCE_MTU= +RED_ADDRESS=0.0.0.0 +RED_NETMASK=0.0.0.0 +RED_TYPE=PPPOE +RED_NETADDRESS=0.0.0.0 + +# Comment for testing + # Comment for testing Comments with spaces before diff --git a/tests/src/initscripts/system/functions/data/2_output_stderr b/tests/src/initscripts/system/functions/data/2_output_stderr new file mode 100644 index 000000000..dfcf2154b --- /dev/null +++ b/tests/src/initscripts/system/functions/data/2_output_stderr @@ -0,0 +1,4 @@ +Invalid key '-RED_DEV' +Invalid key 'RE??D_MACADDR' +Invalid key 'RED&&_DRIVER' +Invalid key '0BLUE_DEV' diff --git a/tests/src/initscripts/system/functions/data/2_output_stdout b/tests/src/initscripts/system/functions/data/2_output_stdout new file mode 100644 index 000000000..e69de29bb diff --git a/tests/src/initscripts/system/functions/test.sh b/tests/src/initscripts/system/functions/test.sh index 915f098a0..a2d6535a5 100755 --- a/tests/src/initscripts/system/functions/test.sh +++ b/tests/src/initscripts/system/functions/test.sh @@ -23,3 +23,19 @@ test_that_array_doesnt_have_key "CONFIG" "# Comment for testing Comments with sp test_that_output_is "${SCRIPT_PATH}/data/1_output_stdout" "1" readhash "CONFIG" "${SCRIPT_PATH}/data/1" test_that_output_is "${SCRIPT_PATH}/data/1_output_stderr" "2" readhash "CONFIG" "${SCRIPT_PATH}/data/1" + +# Check with invalid Lines (values and keys) +readhash "CONFIG2" "${SCRIPT_PATH}/data/2" &> /dev/null + +# test if we read the correct data +test_value_in_array "CONFIG2" "RED_DHCP_HOSTNAME" "ipfire" +test_value_in_array "CONFIG2" "BLUE_MACADDR" "bc:30:7d:58:6b:e3" + +# We could do some complex checking if we would create functions to check for correct values and keys. +# We would be then able to mock these function and check if they are correctly called and if the data +# does not end up in our array. +# I think the more simpler way of checking the logged errors is the fastes way here. +test_that_output_is "${SCRIPT_PATH}/data/2_output_stdout" "1" readhash "CONFIG2" "${SCRIPT_PATH}/data/2" +test_that_output_is "${SCRIPT_PATH}/data/2_output_stderr" "2" readhash "CONFIG2" "${SCRIPT_PATH}/data/2" + + From patchwork Sun Jun 16 16:02:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 7876 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hqn2VqJz3x5M for ; Sun, 16 Jun 2024 16:03:33 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4W2Hql4wztz5p7; Sun, 16 Jun 2024 16:03:31 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4W2Hql4PwYz33G2; Sun, 16 Jun 2024 16:03:31 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hqg30Xfz33Fh for ; Sun, 16 Jun 2024 16:03:27 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4W2Hqg1GLhz2V5; Sun, 16 Jun 2024 16:03:27 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1718553807; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a/23+XT+oNeMsHejHIsftoPiiE0hA1T/lfAqwOXpkz8=; b=xh0YxbhJ6lf/DdkOcwmihXd7Jp6Q2KjN2wCs2P1jDsaXPkfNh7qd4tRRDDloiIuUYeFHSw INmPMEwarUdGOIDQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1718553807; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a/23+XT+oNeMsHejHIsftoPiiE0hA1T/lfAqwOXpkz8=; b=d42Zwj8dBZKjSwBbetw0nDtsCHOA2fYxFAfgfJrbQKgSWSnKGchFFV7S4F0N4nqZdo6J4v 9LbQAl6MpT57+Mk1VPLtr6oXPwJp1q8ZiKNJjjy2VGk0P2JGD6ilJnyirIVG54ssX3Kvck EGNlR+/Yrsvq+zr2N+GMxLPSQCT6XZ4H+kMJveKBJaWIZ2qd9Amtwb4ES+l7jBYQfpzYqK f038DtIrjhA3713ZvC8ExGUmLT+4nxJ7osUCaQ1N6IFQc7+8+RvRI3HCbE71XB6JhRPYDR DYGLsJvmMoHrs5jjWK6fZV5efp/qK6rnGYc4kb1ClXFiFgv0yYk8X+Ccmqsq8Q== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH v2 14/18] initscripts fkt: Check for invalid values in readhash Date: Sun, 16 Jun 2024 18:02:41 +0200 Message-Id: <20240616160245.18865-15-jonatan.schlag@ipfire.org> In-Reply-To: <20240616160245.18865-1-jonatan.schlag@ipfire.org> References: <20240616160245.18865-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: CUGNLTMEQM724ONXOOPFXQCC2DEBZ2KM X-Message-ID-Hash: CUGNLTMEQM724ONXOOPFXQCC2DEBZ2KM X-MailFrom: jonatan.schlag@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Signed-off-by: Jonatan Schlag --- src/initscripts/system/functions | 6 ++++++ tests/src/initscripts/system/functions/data/2 | 8 ++++---- .../src/initscripts/system/functions/data/2_output_stderr | 4 ++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/initscripts/system/functions b/src/initscripts/system/functions index bbcfab95d..ce9d2a5ad 100644 --- a/src/initscripts/system/functions +++ b/src/initscripts/system/functions @@ -920,6 +920,12 @@ readhash() { continue fi + # Skip lines with invalid values + if ! [[ ${val} =~ ^[\'][\ A-Za-z0-9=/,.:%_@#+-]*[\']$ ]] && ! [[ ${val} =~ ^[A-Za-z0-9=/,.:%_@#+-]*$ ]]; then + echo "Invalid value '${val}' for key '${key}'" >&2 + continue + fi + printf -v "${array}[${key}]" "%s" "${val}" done < "${file}" } diff --git a/tests/src/initscripts/system/functions/data/2 b/tests/src/initscripts/system/functions/data/2 index 3e1a7028b..3060ad880 100644 --- a/tests/src/initscripts/system/functions/data/2 +++ b/tests/src/initscripts/system/functions/data/2 @@ -1,7 +1,7 @@ -CONFIG_TYPE=3 -GREEN_DEV=green0 -GREEN_MACADDR=00:c0:08:8a:a0:47 -GREEN_DRIVER=r8175 +CONFIG_TYPE=?3 +GREEN_DEV=gree!n0 +GREEN_MACADDR=00:c0:08:8a :a0:47 +GREEN_DRIVER="r8175" -RED_DEV=red0 RE??D_MACADDR=00:c0:08:8a:a0:56 RED&&_DRIVER=r8283 diff --git a/tests/src/initscripts/system/functions/data/2_output_stderr b/tests/src/initscripts/system/functions/data/2_output_stderr index dfcf2154b..f29e94b19 100644 --- a/tests/src/initscripts/system/functions/data/2_output_stderr +++ b/tests/src/initscripts/system/functions/data/2_output_stderr @@ -1,3 +1,7 @@ +Invalid value '?3' for key 'CONFIG_TYPE' +Invalid value 'gree!n0' for key 'GREEN_DEV' +Invalid value '00:c0:08:8a :a0:47' for key 'GREEN_MACADDR' +Invalid value '"r8175"' for key 'GREEN_DRIVER' Invalid key '-RED_DEV' Invalid key 'RE??D_MACADDR' Invalid key 'RED&&_DRIVER' From patchwork Sun Jun 16 16:02:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 7877 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hqq1CdKz3ws3 for ; Sun, 16 Jun 2024 16:03:35 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4W2Hqp6dHSz5Wm; Sun, 16 Jun 2024 16:03:34 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4W2Hqp64LJz33Fw; Sun, 16 Jun 2024 16:03:34 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hqh1Qjfz33Fw for ; Sun, 16 Jun 2024 16:03:28 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4W2Hqh0Dl4z2V5; Sun, 16 Jun 2024 16:03:28 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1718553808; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NJgcmGJj32DIKmnQXZZJvYfAV0yaTKHQx26kTqivejA=; b=sdnl1fQXyCyDzIw1BTTkEuYDH+PUgcnAx2F3gtYx1dal41Q4/VeSR7CUS0pm5mLZaBzje9 V60TpqpA38zQd6BQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1718553808; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NJgcmGJj32DIKmnQXZZJvYfAV0yaTKHQx26kTqivejA=; b=HQLr72epOnbq7BeywU/u5t5uQmnIf05zb0L2lxdzAwiqd9JLPkBytsCQYTMYUUWVk75ZHk Ckd4TwXpo7eJOvW9V+Xc7aMW0eqbsovStKpgFseeMQIZ6dc7wEs/EvbhoH8Fc0FCflKGhv mhk0LmCYp8PFHwASdWEyhXwWojpWmAC+5lfHZW7e82IAzuudEqCf8KFjD/TMZWOsK9PxhN KOEcbkG++EbDEm0ArFaz3JZ2Rr3XUBcCJ0PPxi9BCzThfG26su6OWWILa4pkT/d3ExNvxl P83toJbWPtnnmvE+DygMJfirYFVtRJxvkGrKN+tjSy8yTccJSIHnx463NLGqHA== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH v2 15/18] initscripts fkt: readhash should only parse lines with a = Date: Sun, 16 Jun 2024 18:02:42 +0200 Message-Id: <20240616160245.18865-16-jonatan.schlag@ipfire.org> In-Reply-To: <20240616160245.18865-1-jonatan.schlag@ipfire.org> References: <20240616160245.18865-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: TQ3KSP6LIBVPOM55ADRPPO3VEJGZMH3S X-Message-ID-Hash: TQ3KSP6LIBVPOM55ADRPPO3VEJGZMH3S X-MailFrom: jonatan.schlag@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: A line without a = is clearly invalid. Signed-off-by: Jonatan Schlag --- src/initscripts/system/functions | 6 ++++++ tests/src/initscripts/system/functions/data/2 | 1 + tests/src/initscripts/system/functions/data/2_output_stderr | 1 + 3 files changed, 8 insertions(+) diff --git a/src/initscripts/system/functions b/src/initscripts/system/functions index ce9d2a5ad..c9c4c0675 100644 --- a/src/initscripts/system/functions +++ b/src/initscripts/system/functions @@ -911,6 +911,12 @@ readhash() { continue fi + # Skip lines without a = + if ! [[ ${line} =~ [^=]*=[^=]*$ ]]; then + echo "Invalid line '${line}'" >&2 + continue + fi + local key="${line%=*}" local val="${line#*=}" diff --git a/tests/src/initscripts/system/functions/data/2 b/tests/src/initscripts/system/functions/data/2 index 3060ad880..760294c30 100644 --- a/tests/src/initscripts/system/functions/data/2 +++ b/tests/src/initscripts/system/functions/data/2 @@ -15,6 +15,7 @@ RED_ADDRESS=0.0.0.0 RED_NETMASK=0.0.0.0 RED_TYPE=PPPOE RED_NETADDRESS=0.0.0.0 +Line_without_a_equal_sign_is_also_invalid # Comment for testing # Comment for testing Comments with spaces before diff --git a/tests/src/initscripts/system/functions/data/2_output_stderr b/tests/src/initscripts/system/functions/data/2_output_stderr index f29e94b19..82f035e26 100644 --- a/tests/src/initscripts/system/functions/data/2_output_stderr +++ b/tests/src/initscripts/system/functions/data/2_output_stderr @@ -6,3 +6,4 @@ Invalid key '-RED_DEV' Invalid key 'RE??D_MACADDR' Invalid key 'RED&&_DRIVER' Invalid key '0BLUE_DEV' +Invalid line 'Line_without_a_equal_sign_is_also_invalid' From patchwork Sun Jun 16 16:02:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 7878 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hqq5mrPz3wy2 for ; Sun, 16 Jun 2024 16:03:35 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4W2Hqq17wlz5p0; Sun, 16 Jun 2024 16:03:35 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4W2Hqq0d7Bz33Fy; Sun, 16 Jun 2024 16:03:35 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hqh6z0Zz33Ft for ; Sun, 16 Jun 2024 16:03:28 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4W2Hqh5rkTz2V5; Sun, 16 Jun 2024 16:03:28 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1718553808; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+XlJYYECdVNEFAqhLHxfOldgj31stWgR4QRpImuc4Uk=; b=BHL9YSU8eOTgeI5c5wwJOqkTmha5bsugfRHdhDMFM+vdMA5PZ9Iu09qqmGiMKlubu77pdQ XiTpN68LnzQb/tCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1718553808; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+XlJYYECdVNEFAqhLHxfOldgj31stWgR4QRpImuc4Uk=; b=lu3mtSPHBqE+cZAjnTlg2TTnhf8vb8zv2bAlvdjzle4jQlfZ+mt7ebFSNpKpuy3prux46h tFpgtTHz6E2tw0AFbkZlCordarukxk3TVDnz1x9FuII0refNE5uFE6mnMET/d3kiVhEIdJ +QGRIoMcmwTVzCLaq6LzbBSLOGrziAF/oVIGzfgOgOZRzXR+vJn2xkWNK1f33aMvf4ajZ9 L62PHwo9NazAr880KBuY/5ViVMKCJOzQTfB7pSTpoBmeVeEtpFQ+frkkvCT0eBFc4OHmht 81p2RtPhpWH/sKWXbHSYxEOqgGlIDUXUxNtyUDw/JgZoM9M3OBZMa3tVIVaCVg== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH v2 16/18] initscripts fkt: keep readhash compatible with older implementation Date: Sun, 16 Jun 2024 18:02:43 +0200 Message-Id: <20240616160245.18865-17-jonatan.schlag@ipfire.org> In-Reply-To: <20240616160245.18865-1-jonatan.schlag@ipfire.org> References: <20240616160245.18865-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: VJBMV5ULC72UAK5RH3YYF2JIVUE436BJ X-Message-ID-Hash: VJBMV5ULC72UAK5RH3YYF2JIVUE436BJ X-MailFrom: jonatan.schlag@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: With the use of eval BLUE_DEV='blue0 net0' stored "blue0 net0" in the variable BLUE_DEV not "'blue0 net0'" Signed-off-by: Jonatan Schlag --- src/initscripts/system/functions | 4 ++++ tests/src/initscripts/system/functions/test.sh | 1 + 2 files changed, 5 insertions(+) diff --git a/src/initscripts/system/functions b/src/initscripts/system/functions index c9c4c0675..6d72e4119 100644 --- a/src/initscripts/system/functions +++ b/src/initscripts/system/functions @@ -932,6 +932,10 @@ readhash() { continue fi + # strip leading and trailing single quotes + val="${val#\'}" + val="${val%\'}" + printf -v "${array}[${key}]" "%s" "${val}" done < "${file}" } diff --git a/tests/src/initscripts/system/functions/test.sh b/tests/src/initscripts/system/functions/test.sh index a2d6535a5..e7f695f55 100755 --- a/tests/src/initscripts/system/functions/test.sh +++ b/tests/src/initscripts/system/functions/test.sh @@ -14,6 +14,7 @@ readhash "CONFIG" "${SCRIPT_PATH}/data/1" # test if we read the correct data test_value_in_array "CONFIG" "RED_DHCP_HOSTNAME" "ipfire" test_value_in_array "CONFIG" "BLUE_MACADDR" "bc:30:7d:58:6b:e3" +test_value_in_array "CONFIG" "BLUE_DEV" "blue0 net0" # Test that comments are skipped # apparently the way we read the file strips the whitespace, so the key does not contain any whitespace either From patchwork Sun Jun 16 16:02:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 7879 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hqr5QLQz3x1l for ; Sun, 16 Jun 2024 16:03:36 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4W2Hqr2qFTz5mp; Sun, 16 Jun 2024 16:03:36 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4W2Hqr2GP5z33FL; Sun, 16 Jun 2024 16:03:36 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hqk4kFgz2xtd for ; Sun, 16 Jun 2024 16:03:30 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4W2Hqk2Lb1z5nk; Sun, 16 Jun 2024 16:03:30 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1718553810; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZGU/6y2nUMStvmCNVH7JLdDrVlh0bzQQQV1Mv2Zf1dE=; b=6FheXw7LBCraU94Eq/uIRVkJD9lum42VXjiOF3nnrN1yEUFOqSpwQdiLlINdIMKFAZmrt3 3nlSoInzpo7FyuBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1718553810; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZGU/6y2nUMStvmCNVH7JLdDrVlh0bzQQQV1Mv2Zf1dE=; b=a/+GRV3cCk7TLKzEZ2mWx7x25ZQM5Gw1f3zcr0pi6wr6RhQqGbC9EiP6Y7gZw0Y5WvuGI+ dodOfE929SDtc92I7mPBuObLgokM+/2Tq+537nnOY0nKGBYWdcb2nypvPa3dpVUgT60PVC +ghvuWpR00PSTiC5ogAxHtN6yI/urH1sQMfCpPNjh74p9zX3XenlRvEy4W6Vngdi9npzPv DIvqosn6xqFzs+h19BGwKv/qzQuggLvcZCrWWNdjvNfPdQ+Icn7IHCPPgSJxGfgLey+ttv KSQqqRaGxNdCSbJnueWzHxURV/IRgtDzNsCt/GLW85k5LsRwgfLvT6301F+blQ== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH v2 17/18] initscripts fkt: Fix shebang Date: Sun, 16 Jun 2024 18:02:44 +0200 Message-Id: <20240616160245.18865-18-jonatan.schlag@ipfire.org> In-Reply-To: <20240616160245.18865-1-jonatan.schlag@ipfire.org> References: <20240616160245.18865-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: BM7GQQECWFKDCDVCMLRALUJM3NWDR37Q X-Message-ID-Hash: BM7GQQECWFKDCDVCMLRALUJM3NWDR37Q X-MailFrom: jonatan.schlag@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: We use features only available in bash. So we should state correctly that the script should be executed in bash. As sh is a symlink to bash this makes not differences on a ipfire system. But my linter is less chatty with this change. Signed-off-by: Jonatan Schlag --- src/initscripts/system/functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/initscripts/system/functions b/src/initscripts/system/functions index 6d72e4119..0775d74a1 100644 --- a/src/initscripts/system/functions +++ b/src/initscripts/system/functions @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash ############################################################################### # # # IPFire.org - A linux based firewall # From patchwork Sun Jun 16 16:02:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 7880 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hqs2NZJz3ws3 for ; Sun, 16 Jun 2024 16:03:37 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4W2Hqr4GcDz5pN; Sun, 16 Jun 2024 16:03:36 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4W2Hqr3jwTz33FL; Sun, 16 Jun 2024 16:03:36 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hql2MfKz33Fh for ; Sun, 16 Jun 2024 16:03:31 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4W2Hql0s5sz5nr; Sun, 16 Jun 2024 16:03:31 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1718553811; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h8O30gjaF/CkkL4pBYzk6Y6qkWIeKW1wCTGibBFeFL4=; b=tayKWP2aOeLPfAutd5RYqGTP1xlQnYf3WbfLBoio6c7ybYjIqQtWz00a7SIB9E9z5j4v05 IkCOWkl0T1LGYQDA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1718553811; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h8O30gjaF/CkkL4pBYzk6Y6qkWIeKW1wCTGibBFeFL4=; b=ICoP6tMgOnll1P1OhpGsWld059jdqo3ocGJ+Ac3o8GXR6+0gI7TH2V/kKYqELJshGBmijP voYBcXwl8LtDPHMvZgzdFrRDXL4+erO84qD23orkKk//YoC+66EjszgWslRCt4VBqL5fHn jJQrrYKkGyJJHc08xh8nuiOQ3uYfNZEkHTVWAe2iFBCTDdHlhdPB6A+i4oao227kV4kOha KTWaOEh74GAl346IwWXBdR5mHMV4wtetNP4yZuaxkw1qAXqFLa7O+5AZl78qlYKTIHZ7Np 4ktcSnb4eH5qQkM6Yp8UGjUIm+khBBP9gZTrh+h2/1Uy2pvY1d5AfrZVA32j8Q== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH v2 18/18] initscripts fkt: Check that readhash returns 1 on a missing file Date: Sun, 16 Jun 2024 18:02:45 +0200 Message-Id: <20240616160245.18865-19-jonatan.schlag@ipfire.org> In-Reply-To: <20240616160245.18865-1-jonatan.schlag@ipfire.org> References: <20240616160245.18865-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: JG7AYPGB2OG3XVCFWNXEA5FTTMEDLFAB X-Message-ID-Hash: JG7AYPGB2OG3XVCFWNXEA5FTTMEDLFAB X-MailFrom: jonatan.schlag@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: It already does that, so the function is not changed Signed-off-by: Jonatan Schlag --- tests/src/initscripts/system/functions/test.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/src/initscripts/system/functions/test.sh b/tests/src/initscripts/system/functions/test.sh index e7f695f55..dbcbd45ef 100755 --- a/tests/src/initscripts/system/functions/test.sh +++ b/tests/src/initscripts/system/functions/test.sh @@ -10,6 +10,7 @@ ROOT="$(readlink -f "${SCRIPT_PATH}/../../../../..")" # read the date in readhash "CONFIG" "${SCRIPT_PATH}/data/1" +test_command [ $? == 0 ] # test if we read the correct data test_value_in_array "CONFIG" "RED_DHCP_HOSTNAME" "ipfire" @@ -27,6 +28,8 @@ test_that_output_is "${SCRIPT_PATH}/data/1_output_stderr" "2" readhash "CONFIG" # Check with invalid Lines (values and keys) readhash "CONFIG2" "${SCRIPT_PATH}/data/2" &> /dev/null +test_command [ $? == 0 ] + # test if we read the correct data test_value_in_array "CONFIG2" "RED_DHCP_HOSTNAME" "ipfire" @@ -39,4 +42,6 @@ test_value_in_array "CONFIG2" "BLUE_MACADDR" "bc:30:7d:58:6b:e3" test_that_output_is "${SCRIPT_PATH}/data/2_output_stdout" "1" readhash "CONFIG2" "${SCRIPT_PATH}/data/2" test_that_output_is "${SCRIPT_PATH}/data/2_output_stderr" "2" readhash "CONFIG2" "${SCRIPT_PATH}/data/2" - +# Check non existent file +readhash "CONFIG3" "${SCRIPT_PATH}/data/-1" &> /dev/null +test_command [ $? == 1 ]