From f398a93acfb6353762a636494783bea5b0bf4136 Mon Sep 17 00:00:00 2001 From: Filipe Brandenburger Date: Wed, 12 Sep 2018 09:22:28 -0700 Subject: [PATCH] test: accept additional supplementary groups in matches If /etc/group is set up in a way that additional groups will be used for the test users, accept that `id -G` will return them in addition to the supplementary groups configured in the unit. For example, in Arch Linux user with uid 1 is in these groups by default: $ id 1 uid=1(bin) gid=1(bin) groups=1(bin),2(daemon),3(sys) Tested: by adding my "bin" user to groups "daemon" and "sys" and running the test cases with `ninja -C build/ test`. Also works without the additional groups. Fixes #9881. --- .../exec-dynamicuser-fixeduser-one-supplementarygroup.service | 2 +- test/test-execute/exec-dynamicuser-fixeduser.service | 2 +- test/test-execute/exec-dynamicuser-supplementarygroups.service | 2 +- ...pplementarygroups-multiple-groups-default-group-user.service | 2 +- .../exec-supplementarygroups-multiple-groups-withgid.service | 2 +- .../exec-supplementarygroups-multiple-groups-withuid.service | 2 +- .../exec-supplementarygroups-single-group-user.service | 2 +- test/test-execute/exec-supplementarygroups-single-group.service | 2 +- test/test-execute/exec-supplementarygroups.service | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/test-execute/exec-dynamicuser-fixeduser-one-supplementarygroup.service b/test/test-execute/exec-dynamicuser-fixeduser-one-supplementarygroup.service index de1a6e73035df..b98fb551c5d51 100644 --- a/test/test-execute/exec-dynamicuser-fixeduser-one-supplementarygroup.service +++ b/test/test-execute/exec-dynamicuser-fixeduser-one-supplementarygroup.service @@ -2,7 +2,7 @@ Description=Test DynamicUser with User= and SupplementaryGroups= [Service] -ExecStart=/bin/sh -x -c 'test "$$(id -G)" = "1" && test "$$(id -g)" = "1" && test "$$(id -u)" = "1"' +ExecStart=/bin/sh -x -c 'test " $$(id -G) " = *" 1 "* && test "$$(id -g)" = "1" && test "$$(id -u)" = "1"' Type=oneshot User=1 DynamicUser=yes diff --git a/test/test-execute/exec-dynamicuser-fixeduser.service b/test/test-execute/exec-dynamicuser-fixeduser.service index 1d84af02ed808..aa6871b2f4d4e 100644 --- a/test/test-execute/exec-dynamicuser-fixeduser.service +++ b/test/test-execute/exec-dynamicuser-fixeduser.service @@ -2,7 +2,7 @@ Description=Test DynamicUser with User= [Service] -ExecStart=/bin/sh -x -c 'test "$$(id -G)" = "1" && test "$$(id -g)" = "1" && test "$$(id -u)" = "1"' +ExecStart=/bin/sh -x -c 'test " $$(id -G) " = *" 1 "* && test "$$(id -g)" = "1" && test "$$(id -u)" = "1"' Type=oneshot User=1 DynamicUser=yes diff --git a/test/test-execute/exec-dynamicuser-supplementarygroups.service b/test/test-execute/exec-dynamicuser-supplementarygroups.service index a47b7fab78166..e07fee55dd111 100644 --- a/test/test-execute/exec-dynamicuser-supplementarygroups.service +++ b/test/test-execute/exec-dynamicuser-supplementarygroups.service @@ -2,7 +2,7 @@ Description=Test DynamicUser with SupplementaryGroups= [Service] -ExecStart=/bin/sh -x -c 'test "$$(id -G | cut -d " " --complement -f 1)" = "1 2 3"' +ExecStart=/bin/sh -x -c 'test " $$(id -G) " = *" 1 2 3 "*' Type=oneshot DynamicUser=yes SupplementaryGroups=1 2 3 diff --git a/test/test-execute/exec-supplementarygroups-multiple-groups-default-group-user.service b/test/test-execute/exec-supplementarygroups-multiple-groups-default-group-user.service index a49c9d26a11b9..9c96201bfbcb7 100644 --- a/test/test-execute/exec-supplementarygroups-multiple-groups-default-group-user.service +++ b/test/test-execute/exec-supplementarygroups-multiple-groups-default-group-user.service @@ -2,6 +2,6 @@ Description=Test for Supplementary Group with multiple groups without Group and User [Service] -ExecStart=/bin/sh -x -c 'test "$$(id -G)" = "0 1 2 3" && test "$$(id -g)" = "0" && test "$$(id -u)" = "0"' +ExecStart=/bin/sh -x -c 'test " $$(id -G) " = *" 0 1 2 3 "* && test "$$(id -g)" = "0" && test "$$(id -u)" = "0"' Type=oneshot SupplementaryGroups=1 2 3 diff --git a/test/test-execute/exec-supplementarygroups-multiple-groups-withgid.service b/test/test-execute/exec-supplementarygroups-multiple-groups-withgid.service index 5c62c1d63918b..7731bf28494db 100644 --- a/test/test-execute/exec-supplementarygroups-multiple-groups-withgid.service +++ b/test/test-execute/exec-supplementarygroups-multiple-groups-withgid.service @@ -2,7 +2,7 @@ Description=Test for Supplementary Group with multiple groups and Group=1 [Service] -ExecStart=/bin/sh -x -c 'test "$$(id -G)" = "1 2 3" && test "$$(id -g)" = "1" && test "$$(id -u)" = "0"' +ExecStart=/bin/sh -x -c 'test " $$(id -G) " = *" 1 2 3 "* && test "$$(id -g)" = "1" && test "$$(id -u)" = "0"' Type=oneshot Group=1 SupplementaryGroups=1 2 3 diff --git a/test/test-execute/exec-supplementarygroups-multiple-groups-withuid.service b/test/test-execute/exec-supplementarygroups-multiple-groups-withuid.service index 00523e383b307..bac61b8303776 100644 --- a/test/test-execute/exec-supplementarygroups-multiple-groups-withuid.service +++ b/test/test-execute/exec-supplementarygroups-multiple-groups-withuid.service @@ -2,7 +2,7 @@ Description=Test for Supplementary Group with multiple groups and Uid=1 [Service] -ExecStart=/bin/sh -x -c 'test "$$(id -G)" = "1 2 3" && test "$$(id -g)" = "1" && test "$$(id -u)" = "1"' +ExecStart=/bin/sh -x -c 'test " $$(id -G) " = *" 1 2 3 "* && test "$$(id -g)" = "1" && test "$$(id -u)" = "1"' Type=oneshot User=1 SupplementaryGroups=1 2 3 diff --git a/test/test-execute/exec-supplementarygroups-single-group-user.service b/test/test-execute/exec-supplementarygroups-single-group-user.service index ed6276d3036f1..9f822602ae2cb 100644 --- a/test/test-execute/exec-supplementarygroups-single-group-user.service +++ b/test/test-execute/exec-supplementarygroups-single-group-user.service @@ -2,7 +2,7 @@ Description=Test for Supplementary Group with only one group and uid 1 [Service] -ExecStart=/bin/sh -x -c 'test "$$(id -G)" = "1" && test "$$(id -g)" = "1" && test "$$(id -u)" = "1"' +ExecStart=/bin/sh -x -c 'test " $$(id -G) " = *" 1 "* && test "$$(id -g)" = "1" && test "$$(id -u)" = "1"' Type=oneshot User=1 Group=1 diff --git a/test/test-execute/exec-supplementarygroups-single-group.service b/test/test-execute/exec-supplementarygroups-single-group.service index ee502b3d3773d..a34301caef24c 100644 --- a/test/test-execute/exec-supplementarygroups-single-group.service +++ b/test/test-execute/exec-supplementarygroups-single-group.service @@ -2,7 +2,7 @@ Description=Test for Supplementary Group with only one group [Service] -ExecStart=/bin/sh -x -c 'test "$$(id -G)" = "1" && test "$$(id -g)" = "1" && test "$$(id -u)" = "0"' +ExecStart=/bin/sh -x -c 'test " $$(id -G) " = *" 1 "* && test "$$(id -g)" = "1" && test "$$(id -u)" = "0"' Type=oneshot Group=1 SupplementaryGroups=1 diff --git a/test/test-execute/exec-supplementarygroups.service b/test/test-execute/exec-supplementarygroups.service index 43a9a981f2436..9ecf344ef9fae 100644 --- a/test/test-execute/exec-supplementarygroups.service +++ b/test/test-execute/exec-supplementarygroups.service @@ -2,6 +2,6 @@ Description=Test for Supplementary Group [Service] -ExecStart=/bin/sh -x -c 'test "$$(id -G)" = "0 1"' +ExecStart=/bin/sh -x -c 'test " $$(id -G) " = *" 0 1 "*' Type=oneshot SupplementaryGroups=1