diff options
author | Davide Cavalca <davide125@tiscali.it> | 2018-10-13 01:26:48 -0700 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-10-13 17:26:48 +0900 |
commit | b75f0c69b3c80ab1d80f907de96f1c1a444c171a (patch) | |
tree | c2320b5e58c405c571b9ddd565d52d134501cc6c /src/test | |
parent | b4b3649a94fbb8833f946a3dae5c6ee1137cb1a9 (diff) | |
download | systemd-b75f0c69b3c80ab1d80f907de96f1c1a444c171a.tar.gz systemd-b75f0c69b3c80ab1d80f907de96f1c1a444c171a.tar.bz2 systemd-b75f0c69b3c80ab1d80f907de96f1c1a444c171a.zip |
shared: add %g, %G specifiers for group / gid (#10368)
Diffstat (limited to 'src/test')
-rwxr-xr-x | src/test/test-systemd-tmpfiles.py | 9 | ||||
-rw-r--r-- | src/test/test-unit-file.c | 12 | ||||
-rw-r--r-- | src/test/test-unit-name.c | 8 |
3 files changed, 25 insertions, 4 deletions
diff --git a/src/test/test-systemd-tmpfiles.py b/src/test/test-systemd-tmpfiles.py index 13a44f3c4a..28dadd0c5b 100755 --- a/src/test/test-systemd-tmpfiles.py +++ b/src/test/test-systemd-tmpfiles.py @@ -12,6 +12,7 @@ import socket import subprocess import tempfile import pwd +import grp try: from systemd import id128 @@ -95,9 +96,13 @@ def test_valid_specifiers(*, user): test_content('f {} - - - - %H', '{}'.format(socket.gethostname()), user=user) test_content('f {} - - - - %v', '{}'.format(os.uname().release), user=user) test_content('f {} - - - - %U', '{}'.format(os.getuid()), user=user) + test_content('f {} - - - - %G', '{}'.format(os.getgid()), user=user) - user = pwd.getpwuid(os.getuid()) - test_content('f {} - - - - %u', '{}'.format(user.pw_name), user=user) + puser = pwd.getpwuid(os.getuid()) + test_content('f {} - - - - %u', '{}'.format(puser.pw_name), user=user) + + pgroup = grp.getgrgid(os.getgid()) + test_content('f {} - - - - %g', '{}'.format(pgroup.gr_name), user=user) # Note that %h is the only specifier in which we look the environment, # because we check $HOME. Should we even be doing that? diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c index cb074aaa4d..fe6da4fe2d 100644 --- a/src/test/test-unit-file.c +++ b/src/test/test-unit-file.c @@ -621,11 +621,13 @@ static void test_install_printf(void) { UnitFileInstallInfo i3 = { .name = name3, .path = path3, }; UnitFileInstallInfo i4 = { .name = name3, .path = path3, }; - _cleanup_free_ char *mid = NULL, *bid = NULL, *host = NULL, *uid = NULL, *user = NULL; + _cleanup_free_ char *mid = NULL, *bid = NULL, *host = NULL, *gid = NULL, *group = NULL, *uid = NULL, *user = NULL; assert_se(specifier_machine_id('m', NULL, NULL, &mid) >= 0 && mid); assert_se(specifier_boot_id('b', NULL, NULL, &bid) >= 0 && bid); assert_se(host = gethostname_malloc()); + assert_se(group = gid_to_name(getgid())); + assert_se(asprintf(&gid, UID_FMT, getgid()) >= 0); assert_se(user = uid_to_name(getuid())); assert_se(asprintf(&uid, UID_FMT, getuid()) >= 0); @@ -652,6 +654,8 @@ static void test_install_printf(void) { expect(i, "%p", "name"); expect(i, "%i", ""); expect(i, "%j", "name"); + expect(i, "%g", group); + expect(i, "%G", gid); expect(i, "%u", user); expect(i, "%U", uid); @@ -659,12 +663,16 @@ static void test_install_printf(void) { expect(i, "%b", bid); expect(i, "%H", host); + expect(i2, "%g", group); + expect(i2, "%G", gid); expect(i2, "%u", user); expect(i2, "%U", uid); expect(i3, "%n", "name@inst.service"); expect(i3, "%N", "name@inst"); expect(i3, "%p", "name"); + expect(i3, "%g", group); + expect(i3, "%G", gid); expect(i3, "%u", user); expect(i3, "%U", uid); @@ -672,6 +680,8 @@ static void test_install_printf(void) { expect(i3, "%b", bid); expect(i3, "%H", host); + expect(i4, "%g", group); + expect(i4, "%G", gid); expect(i4, "%u", user); expect(i4, "%U", uid); } diff --git a/src/test/test-unit-name.c b/src/test/test-unit-name.c index 157c900276..0d3674cff8 100644 --- a/src/test/test-unit-name.c +++ b/src/test/test-unit-name.c @@ -191,7 +191,7 @@ static void test_unit_name_mangle(void) { } static int test_unit_printf(void) { - _cleanup_free_ char *mid = NULL, *bid = NULL, *host = NULL, *uid = NULL, *user = NULL, *shell = NULL, *home = NULL; + _cleanup_free_ char *mid = NULL, *bid = NULL, *host = NULL, *gid = NULL, *group = NULL, *uid = NULL, *user = NULL, *shell = NULL, *home = NULL; _cleanup_(manager_freep) Manager *m = NULL; Unit *u; int r; @@ -200,7 +200,9 @@ static int test_unit_printf(void) { assert_se(specifier_boot_id('b', NULL, NULL, &bid) >= 0 && bid); assert_se(host = gethostname_malloc()); assert_se(user = uid_to_name(getuid())); + assert_se(group = gid_to_name(getgid())); assert_se(asprintf(&uid, UID_FMT, getuid())); + assert_se(asprintf(&gid, UID_FMT, getgid())); assert_se(get_home_dir(&home) >= 0); assert_se(get_shell(&shell) >= 0); @@ -241,6 +243,8 @@ static int test_unit_printf(void) { expect(u, "%I", ""); expect(u, "%j", "blah"); expect(u, "%J", "blah"); + expect(u, "%g", group); + expect(u, "%G", gid); expect(u, "%u", user); expect(u, "%U", uid); expect(u, "%h", home); @@ -263,6 +267,8 @@ static int test_unit_printf(void) { expect(u, "%I", "foo/foo"); expect(u, "%j", "blah"); expect(u, "%J", "blah"); + expect(u, "%g", group); + expect(u, "%G", gid); expect(u, "%u", user); expect(u, "%U", uid); expect(u, "%h", home); |