summaryrefslogtreecommitdiffstats
path: root/src/test/test-chase.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 03:50:45 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 03:50:45 +0000
commitefeb864cb547a2cbf96dc0053a8bdb4d9190b364 (patch)
treec0b83368f18be983fcc763200c4c24d633244588 /src/test/test-chase.c
parentReleasing progress-linux version 255.5-1~progress7.99u1. (diff)
downloadsystemd-efeb864cb547a2cbf96dc0053a8bdb4d9190b364.tar.xz
systemd-efeb864cb547a2cbf96dc0053a8bdb4d9190b364.zip
Merging upstream version 256.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/test-chase.c')
-rw-r--r--src/test/test-chase.c324
1 files changed, 165 insertions, 159 deletions
diff --git a/src/test/test-chase.c b/src/test/test-chase.c
index dbbc99b..13ee702 100644
--- a/src/test/test-chase.c
+++ b/src/test/test-chase.c
@@ -23,11 +23,11 @@ static void test_chase_extract_filename_one(const char *path, const char *root,
log_debug("/* %s(path=%s, root=%s) */", __func__, path, strnull(root));
assert_se(chase(path, root, CHASE_EXTRACT_FILENAME, &ret1, NULL) > 0);
- assert_se(streq(ret1, expected));
+ ASSERT_STREQ(ret1, expected);
assert_se(chase(path, root, 0, &ret2, NULL) > 0);
- assert_se(chase_extract_filename(ret2, root, &fname) >= 0);
- assert_se(streq(fname, expected));
+ ASSERT_OK(chase_extract_filename(ret2, root, &fname));
+ ASSERT_STREQ(fname, expected);
}
TEST(chase) {
@@ -42,7 +42,7 @@ TEST(chase) {
assert_se(mkdtemp(temp));
top = strjoina(temp, "/top");
- assert_se(mkdir(top, 0700) >= 0);
+ ASSERT_OK(mkdir(top, 0700));
p = strjoina(top, "/dot");
if (symlink(".", p) < 0) {
@@ -52,19 +52,19 @@ TEST(chase) {
};
p = strjoina(top, "/dotdot");
- assert_se(symlink("..", p) >= 0);
+ ASSERT_OK(symlink("..", p));
p = strjoina(top, "/dotdota");
- assert_se(symlink("../a", p) >= 0);
+ ASSERT_OK(symlink("../a", p));
p = strjoina(temp, "/a");
- assert_se(symlink("b", p) >= 0);
+ ASSERT_OK(symlink("b", p));
p = strjoina(temp, "/b");
- assert_se(symlink("/usr", p) >= 0);
+ ASSERT_OK(symlink("/usr", p));
p = strjoina(temp, "/start");
- assert_se(symlink("top/dot/dotdota", p) >= 0);
+ ASSERT_OK(symlink("top/dot/dotdota", p));
/* Paths that use symlinks underneath the "root" */
@@ -104,7 +104,7 @@ TEST(chase) {
assert_se(path_equal(result, qslash));
result = mfree(result);
- assert_se(mkdir(q, 0700) >= 0);
+ ASSERT_OK(mkdir(q, 0700));
r = chase(p, temp, 0, &result, NULL);
assert_se(r > 0);
@@ -145,21 +145,21 @@ TEST(chase) {
/* Paths that would "escape" outside of the "root" */
p = strjoina(temp, "/6dots");
- assert_se(symlink("../../..", p) >= 0);
+ ASSERT_OK(symlink("../../..", p));
r = chase(p, temp, 0, &result, NULL);
assert_se(r > 0 && path_equal(result, temp));
result = mfree(result);
p = strjoina(temp, "/6dotsusr");
- assert_se(symlink("../../../usr", p) >= 0);
+ ASSERT_OK(symlink("../../../usr", p));
r = chase(p, temp, 0, &result, NULL);
assert_se(r > 0 && path_equal(result, q));
result = mfree(result);
p = strjoina(temp, "/top/8dotsusr");
- assert_se(symlink("../../../../usr", p) >= 0);
+ ASSERT_OK(symlink("../../../../usr", p));
r = chase(p, temp, 0, &result, NULL);
assert_se(r > 0 && path_equal(result, q));
@@ -168,12 +168,12 @@ TEST(chase) {
/* Paths that contain repeated slashes */
p = strjoina(temp, "/slashslash");
- assert_se(symlink("///usr///", p) >= 0);
+ ASSERT_OK(symlink("///usr///", p));
r = chase(p, NULL, 0, &result, NULL);
assert_se(r > 0);
assert_se(path_equal(result, "/usr"));
- assert_se(streq(result, "/usr")); /* we guarantee that we drop redundant slashes */
+ ASSERT_STREQ(result, "/usr"); /* we guarantee that we drop redundant slashes */
result = mfree(result);
r = chase(p, temp, 0, &result, NULL);
@@ -185,14 +185,14 @@ TEST(chase) {
if (geteuid() == 0) {
p = strjoina(temp, "/user");
- assert_se(mkdir(p, 0755) >= 0);
- assert_se(chown(p, UID_NOBODY, GID_NOBODY) >= 0);
+ ASSERT_OK(mkdir(p, 0755));
+ ASSERT_OK(chown(p, UID_NOBODY, GID_NOBODY));
q = strjoina(temp, "/user/root");
- assert_se(mkdir(q, 0755) >= 0);
+ ASSERT_OK(mkdir(q, 0755));
p = strjoina(q, "/link");
- assert_se(symlink("/", p) >= 0);
+ ASSERT_OK(symlink("/", p));
/* Fail when user-owned directories contain root-owned subdirectories. */
r = chase(p, temp, CHASE_SAFE, &result, NULL);
@@ -218,22 +218,28 @@ TEST(chase) {
r = chase("/../.././//../../etc", NULL, 0, &result, NULL);
assert_se(r > 0);
- assert_se(streq(result, "/etc"));
+ ASSERT_STREQ(result, "/etc");
result = mfree(result);
r = chase("/../.././//../../test-chase.fsldajfl", NULL, CHASE_NONEXISTENT, &result, NULL);
assert_se(r == 0);
- assert_se(streq(result, "/test-chase.fsldajfl"));
+ ASSERT_STREQ(result, "/test-chase.fsldajfl");
result = mfree(result);
r = chase("/../.././//../../etc", "/", CHASE_PREFIX_ROOT, &result, NULL);
assert_se(r > 0);
- assert_se(streq(result, "/etc"));
+ ASSERT_STREQ(result, "/etc");
result = mfree(result);
r = chase("/../.././//../../test-chase.fsldajfl", "/", CHASE_PREFIX_ROOT|CHASE_NONEXISTENT, &result, NULL);
assert_se(r == 0);
- assert_se(streq(result, "/test-chase.fsldajfl"));
+ ASSERT_STREQ(result, "/test-chase.fsldajfl");
+ result = mfree(result);
+
+ r = chase("/.path/with/dot", temp, CHASE_PREFIX_ROOT|CHASE_NONEXISTENT, &result, NULL);
+ ASSERT_OK(r);
+ q = strjoina(temp, "/.path/with/dot");
+ ASSERT_STREQ(result, q);
result = mfree(result);
r = chase("/etc/machine-id/foo", NULL, 0, &result, NULL);
@@ -243,7 +249,7 @@ TEST(chase) {
/* Path that loops back to self */
p = strjoina(temp, "/recursive-symlink");
- assert_se(symlink("recursive-symlink", p) >= 0);
+ ASSERT_OK(symlink("recursive-symlink", p));
r = chase(p, NULL, 0, &result, NULL);
assert_se(r == -ELOOP);
@@ -269,9 +275,9 @@ TEST(chase) {
/* Relative paths */
- assert_se(safe_getcwd(&pwd) >= 0);
+ ASSERT_OK(safe_getcwd(&pwd));
- assert_se(chdir(temp) >= 0);
+ ASSERT_OK(chdir(temp));
p = "this/is/a/relative/path";
r = chase(p, NULL, CHASE_NONEXISTENT, &result, NULL);
@@ -309,46 +315,46 @@ TEST(chase) {
if (geteuid() == 0) {
p = strjoina(temp, "/priv1");
- assert_se(mkdir(p, 0755) >= 0);
+ ASSERT_OK(mkdir(p, 0755));
q = strjoina(p, "/priv2");
- assert_se(mkdir(q, 0755) >= 0);
+ ASSERT_OK(mkdir(q, 0755));
- assert_se(chase(q, NULL, CHASE_SAFE, NULL, NULL) >= 0);
+ ASSERT_OK(chase(q, NULL, CHASE_SAFE, NULL, NULL));
- assert_se(chown(q, UID_NOBODY, GID_NOBODY) >= 0);
- assert_se(chase(q, NULL, CHASE_SAFE, NULL, NULL) >= 0);
+ ASSERT_OK(chown(q, UID_NOBODY, GID_NOBODY));
+ ASSERT_OK(chase(q, NULL, CHASE_SAFE, NULL, NULL));
- assert_se(chown(p, UID_NOBODY, GID_NOBODY) >= 0);
- assert_se(chase(q, NULL, CHASE_SAFE, NULL, NULL) >= 0);
+ ASSERT_OK(chown(p, UID_NOBODY, GID_NOBODY));
+ ASSERT_OK(chase(q, NULL, CHASE_SAFE, NULL, NULL));
assert_se(chown(q, 0, 0) >= 0);
assert_se(chase(q, NULL, CHASE_SAFE, NULL, NULL) == -ENOLINK);
- assert_se(rmdir(q) >= 0);
- assert_se(symlink("/etc/passwd", q) >= 0);
+ ASSERT_OK(rmdir(q));
+ ASSERT_OK(symlink("/etc/passwd", q));
assert_se(chase(q, NULL, CHASE_SAFE, NULL, NULL) == -ENOLINK);
assert_se(chown(p, 0, 0) >= 0);
- assert_se(chase(q, NULL, CHASE_SAFE, NULL, NULL) >= 0);
+ ASSERT_OK(chase(q, NULL, CHASE_SAFE, NULL, NULL));
}
p = strjoina(temp, "/machine-id-test");
- assert_se(symlink("/usr/../etc/./machine-id", p) >= 0);
+ ASSERT_OK(symlink("/usr/../etc/./machine-id", p));
r = chase(p, NULL, 0, NULL, &pfd);
if (r != -ENOENT && sd_id128_get_machine(NULL) >= 0) {
_cleanup_close_ int fd = -EBADF;
sd_id128_t a, b;
- assert_se(pfd >= 0);
+ ASSERT_OK(pfd);
fd = fd_reopen(pfd, O_RDONLY|O_CLOEXEC);
- assert_se(fd >= 0);
+ ASSERT_OK(fd);
safe_close(pfd);
- assert_se(id128_read_fd(fd, ID128_FORMAT_PLAIN, &a) >= 0);
- assert_se(sd_id128_get_machine(&b) >= 0);
+ ASSERT_OK(id128_read_fd(fd, ID128_FORMAT_PLAIN, &a));
+ ASSERT_OK(sd_id128_get_machine(&b));
assert_se(sd_id128_equal(a, b));
}
@@ -365,24 +371,24 @@ TEST(chase) {
q = strjoina(temp, "/symlink");
assert_se(symlink(p, q) >= 0);
r = chase(q, NULL, CHASE_NOFOLLOW, &result, &pfd);
- assert_se(r >= 0);
- assert_se(pfd >= 0);
+ ASSERT_OK(r);
+ ASSERT_OK(pfd);
assert_se(path_equal(result, q));
- assert_se(fstat(pfd, &st) >= 0);
+ ASSERT_OK(fstat(pfd, &st));
assert_se(S_ISLNK(st.st_mode));
result = mfree(result);
pfd = safe_close(pfd);
/* s1 -> s2 -> nonexistent */
q = strjoina(temp, "/s1");
- assert_se(symlink("s2", q) >= 0);
+ ASSERT_OK(symlink("s2", q));
p = strjoina(temp, "/s2");
- assert_se(symlink("nonexistent", p) >= 0);
+ ASSERT_OK(symlink("nonexistent", p));
r = chase(q, NULL, CHASE_NOFOLLOW, &result, &pfd);
- assert_se(r >= 0);
- assert_se(pfd >= 0);
+ ASSERT_OK(r);
+ ASSERT_OK(pfd);
assert_se(path_equal(result, q));
- assert_se(fstat(pfd, &st) >= 0);
+ ASSERT_OK(fstat(pfd, &st));
assert_se(S_ISLNK(st.st_mode));
result = mfree(result);
pfd = safe_close(pfd);
@@ -393,41 +399,41 @@ TEST(chase) {
r = chase(p, NULL, CHASE_STEP, &result, NULL);
assert_se(r == 0);
p = strjoina(temp, "/top/dot/dotdota");
- assert_se(streq(p, result));
+ ASSERT_STREQ(p, result);
result = mfree(result);
r = chase(p, NULL, CHASE_STEP, &result, NULL);
assert_se(r == 0);
p = strjoina(temp, "/top/dotdota");
- assert_se(streq(p, result));
+ ASSERT_STREQ(p, result);
result = mfree(result);
r = chase(p, NULL, CHASE_STEP, &result, NULL);
assert_se(r == 0);
p = strjoina(temp, "/top/../a");
- assert_se(streq(p, result));
+ ASSERT_STREQ(p, result);
result = mfree(result);
r = chase(p, NULL, CHASE_STEP, &result, NULL);
assert_se(r == 0);
p = strjoina(temp, "/a");
- assert_se(streq(p, result));
+ ASSERT_STREQ(p, result);
result = mfree(result);
r = chase(p, NULL, CHASE_STEP, &result, NULL);
assert_se(r == 0);
p = strjoina(temp, "/b");
- assert_se(streq(p, result));
+ ASSERT_STREQ(p, result);
result = mfree(result);
r = chase(p, NULL, CHASE_STEP, &result, NULL);
assert_se(r == 0);
- assert_se(streq("/usr", result));
+ ASSERT_STREQ("/usr", result);
result = mfree(result);
r = chase("/usr", NULL, CHASE_STEP, &result, NULL);
assert_se(r > 0);
- assert_se(streq("/usr", result));
+ ASSERT_STREQ("/usr", result);
result = mfree(result);
/* Make sure that symlinks in the "root" path are not resolved, but those below are */
@@ -449,7 +455,7 @@ TEST(chase) {
assert_se(chase("top/dot/dot", temp, CHASE_PREFIX_ROOT|CHASE_PROHIBIT_SYMLINKS|CHASE_WARN, NULL, NULL) == -EREMCHG);
cleanup:
- assert_se(rm_rf(temp, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
+ ASSERT_OK(rm_rf(temp, REMOVE_ROOT|REMOVE_PHYSICAL));
}
TEST(chaseat) {
@@ -461,29 +467,29 @@ TEST(chaseat) {
struct stat st;
const char *p;
- assert_se((tfd = mkdtemp_open(NULL, 0, &t)) >= 0);
+ ASSERT_OK((tfd = mkdtemp_open(NULL, 0, &t)));
/* Test that AT_FDCWD with CHASE_AT_RESOLVE_IN_ROOT resolves against / and not the current working
* directory. */
- assert_se(symlinkat("/usr", tfd, "abc") >= 0);
+ ASSERT_OK(symlinkat("/usr", tfd, "abc"));
p = strjoina(t, "/abc");
- assert_se(chaseat(AT_FDCWD, p, CHASE_AT_RESOLVE_IN_ROOT, &result, NULL) >= 0);
- assert_se(streq(result, "/usr"));
+ ASSERT_OK(chaseat(AT_FDCWD, p, CHASE_AT_RESOLVE_IN_ROOT, &result, NULL));
+ ASSERT_STREQ(result, "/usr");
result = mfree(result);
/* If the file descriptor points to the root directory, the result will be absolute. */
fd = open("/", O_CLOEXEC | O_DIRECTORY | O_PATH);
- assert_se(fd >= 0);
+ ASSERT_OK(fd);
- assert_se(chaseat(fd, p, 0, &result, NULL) >= 0);
- assert_se(streq(result, "/usr"));
+ ASSERT_OK(chaseat(fd, p, 0, &result, NULL));
+ ASSERT_STREQ(result, "/usr");
result = mfree(result);
- assert_se(chaseat(fd, p, CHASE_AT_RESOLVE_IN_ROOT, &result, NULL) >= 0);
- assert_se(streq(result, "/usr"));
+ ASSERT_OK(chaseat(fd, p, CHASE_AT_RESOLVE_IN_ROOT, &result, NULL));
+ ASSERT_STREQ(result, "/usr");
result = mfree(result);
fd = safe_close(fd);
@@ -491,36 +497,36 @@ TEST(chaseat) {
/* If the file descriptor does not point to the root directory, the result will be relative
* unless the result is outside of the specified file descriptor. */
- assert_se(chaseat(tfd, "abc", 0, &result, NULL) >= 0);
- assert_se(streq(result, "/usr"));
+ ASSERT_OK(chaseat(tfd, "abc", 0, &result, NULL));
+ ASSERT_STREQ(result, "/usr");
result = mfree(result);
- assert_se(chaseat(tfd, "/abc", 0, &result, NULL) >= 0);
- assert_se(streq(result, "/usr"));
+ ASSERT_OK(chaseat(tfd, "/abc", 0, &result, NULL));
+ ASSERT_STREQ(result, "/usr");
result = mfree(result);
assert_se(chaseat(tfd, "abc", CHASE_AT_RESOLVE_IN_ROOT, NULL, NULL) == -ENOENT);
assert_se(chaseat(tfd, "/abc", CHASE_AT_RESOLVE_IN_ROOT, NULL, NULL) == -ENOENT);
- assert_se(chaseat(tfd, "abc", CHASE_AT_RESOLVE_IN_ROOT | CHASE_NONEXISTENT, &result, NULL) >= 0);
- assert_se(streq(result, "usr"));
+ ASSERT_OK(chaseat(tfd, "abc", CHASE_AT_RESOLVE_IN_ROOT | CHASE_NONEXISTENT, &result, NULL));
+ ASSERT_STREQ(result, "usr");
result = mfree(result);
- assert_se(chaseat(tfd, "/abc", CHASE_AT_RESOLVE_IN_ROOT | CHASE_NONEXISTENT, &result, NULL) >= 0);
- assert_se(streq(result, "usr"));
+ ASSERT_OK(chaseat(tfd, "/abc", CHASE_AT_RESOLVE_IN_ROOT | CHASE_NONEXISTENT, &result, NULL));
+ ASSERT_STREQ(result, "usr");
result = mfree(result);
/* Test that absolute path or not are the same when resolving relative to a directory file
* descriptor and that we always get a relative path back. */
- assert_se(fd = openat(tfd, "def", O_CREAT|O_CLOEXEC, 0700) >= 0);
+ ASSERT_OK(fd = openat(tfd, "def", O_CREAT|O_CLOEXEC, 0700));
fd = safe_close(fd);
- assert_se(symlinkat("/def", tfd, "qed") >= 0);
- assert_se(chaseat(tfd, "qed", CHASE_AT_RESOLVE_IN_ROOT, &result, NULL) >= 0);
- assert_se(streq(result, "def"));
+ ASSERT_OK(symlinkat("/def", tfd, "qed"));
+ ASSERT_OK(chaseat(tfd, "qed", CHASE_AT_RESOLVE_IN_ROOT, &result, NULL));
+ ASSERT_STREQ(result, "def");
result = mfree(result);
- assert_se(chaseat(tfd, "/qed", CHASE_AT_RESOLVE_IN_ROOT, &result, NULL) >= 0);
- assert_se(streq(result, "def"));
+ ASSERT_OK(chaseat(tfd, "/qed", CHASE_AT_RESOLVE_IN_ROOT, &result, NULL));
+ ASSERT_STREQ(result, "def");
result = mfree(result);
/* Valid directory file descriptor without CHASE_AT_RESOLVE_IN_ROOT should resolve symlinks against
@@ -529,157 +535,157 @@ TEST(chaseat) {
/* Test CHASE_PARENT */
- assert_se((fd = open_mkdir_at(tfd, "chase", O_CLOEXEC, 0755)) >= 0);
- assert_se(symlinkat("/def", fd, "parent") >= 0);
+ ASSERT_OK((fd = open_mkdir_at(tfd, "chase", O_CLOEXEC, 0755)));
+ ASSERT_OK(symlinkat("/def", fd, "parent"));
fd = safe_close(fd);
/* Make sure that when we chase a symlink parent directory, that we chase the parent directory of the
* symlink target and not the symlink itself. But if we add CHASE_NOFOLLOW, we get the parent
* directory of the symlink itself. */
- assert_se(chaseat(tfd, "chase/parent", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT, &result, &fd) >= 0);
- assert_se(faccessat(fd, "def", F_OK, 0) >= 0);
- assert_se(streq(result, "def"));
+ ASSERT_OK(chaseat(tfd, "chase/parent", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT, &result, &fd));
+ ASSERT_OK(faccessat(fd, "def", F_OK, 0));
+ ASSERT_STREQ(result, "def");
fd = safe_close(fd);
result = mfree(result);
- assert_se(chaseat(tfd, "chase/parent", CHASE_AT_RESOLVE_IN_ROOT|CHASE_PARENT|CHASE_NOFOLLOW, &result, &fd) >= 0);
- assert_se(faccessat(fd, "parent", F_OK, AT_SYMLINK_NOFOLLOW) >= 0);
- assert_se(streq(result, "chase/parent"));
+ ASSERT_OK(chaseat(tfd, "chase/parent", CHASE_AT_RESOLVE_IN_ROOT|CHASE_PARENT|CHASE_NOFOLLOW, &result, &fd));
+ ASSERT_OK(faccessat(fd, "parent", F_OK, AT_SYMLINK_NOFOLLOW));
+ ASSERT_STREQ(result, "chase/parent");
fd = safe_close(fd);
result = mfree(result);
- assert_se(chaseat(tfd, "chase", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT, &result, &fd) >= 0);
- assert_se(faccessat(fd, "chase", F_OK, 0) >= 0);
- assert_se(streq(result, "chase"));
+ ASSERT_OK(chaseat(tfd, "chase", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT, &result, &fd));
+ ASSERT_OK(faccessat(fd, "chase", F_OK, 0));
+ ASSERT_STREQ(result, "chase");
fd = safe_close(fd);
result = mfree(result);
- assert_se(chaseat(tfd, "/", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT, &result, NULL) >= 0);
- assert_se(streq(result, "."));
+ ASSERT_OK(chaseat(tfd, "/", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT, &result, NULL));
+ ASSERT_STREQ(result, ".");
result = mfree(result);
- assert_se(chaseat(tfd, ".", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT, &result, NULL) >= 0);
- assert_se(streq(result, "."));
+ assert_se(chaseat(tfd, ".", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT, &result, NULL));
+ ASSERT_STREQ(result, ".");
result = mfree(result);
/* Test CHASE_MKDIR_0755 */
- assert_se(chaseat(tfd, "m/k/d/i/r", CHASE_MKDIR_0755|CHASE_NONEXISTENT, &result, NULL) >= 0);
- assert_se(faccessat(tfd, "m/k/d/i", F_OK, 0) >= 0);
+ ASSERT_OK(chaseat(tfd, "m/k/d/i/r", CHASE_MKDIR_0755|CHASE_NONEXISTENT, &result, NULL));
+ ASSERT_OK(faccessat(tfd, "m/k/d/i", F_OK, 0));
assert_se(RET_NERRNO(faccessat(tfd, "m/k/d/i/r", F_OK, 0)) == -ENOENT);
- assert_se(streq(result, "m/k/d/i/r"));
+ ASSERT_STREQ(result, "m/k/d/i/r");
result = mfree(result);
- assert_se(chaseat(tfd, "m/../q", CHASE_MKDIR_0755|CHASE_NONEXISTENT, &result, NULL) >= 0);
- assert_se(faccessat(tfd, "m", F_OK, 0) >= 0);
+ ASSERT_OK(chaseat(tfd, "m/../q", CHASE_MKDIR_0755|CHASE_NONEXISTENT, &result, NULL));
+ ASSERT_OK(faccessat(tfd, "m", F_OK, 0));
assert_se(RET_NERRNO(faccessat(tfd, "q", F_OK, 0)) == -ENOENT);
- assert_se(streq(result, "q"));
+ ASSERT_STREQ(result, "q");
result = mfree(result);
assert_se(chaseat(tfd, "i/../p", CHASE_MKDIR_0755|CHASE_NONEXISTENT, NULL, NULL) == -ENOENT);
/* Test CHASE_EXTRACT_FILENAME */
- assert_se(chaseat(tfd, "chase/parent", CHASE_AT_RESOLVE_IN_ROOT|CHASE_PARENT|CHASE_NOFOLLOW|CHASE_EXTRACT_FILENAME, &result, &fd) >= 0);
- assert_se(faccessat(fd, result, F_OK, AT_SYMLINK_NOFOLLOW) >= 0);
- assert_se(streq(result, "parent"));
+ ASSERT_OK(chaseat(tfd, "chase/parent", CHASE_AT_RESOLVE_IN_ROOT|CHASE_PARENT|CHASE_NOFOLLOW|CHASE_EXTRACT_FILENAME, &result, &fd));
+ ASSERT_OK(faccessat(fd, result, F_OK, AT_SYMLINK_NOFOLLOW));
+ ASSERT_STREQ(result, "parent");
fd = safe_close(fd);
result = mfree(result);
- assert_se(chaseat(tfd, "chase", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT|CHASE_EXTRACT_FILENAME, &result, &fd) >= 0);
- assert_se(faccessat(fd, result, F_OK, 0) >= 0);
- assert_se(streq(result, "chase"));
+ ASSERT_OK(chaseat(tfd, "chase", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT|CHASE_EXTRACT_FILENAME, &result, &fd));
+ ASSERT_OK(faccessat(fd, result, F_OK, 0));
+ ASSERT_STREQ(result, "chase");
fd = safe_close(fd);
result = mfree(result);
- assert_se(chaseat(tfd, "/", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT|CHASE_EXTRACT_FILENAME, &result, NULL) >= 0);
- assert_se(streq(result, "."));
+ ASSERT_OK(chaseat(tfd, "/", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT|CHASE_EXTRACT_FILENAME, &result, NULL));
+ ASSERT_STREQ(result, ".");
result = mfree(result);
- assert_se(chaseat(tfd, ".", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT|CHASE_EXTRACT_FILENAME, &result, NULL) >= 0);
- assert_se(streq(result, "."));
+ ASSERT_OK(chaseat(tfd, ".", CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT|CHASE_EXTRACT_FILENAME, &result, NULL));
+ ASSERT_STREQ(result, ".");
result = mfree(result);
- assert_se(chaseat(tfd, NULL, CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT|CHASE_EXTRACT_FILENAME, &result, NULL) >= 0);
- assert_se(streq(result, "."));
+ ASSERT_OK(chaseat(tfd, NULL, CHASE_PARENT|CHASE_AT_RESOLVE_IN_ROOT|CHASE_EXTRACT_FILENAME, &result, NULL));
+ ASSERT_STREQ(result, ".");
result = mfree(result);
/* Test chase_and_openat() */
fd = chase_and_openat(tfd, "o/p/e/n/f/i/l/e", CHASE_MKDIR_0755, O_CREAT|O_EXCL|O_CLOEXEC, NULL);
- assert_se(fd >= 0);
- assert_se(fd_verify_regular(fd) >= 0);
+ ASSERT_OK(fd);
+ ASSERT_OK(fd_verify_regular(fd));
fd = safe_close(fd);
fd = chase_and_openat(tfd, "o/p/e/n/d/i/r", CHASE_MKDIR_0755, O_DIRECTORY|O_CREAT|O_EXCL|O_CLOEXEC, NULL);
- assert_se(fd >= 0);
- assert_se(fd_verify_directory(fd) >= 0);
+ ASSERT_OK(fd);
+ ASSERT_OK(fd_verify_directory(fd));
fd = safe_close(fd);
fd = chase_and_openat(tfd, NULL, CHASE_PARENT|CHASE_EXTRACT_FILENAME, O_PATH|O_DIRECTORY|O_CLOEXEC, &result);
- assert_se(fd >= 0);
- assert_se(streq(result, "."));
+ ASSERT_OK(fd);
+ ASSERT_STREQ(result, ".");
fd = safe_close(fd);
result = mfree(result);
/* Test chase_and_openatdir() */
- assert_se(chase_and_opendirat(tfd, "o/p/e/n/d/i", 0, &result, &dir) >= 0);
+ ASSERT_OK(chase_and_opendirat(tfd, "o/p/e/n/d/i", 0, &result, &dir));
FOREACH_DIRENT(de, dir, assert_not_reached())
- assert_se(streq(de->d_name, "r"));
- assert_se(streq(result, "o/p/e/n/d/i"));
+ ASSERT_STREQ(de->d_name, "r");
+ ASSERT_STREQ(result, "o/p/e/n/d/i");
result = mfree(result);
/* Test chase_and_statat() */
- assert_se(chase_and_statat(tfd, "o/p", 0, &result, &st) >= 0);
- assert_se(stat_verify_directory(&st) >= 0);
- assert_se(streq(result, "o/p"));
+ ASSERT_OK(chase_and_statat(tfd, "o/p", 0, &result, &st));
+ ASSERT_OK(stat_verify_directory(&st));
+ ASSERT_STREQ(result, "o/p");
result = mfree(result);
/* Test chase_and_accessat() */
- assert_se(chase_and_accessat(tfd, "o/p/e", 0, F_OK, &result) >= 0);
- assert_se(streq(result, "o/p/e"));
+ ASSERT_OK(chase_and_accessat(tfd, "o/p/e", 0, F_OK, &result));
+ ASSERT_STREQ(result, "o/p/e");
result = mfree(result);
/* Test chase_and_fopenat_unlocked() */
- assert_se(chase_and_fopenat_unlocked(tfd, "o/p/e/n/f/i/l/e", 0, "re", &result, &f) >= 0);
+ ASSERT_OK(chase_and_fopenat_unlocked(tfd, "o/p/e/n/f/i/l/e", 0, "re", &result, &f));
assert_se(fread(&(char[1]) {}, 1, 1, f) == 0);
assert_se(feof(f));
f = safe_fclose(f);
- assert_se(streq(result, "o/p/e/n/f/i/l/e"));
+ ASSERT_STREQ(result, "o/p/e/n/f/i/l/e");
result = mfree(result);
/* Test chase_and_unlinkat() */
- assert_se(chase_and_unlinkat(tfd, "o/p/e/n/f/i/l/e", 0, 0, &result) >= 0);
- assert_se(streq(result, "o/p/e/n/f/i/l/e"));
+ ASSERT_OK(chase_and_unlinkat(tfd, "o/p/e/n/f/i/l/e", 0, 0, &result));
+ ASSERT_STREQ(result, "o/p/e/n/f/i/l/e");
result = mfree(result);
/* Test chase_and_open_parent_at() */
- assert_se((fd = chase_and_open_parent_at(tfd, "chase/parent", CHASE_AT_RESOLVE_IN_ROOT|CHASE_NOFOLLOW, &result)) >= 0);
- assert_se(faccessat(fd, result, F_OK, AT_SYMLINK_NOFOLLOW) >= 0);
- assert_se(streq(result, "parent"));
+ ASSERT_OK((fd = chase_and_open_parent_at(tfd, "chase/parent", CHASE_AT_RESOLVE_IN_ROOT|CHASE_NOFOLLOW, &result)));
+ ASSERT_OK(faccessat(fd, result, F_OK, AT_SYMLINK_NOFOLLOW));
+ ASSERT_STREQ(result, "parent");
fd = safe_close(fd);
result = mfree(result);
- assert_se((fd = chase_and_open_parent_at(tfd, "chase", CHASE_AT_RESOLVE_IN_ROOT, &result)) >= 0);
- assert_se(faccessat(fd, result, F_OK, 0) >= 0);
- assert_se(streq(result, "chase"));
+ ASSERT_OK((fd = chase_and_open_parent_at(tfd, "chase", CHASE_AT_RESOLVE_IN_ROOT, &result)));
+ ASSERT_OK(faccessat(fd, result, F_OK, 0));
+ ASSERT_STREQ(result, "chase");
fd = safe_close(fd);
result = mfree(result);
- assert_se((fd = chase_and_open_parent_at(tfd, "/", CHASE_AT_RESOLVE_IN_ROOT, &result)) >= 0);
- assert_se(streq(result, "."));
+ ASSERT_OK((fd = chase_and_open_parent_at(tfd, "/", CHASE_AT_RESOLVE_IN_ROOT, &result)));
+ ASSERT_STREQ(result, ".");
fd = safe_close(fd);
result = mfree(result);
- assert_se((fd = chase_and_open_parent_at(tfd, ".", CHASE_AT_RESOLVE_IN_ROOT, &result)) >= 0);
- assert_se(streq(result, "."));
+ ASSERT_OK((fd = chase_and_open_parent_at(tfd, ".", CHASE_AT_RESOLVE_IN_ROOT, &result)));
+ ASSERT_STREQ(result, ".");
fd = safe_close(fd);
result = mfree(result);
}
@@ -687,47 +693,47 @@ TEST(chaseat) {
TEST(chaseat_prefix_root) {
_cleanup_free_ char *cwd = NULL, *ret = NULL, *expected = NULL;
- assert_se(safe_getcwd(&cwd) >= 0);
+ ASSERT_OK(safe_getcwd(&cwd));
- assert_se(chaseat_prefix_root("/hoge", NULL, &ret) >= 0);
- assert_se(streq(ret, "/hoge"));
+ ASSERT_OK(chaseat_prefix_root("/hoge", NULL, &ret));
+ ASSERT_STREQ(ret, "/hoge");
ret = mfree(ret);
- assert_se(chaseat_prefix_root("/hoge", "a/b/c", &ret) >= 0);
- assert_se(streq(ret, "/hoge"));
+ ASSERT_OK(chaseat_prefix_root("/hoge", "a/b/c", &ret));
+ ASSERT_STREQ(ret, "/hoge");
ret = mfree(ret);
- assert_se(chaseat_prefix_root("hoge", "/a/b//./c///", &ret) >= 0);
- assert_se(streq(ret, "/a/b/c/hoge"));
+ ASSERT_OK(chaseat_prefix_root("hoge", "/a/b//./c///", &ret));
+ ASSERT_STREQ(ret, "/a/b/c/hoge");
ret = mfree(ret);
- assert_se(chaseat_prefix_root("hoge", "a/b//./c///", &ret) >= 0);
+ ASSERT_OK(chaseat_prefix_root("hoge", "a/b//./c///", &ret));
assert_se(expected = path_join(cwd, "a/b/c/hoge"));
- assert_se(streq(ret, expected));
+ ASSERT_STREQ(ret, expected);
ret = mfree(ret);
expected = mfree(expected);
- assert_se(chaseat_prefix_root("./hoge/aaa/../././b", "/a/b//./c///", &ret) >= 0);
- assert_se(streq(ret, "/a/b/c/hoge/aaa/../././b"));
+ ASSERT_OK(chaseat_prefix_root("./hoge/aaa/../././b", "/a/b//./c///", &ret));
+ ASSERT_STREQ(ret, "/a/b/c/hoge/aaa/../././b");
ret = mfree(ret);
assert_se(chaseat_prefix_root("./hoge/aaa/../././b", "a/b//./c///", &ret) >= 0);
assert_se(expected = path_join(cwd, "a/b/c/hoge/aaa/../././b"));
- assert_se(streq(ret, expected));
+ ASSERT_STREQ(ret, expected);
}
TEST(trailing_dot_dot) {
_cleanup_free_ char *path = NULL, *fdpath = NULL;
_cleanup_close_ int fd = -EBADF;
- assert_se(chase("/usr/..", NULL, CHASE_PARENT, &path, &fd) >= 0);
+ ASSERT_OK(chase("/usr/..", NULL, CHASE_PARENT, &path, &fd));
assert_se(path_equal(path, "/"));
- assert_se(fd_get_path(fd, &fdpath) >= 0);
+ ASSERT_OK(fd_get_path(fd, &fdpath));
assert_se(path_equal(fdpath, "/"));
path = mfree(path);
@@ -735,16 +741,16 @@ TEST(trailing_dot_dot) {
fd = safe_close(fd);
_cleanup_(rm_rf_physical_and_freep) char *t = NULL;
- assert_se(mkdtemp_malloc(NULL, &t) >= 0);
+ ASSERT_OK(mkdtemp_malloc(NULL, &t));
_cleanup_free_ char *sub = ASSERT_PTR(path_join(t, "a/b/c/d"));
- assert_se(mkdir_p(sub, 0700) >= 0);
+ ASSERT_OK(mkdir_p(sub, 0700));
_cleanup_free_ char *suffixed = ASSERT_PTR(path_join(sub, ".."));
- assert_se(chase(suffixed, NULL, CHASE_PARENT, &path, &fd) >= 0);
+ ASSERT_OK(chase(suffixed, NULL, CHASE_PARENT, &path, &fd));
_cleanup_free_ char *expected1 = ASSERT_PTR(path_join(t, "a/b/c"));
_cleanup_free_ char *expected2 = ASSERT_PTR(path_join(t, "a/b"));
assert_se(path_equal(path, expected1));
- assert_se(fd_get_path(fd, &fdpath) >= 0);
+ ASSERT_OK(fd_get_path(fd, &fdpath));
assert_se(path_equal(fdpath, expected2));
}