Skip to content

Commit

Permalink
test: accept additional supplementary groups in matches
Browse files Browse the repository at this point in the history
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 systemd#9881.
  • Loading branch information
filbranden committed Sep 12, 2018
1 parent 87ead8e commit f398a93
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 9 deletions.
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/test-execute/exec-dynamicuser-fixeduser.service
Expand Up @@ -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
Expand Up @@ -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
Expand Up @@ -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
Expand Up @@ -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
Expand Up @@ -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
Expand Up @@ -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
Expand Down
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/test-execute/exec-supplementarygroups.service
Expand Up @@ -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

0 comments on commit f398a93

Please sign in to comment.