summaryrefslogtreecommitdiff
path: root/src/test/test-user-util.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-02-20 17:13:41 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-02-21 09:57:35 +0100
commit7559b2da10b1513849f22312d09a2381569b4f06 (patch)
treea323f227d23a7014327d3361e15bcfbfc4ef795a /src/test/test-user-util.c
parent52c6e6a8a0221530659c65090f18b16c45a9fc04 (diff)
downloadsystemd-7559b2da10b1513849f22312d09a2381569b4f06.tar.gz
test-user-util: skip most tests for nobody if synthentization is off
When synthetisation is turned off, there's just too many ways those tests can go wrong. We are not interested in verifying that the db on disk is correct, let's just skip all checks. In the first version of this patch, I recorded if we detected a mismatch during configuration and only skipped tests in that case, but actually it is possible to change the host configuration between our configuration phase and running of the tests. It's just more robust to skip always. (This is particularly true if tests are installed.)
Diffstat (limited to 'src/test/test-user-util.c')
-rw-r--r--src/test/test-user-util.c40
1 files changed, 30 insertions, 10 deletions
diff --git a/src/test/test-user-util.c b/src/test/test-user-util.c
index 2af282d075..3a943bf10f 100644
--- a/src/test/test-user-util.c
+++ b/src/test/test-user-util.c
@@ -32,6 +32,10 @@ static void test_uid_to_name_one(uid_t uid, const char *name) {
log_info("/* %s("UID_FMT", \"%s\") */", __func__, uid, name);
assert_se(t = uid_to_name(uid));
+ if (!synthesize_nobody() && streq(name, NOBODY_USER_NAME)) {
+ log_info("(skipping detailed tests because nobody is not synthesized)");
+ return;
+ }
assert_se(streq_ptr(t, name));
}
@@ -41,6 +45,10 @@ static void test_gid_to_name_one(gid_t gid, const char *name) {
log_info("/* %s("GID_FMT", \"%s\") */", __func__, gid, name);
assert_se(t = gid_to_name(gid));
+ if (!synthesize_nobody() && streq(name, NOBODY_GROUP_NAME)) {
+ log_info("(skipping detailed tests because nobody is not synthesized)");
+ return;
+ }
assert_se(streq_ptr(t, name));
}
@@ -160,17 +168,23 @@ static void test_valid_home(void) {
}
static void test_get_user_creds_one(const char *id, const char *name, uid_t uid, gid_t gid, const char *home, const char *shell) {
- const char *rhome;
- const char *rshell;
- uid_t ruid;
- gid_t rgid;
+ const char *rhome = NULL;
+ const char *rshell = NULL;
+ uid_t ruid = UID_INVALID;
+ gid_t rgid = GID_INVALID;
+ int r;
log_info("/* %s(\"%s\", \"%s\", "UID_FMT", "GID_FMT", \"%s\", \"%s\") */",
__func__, id, name, uid, gid, home, shell);
- assert_se(get_user_creds(&id, &ruid, &rgid, &rhome, &rshell) >= 0);
- log_info("got \"%s\", "UID_FMT", "GID_FMT", \"%s\", \"%s\"",
- id, ruid, rgid, rhome, rshell);
+ r = get_user_creds(&id, &ruid, &rgid, &rhome, &rshell);
+ log_info_errno(r, "got \"%s\", "UID_FMT", "GID_FMT", \"%s\", \"%s\": %m",
+ id, ruid, rgid, strnull(rhome), strnull(rshell));
+ if (!synthesize_nobody() && streq(name, NOBODY_USER_NAME)) {
+ log_info("(skipping detailed tests because nobody is not synthesized)");
+ return;
+ }
+ assert_se(r == 0);
assert_se(streq_ptr(id, name));
assert_se(ruid == uid);
assert_se(rgid == gid);
@@ -179,12 +193,18 @@ static void test_get_user_creds_one(const char *id, const char *name, uid_t uid,
}
static void test_get_group_creds_one(const char *id, const char *name, gid_t gid) {
- gid_t rgid;
+ gid_t rgid = GID_INVALID;
+ int r;
log_info("/* %s(\"%s\", \"%s\", "GID_FMT") */", __func__, id, name, gid);
- assert_se(get_group_creds(&id, &rgid) >= 0);
- log_info("got \"%s\", "GID_FMT, id, rgid);
+ r = get_group_creds(&id, &rgid);
+ log_info_errno(r, "got \"%s\", "GID_FMT": %m", id, rgid);
+ if (!synthesize_nobody() && streq(name, NOBODY_GROUP_NAME)) {
+ log_info("(skipping detailed tests because nobody is not synthesized)");
+ return;
+ }
+ assert_se(r == 0);
assert_se(streq_ptr(id, name));
assert_se(rgid == gid);
}