Message ID | 20240520090611.10406-14-jonatan.schlag@ipfire.org |
---|---|
State | New |
Headers |
Return-Path: <development-bounces@lists.ipfire.org> 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 4VjWsp5YYsz3wxb for <patchwork@web04.haj.ipfire.org>; Mon, 20 May 2024 09:07:10 +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 4VjWsl3YmXzcS; Mon, 20 May 2024 09:07:07 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4VjWsG6b21z336Z; Mon, 20 May 2024 09:06:42 +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 4VjWsD0w1kz2y2N for <development@lists.ipfire.org>; Mon, 20 May 2024 09:06:40 +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 4VjWs809GMz15J; Mon, 20 May 2024 09:06:36 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1716195996; 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=uISKL2l3A/kw68nYfY/vcC6+uwO13p2Wl0Fl+9foNfY=; b=1GVV/Do+SODGwq/ppbrkYpPE9qTs4sxVVnhhOBqmb3PbxwD3SGw28NoQ9XY6BoWb4ZRMqc NtVrHvJV8OLXSmCw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1716195996; 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=uISKL2l3A/kw68nYfY/vcC6+uwO13p2Wl0Fl+9foNfY=; b=DwjD2Oh92fzw8IMomqFlaw4oM3rkKyE+LnDQJhEaQC7+lPciPhLXfP9lnLnyENPTsMCrIU rZ+r5y2+fp7UOwjLqRk2hMcMPo2u86TiBY2uxksCBCBuicha/SMopVpfjQ/x387R1ddHDS rUV5K33VGK1tdJmsLKl5DRJ57YSeK1iTV7+jwFzK9fSY3Fxj9UZpv8zbVXLfza46UJunTd kk6NvE9McDnd6px6IccYd0uL0stLM/D7euoXchx/p1bRNNVxM5WDug6RujgMWhUl7VspBW yYh6ZhotJ7v8qdfkMFwFelOM8qCaNjWyRpkCICcbUGtlkZW090rgQDB22cX9Lw== From: Jonatan Schlag <jonatan.schlag@ipfire.org> To: development@lists.ipfire.org Subject: [PATCH 13/21] initscript fkt: ignore blank lines in readhash Date: Mon, 20 May 2024 11:06:03 +0200 Message-Id: <20240520090611.10406-14-jonatan.schlag@ipfire.org> In-Reply-To: <20240520090611.10406-1-jonatan.schlag@ipfire.org> References: <20240520090611.10406-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: EIG65NEJFURIB22DSFD6CHORST7NPUHK X-Message-ID-Hash: EIG65NEJFURIB22DSFD6CHORST7NPUHK 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 <development.lists.ipfire.org> Archived-At: <https://lists.ipfire.org/hyperkitty/list/development@lists.ipfire.org/message/EIG65NEJFURIB22DSFD6CHORST7NPUHK/> List-Archive: <https://lists.ipfire.org/hyperkitty/list/development@lists.ipfire.org/> List-Help: <mailto:development-request@lists.ipfire.org?subject=help> List-Owner: <mailto:development-owner@lists.ipfire.org> List-Post: <mailto:development@lists.ipfire.org> List-Subscribe: <mailto:development-join@lists.ipfire.org> List-Unsubscribe: <mailto:development-leave@lists.ipfire.org> |
Series |
[01/21] test: Add bash lib for colors
|
|
Commit Message
Jonatan Schlag
May 20, 2024, 9:06 a.m. UTC
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
---
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
Comments
> On 20 May 2024, at 10:06, Jonatan Schlag <jonatan.schlag@ipfire.org> wrote: > > Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org> > --- > 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#*=}" I don’t think this is quite sufficient. You might have other lines that are invalid. For example “=VALUE”. I think we should check that key isn’t empty, and we should limit what characters can be used in keys and values as it used to be before in the script. https://git.ipfire.org/?p=ipfire-2.x.git;a=blob;f=src/scripts/readhash;h=bffc93fbd00c31a76e9c96fc17dabf0a87c3c9ef;hb=HEAD > > 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 ec502e199..8d644b8cd 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_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" > -- > 2.39.2 >
Hi, Am Freitag, dem 31.05.2024 um 10:55 +0100 schrieb Michael Tremer: > > > > On 20 May 2024, at 10:06, Jonatan Schlag > > <jonatan.schlag@ipfire.org> wrote: > > > > Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org> > > --- > > 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#*=}" > > I don’t think this is quite sufficient. > > You might have other lines that are invalid. For example “=VALUE”. I > think we should check that key isn’t empty, and we should limit what > characters can be used in keys and values as it used to be before in > the script. > > https://git.ipfire.org/?p=ipfire-2.x.git;a=blob;f=src/scripts/readhash;h=bffc93fbd00c31a76e9c96fc17dabf0a87c3c9ef;hb=HEAD > Hi, I will merge all commits for checks in the next series. There are more checks to come. In a later commit, I check for correct values and keys. Jonatan > > > > 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 ec502e199..8d644b8cd 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_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" > > -- > > 2.39.2 > > >
Your tests I didn’t understand at all. You need to structure those in a more simple way. > On 2 Jun 2024, at 19:07, Jonatan Schlag <jonatan.schlag@ipfire.org> wrote: > > Hi, > > > Am Freitag, dem 31.05.2024 um 10:55 +0100 schrieb Michael Tremer: >> >> >>> On 20 May 2024, at 10:06, Jonatan Schlag >>> <jonatan.schlag@ipfire.org> wrote: >>> >>> Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org> >>> --- >>> 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#*=}" >> >> I don’t think this is quite sufficient. >> >> You might have other lines that are invalid. For example “=VALUE”. I >> think we should check that key isn’t empty, and we should limit what >> characters can be used in keys and values as it used to be before in >> the script. >> >> https://git.ipfire.org/?p=ipfire-2.x.git;a=blob;f=src/scripts/readhash;h=bffc93fbd00c31a76e9c96fc17dabf0a87c3c9ef;hb=HEAD >> > Hi, > > I will merge all commits for checks in the next series. There are more > checks to come. In a later commit, I check for correct values and keys. > > Jonatan >>> >>> 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 ec502e199..8d644b8cd 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_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" >>> -- >>> 2.39.2
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 ec502e199..8d644b8cd 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_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"