Mike Frysinger | 50e31fa | 2018-01-19 18:59:49 -0500 | [diff] [blame] | 1 | /* Copyright 2017 The Chromium OS Authors. All rights reserved. |
| 2 | * Use of this source code is governed by a BSD-style license that can be |
| 3 | * found in the LICENSE file. |
| 4 | * |
| 5 | * Test system.[ch] module code using gtest. |
| 6 | */ |
Mike Frysinger | 0b5cffa | 2017-08-15 18:06:18 -0400 | [diff] [blame] | 7 | |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 8 | #include <ftw.h> |
yusukes | 76a9d74 | 2018-03-05 10:20:22 -0800 | [diff] [blame] | 9 | #include <limits.h> |
Jorge Lucangeli Obes | 5423421 | 2018-04-26 11:52:15 -0400 | [diff] [blame] | 10 | #include <linux/securebits.h> |
Mike Frysinger | 0b5cffa | 2017-08-15 18:06:18 -0400 | [diff] [blame] | 11 | #include <stdio.h> |
| 12 | #include <stdlib.h> |
| 13 | #include <string.h> |
Mike Frysinger | 5fdba4e | 2018-01-17 15:39:48 -0500 | [diff] [blame] | 14 | #include <sys/stat.h> |
Luis Hector Chavez | 0bacbf8 | 2018-07-10 20:06:55 -0700 | [diff] [blame] | 15 | #include <sys/statvfs.h> |
Mike Frysinger | 0b5cffa | 2017-08-15 18:06:18 -0400 | [diff] [blame] | 16 | #include <unistd.h> |
| 17 | |
| 18 | #include <gtest/gtest.h> |
| 19 | |
Luis Hector Chavez | 6bdebb0 | 2018-07-10 19:31:27 -0700 | [diff] [blame] | 20 | #include <string> |
| 21 | |
Mike Frysinger | 0b5cffa | 2017-08-15 18:06:18 -0400 | [diff] [blame] | 22 | #include "system.h" |
Jorge Lucangeli Obes | 22388b9 | 2022-07-13 14:34:47 -0400 | [diff] [blame] | 23 | #include "unittest_util.h" |
Mike Frysinger | 0b5cffa | 2017-08-15 18:06:18 -0400 | [diff] [blame] | 24 | |
| 25 | namespace { |
| 26 | |
| 27 | // A random path that really really should not exist on the host. |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 28 | constexpr const char kNoSuchDir[] = "/.x/..x/...x/path/should/not/exist/"; |
Mike Frysinger | 0b5cffa | 2017-08-15 18:06:18 -0400 | [diff] [blame] | 29 | |
Jorge Lucangeli Obes | 1fc0518 | 2018-04-05 10:17:01 -0400 | [diff] [blame] | 30 | // A random file that should exist on both Linux and Android. |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 31 | constexpr const char kValidFile[] = "/etc/hosts"; |
Mike Frysinger | eaab420 | 2017-08-14 14:57:21 -0400 | [diff] [blame] | 32 | |
| 33 | // A random directory that should exist. |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 34 | constexpr const char kValidDir[] = "/"; |
Mike Frysinger | eaab420 | 2017-08-14 14:57:21 -0400 | [diff] [blame] | 35 | |
| 36 | // A random character device that should exist. |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 37 | constexpr const char kValidCharDev[] = "/dev/null"; |
Mike Frysinger | eaab420 | 2017-08-14 14:57:21 -0400 | [diff] [blame] | 38 | |
Mike Frysinger | 0b5cffa | 2017-08-15 18:06:18 -0400 | [diff] [blame] | 39 | } // namespace |
| 40 | |
Jorge Lucangeli Obes | 5423421 | 2018-04-26 11:52:15 -0400 | [diff] [blame] | 41 | TEST(secure_noroot_set_and_locked, zero_mask) { |
| 42 | ASSERT_EQ(secure_noroot_set_and_locked(0), 0); |
| 43 | } |
| 44 | |
| 45 | TEST(secure_noroot_set_and_locked, set) { |
| 46 | ASSERT_EQ(secure_noroot_set_and_locked(issecure_mask(SECURE_NOROOT) | |
| 47 | issecure_mask(SECURE_NOROOT_LOCKED)), |
| 48 | 1); |
| 49 | } |
| 50 | |
| 51 | TEST(secure_noroot_set_and_locked, not_set) { |
| 52 | ASSERT_EQ(secure_noroot_set_and_locked(issecure_mask(SECURE_KEEP_CAPS) | |
| 53 | issecure_mask(SECURE_NOROOT_LOCKED)), |
| 54 | 0); |
| 55 | } |
| 56 | |
Mike Frysinger | 0b5cffa | 2017-08-15 18:06:18 -0400 | [diff] [blame] | 57 | // Sanity check for the cap range. |
| 58 | TEST(get_last_valid_cap, basic) { |
| 59 | unsigned int cap = get_last_valid_cap(); |
| 60 | |
| 61 | // We pick 35 as it's been that since at least v3.0. |
| 62 | // If this test is run on older kernels, it might fail. |
| 63 | EXPECT_GE(cap, 35u); |
| 64 | |
| 65 | // Pick a really large number that we probably won't hit for a long time. |
| 66 | // It helps that caps are bitfields. |
| 67 | EXPECT_LT(cap, 128u); |
| 68 | } |
| 69 | |
| 70 | // Might be useful to figure out the return value, but for now, |
| 71 | // just make sure it doesn't crash? |
| 72 | TEST(cap_ambient_supported, smoke) { |
| 73 | cap_ambient_supported(); |
| 74 | } |
| 75 | |
Mike Frysinger | 0b5cffa | 2017-08-15 18:06:18 -0400 | [diff] [blame] | 76 | // An invalid path should return an error. |
| 77 | TEST(write_pid_to_path, bad_path) { |
| 78 | EXPECT_NE(0, write_pid_to_path(0, kNoSuchDir)); |
| 79 | } |
| 80 | |
| 81 | // Make sure we can write a pid to the file. |
| 82 | TEST(write_pid_to_path, basic) { |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 83 | TemporaryFile tmp; |
| 84 | ASSERT_TRUE(tmp.is_valid()); |
Mike Frysinger | 0b5cffa | 2017-08-15 18:06:18 -0400 | [diff] [blame] | 85 | |
Jorge Lucangeli Obes | 1f5d095 | 2019-06-04 09:18:26 -0400 | [diff] [blame] | 86 | EXPECT_EQ(0, write_pid_to_path(1234, tmp.path.c_str())); |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 87 | FILE *fp = fopen(tmp.path.c_str(), "re"); |
Mike Frysinger | 0b5cffa | 2017-08-15 18:06:18 -0400 | [diff] [blame] | 88 | EXPECT_NE(nullptr, fp); |
lhchavez | 24b64c2 | 2017-09-01 03:52:13 +0000 | [diff] [blame] | 89 | char data[6] = {}; |
Mike Frysinger | 0b5cffa | 2017-08-15 18:06:18 -0400 | [diff] [blame] | 90 | EXPECT_EQ(5u, fread(data, 1, sizeof(data), fp)); |
| 91 | fclose(fp); |
Mike Frysinger | 22dc352 | 2022-07-07 19:24:13 -0400 | [diff] [blame] | 92 | EXPECT_STREQ(data, "1234\n"); |
Mike Frysinger | eaab420 | 2017-08-14 14:57:21 -0400 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | // If the destination exists, there's nothing to do. |
Mike Frysinger | 5fdba4e | 2018-01-17 15:39:48 -0500 | [diff] [blame] | 96 | // Also check trailing slash handling. |
| 97 | TEST(mkdir_p, dest_exists) { |
| 98 | EXPECT_EQ(0, mkdir_p("/", 0, true)); |
| 99 | EXPECT_EQ(0, mkdir_p("///", 0, true)); |
| 100 | EXPECT_EQ(0, mkdir_p("/proc", 0, true)); |
| 101 | EXPECT_EQ(0, mkdir_p("/proc/", 0, true)); |
| 102 | EXPECT_EQ(0, mkdir_p("/dev", 0, true)); |
| 103 | EXPECT_EQ(0, mkdir_p("/dev/", 0, true)); |
| 104 | } |
| 105 | |
| 106 | // Create a directory tree that doesn't exist. |
| 107 | TEST(mkdir_p, create_tree) { |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 108 | TemporaryDir dir; |
| 109 | ASSERT_TRUE(dir.is_valid()); |
Mike Frysinger | 5fdba4e | 2018-01-17 15:39:48 -0500 | [diff] [blame] | 110 | |
| 111 | // Run `mkdir -p <path>/a/b/c`. |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 112 | std::string path_a = dir.path + "/a"; |
| 113 | std::string path_a_b = path_a + "/b"; |
| 114 | std::string path_a_b_c = path_a_b + "/c"; |
Mike Frysinger | 5fdba4e | 2018-01-17 15:39:48 -0500 | [diff] [blame] | 115 | |
| 116 | // First try creating it as a file. |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 117 | EXPECT_EQ(0, mkdir_p(path_a_b_c.c_str(), 0700, false)); |
Mike Frysinger | 5fdba4e | 2018-01-17 15:39:48 -0500 | [diff] [blame] | 118 | |
| 119 | // Make sure the final path doesn't exist yet. |
| 120 | struct stat st; |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 121 | EXPECT_EQ(0, stat(path_a_b.c_str(), &st)); |
Mike Frysinger | 5fdba4e | 2018-01-17 15:39:48 -0500 | [diff] [blame] | 122 | EXPECT_EQ(true, S_ISDIR(st.st_mode)); |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 123 | EXPECT_EQ(-1, stat(path_a_b_c.c_str(), &st)); |
Mike Frysinger | 5fdba4e | 2018-01-17 15:39:48 -0500 | [diff] [blame] | 124 | |
| 125 | // Then create it as a complete dir. |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 126 | EXPECT_EQ(0, mkdir_p(path_a_b_c.c_str(), 0700, true)); |
Mike Frysinger | 5fdba4e | 2018-01-17 15:39:48 -0500 | [diff] [blame] | 127 | |
| 128 | // Make sure the final dir actually exists. |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 129 | EXPECT_EQ(0, stat(path_a_b_c.c_str(), &st)); |
Mike Frysinger | 5fdba4e | 2018-01-17 15:39:48 -0500 | [diff] [blame] | 130 | EXPECT_EQ(true, S_ISDIR(st.st_mode)); |
Mike Frysinger | 5fdba4e | 2018-01-17 15:39:48 -0500 | [diff] [blame] | 131 | } |
| 132 | |
Jorge Lucangeli Obes | 3ce72e0 | 2022-06-07 19:41:11 -0400 | [diff] [blame] | 133 | // Return success on NULL pointer. |
| 134 | TEST(get_mount_flags, null_ptr) { |
| 135 | ASSERT_EQ(0, get_mount_flags("/proc", nullptr)); |
Luis Hector Chavez | 0bacbf8 | 2018-07-10 20:06:55 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Jorge Lucangeli Obes | 3ce72e0 | 2022-06-07 19:41:11 -0400 | [diff] [blame] | 138 | // Successfully obtain mount flags. |
| 139 | TEST(get_mount_flags, mount_flags) { |
Luis Hector Chavez | 0bacbf8 | 2018-07-10 20:06:55 -0700 | [diff] [blame] | 140 | struct statvfs stvfs_buf; |
| 141 | ASSERT_EQ(0, statvfs("/proc", &stvfs_buf)); |
| 142 | |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 143 | TemporaryDir dir; |
| 144 | ASSERT_TRUE(dir.is_valid()); |
Luis Hector Chavez | 0bacbf8 | 2018-07-10 20:06:55 -0700 | [diff] [blame] | 145 | |
| 146 | unsigned long mount_flags = -1; |
Jorge Lucangeli Obes | 3ce72e0 | 2022-06-07 19:41:11 -0400 | [diff] [blame] | 147 | ASSERT_EQ(0, get_mount_flags("/proc", &mount_flags)); |
Jorge Lucangeli Obes | b4b7c5a | 2019-09-09 10:47:36 -0400 | [diff] [blame] | 148 | EXPECT_EQ(stvfs_buf.f_flag, mount_flags); |
Luis Hector Chavez | 0bacbf8 | 2018-07-10 20:06:55 -0700 | [diff] [blame] | 149 | |
| 150 | // Same thing holds for children of a mount. |
| 151 | mount_flags = -1; |
Jorge Lucangeli Obes | 3ce72e0 | 2022-06-07 19:41:11 -0400 | [diff] [blame] | 152 | ASSERT_EQ(0, get_mount_flags("/proc/self", &mount_flags)); |
Jorge Lucangeli Obes | b4b7c5a | 2019-09-09 10:47:36 -0400 | [diff] [blame] | 153 | EXPECT_EQ(stvfs_buf.f_flag, mount_flags); |
Jorge Lucangeli Obes | 3ce72e0 | 2022-06-07 19:41:11 -0400 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | // Non-existent paths fail with the proper errno value. |
| 157 | TEST(get_mount_flags, nonexistent_path) { |
| 158 | unsigned long mount_flags = -1; |
| 159 | ASSERT_EQ(-ENOENT, get_mount_flags("/does/not/exist", &mount_flags)); |
| 160 | } |
| 161 | |
| 162 | // If the destination exists, there's nothing to do. |
| 163 | TEST(setup_mount_destination, dest_exists) { |
| 164 | // Pick some paths that should always exist. We pass in invalid pointers |
| 165 | // for other args so we crash if the dest check doesn't short circuit. |
| 166 | EXPECT_EQ(0, setup_mount_destination(nullptr, kValidDir, 0, 0, false)); |
| 167 | EXPECT_EQ(0, setup_mount_destination(nullptr, "/proc", 0, 0, true)); |
| 168 | EXPECT_EQ(0, setup_mount_destination(nullptr, "/dev", 0, 0, false)); |
Mike Frysinger | eaab420 | 2017-08-14 14:57:21 -0400 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | // When given a bind mount where the source is relative, reject it. |
| 172 | TEST(setup_mount_destination, reject_relative_bind) { |
| 173 | // Pick a destination we know doesn't exist. |
Jorge Lucangeli Obes | 3ce72e0 | 2022-06-07 19:41:11 -0400 | [diff] [blame] | 174 | EXPECT_NE(0, setup_mount_destination("foo", kNoSuchDir, 0, 0, true)); |
Mike Frysinger | eaab420 | 2017-08-14 14:57:21 -0400 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | // A mount of a pseudo filesystem should make the destination dir. |
| 178 | TEST(setup_mount_destination, create_pseudo_fs) { |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 179 | TemporaryDir dir; |
| 180 | ASSERT_TRUE(dir.is_valid()); |
Mike Frysinger | eaab420 | 2017-08-14 14:57:21 -0400 | [diff] [blame] | 181 | |
Jorge Lucangeli Obes | 1fc0518 | 2018-04-05 10:17:01 -0400 | [diff] [blame] | 182 | // Passing -1 for user ID/group ID tells chown to make no changes. |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 183 | std::string no_chmod = dir.path + "/no_chmod"; |
Jorge Lucangeli Obes | 3ce72e0 | 2022-06-07 19:41:11 -0400 | [diff] [blame] | 184 | EXPECT_EQ(0, setup_mount_destination("none", no_chmod.c_str(), -1, -1, |
| 185 | false)); |
Mike Frysinger | eaab420 | 2017-08-14 14:57:21 -0400 | [diff] [blame] | 186 | // We check it's a directory by deleting it as such. |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 187 | EXPECT_EQ(0, rmdir(no_chmod.c_str())); |
Jorge Lucangeli Obes | 1fc0518 | 2018-04-05 10:17:01 -0400 | [diff] [blame] | 188 | |
| 189 | // Confirm that a bad user ID/group ID fails the function as expected. |
| 190 | // On Android, Bionic manages user IDs directly: there is no /etc/passwd file. |
| 191 | // This results in most user IDs being valid. Instead of trying to find an |
| 192 | // invalid user ID, just skip this check. |
| 193 | if (!is_android()) { |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 194 | std::string with_chmod = dir.path + "/with_chmod"; |
| 195 | EXPECT_NE(0, setup_mount_destination("none", with_chmod.c_str(), |
Jorge Lucangeli Obes | 3ce72e0 | 2022-06-07 19:41:11 -0400 | [diff] [blame] | 196 | UINT_MAX / 2, UINT_MAX / 2, false)); |
Jorge Lucangeli Obes | 1fc0518 | 2018-04-05 10:17:01 -0400 | [diff] [blame] | 197 | } |
Mike Frysinger | eaab420 | 2017-08-14 14:57:21 -0400 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | // If the source path does not exist, we should error out. |
| 201 | TEST(setup_mount_destination, missing_source) { |
| 202 | // The missing dest path is so we can exercise the source logic. |
Jorge Lucangeli Obes | 3ce72e0 | 2022-06-07 19:41:11 -0400 | [diff] [blame] | 203 | EXPECT_NE(0, setup_mount_destination(kNoSuchDir, kNoSuchDir, 0, 0, false)); |
| 204 | EXPECT_NE(0, setup_mount_destination(kNoSuchDir, kNoSuchDir, 0, 0, true)); |
Mike Frysinger | eaab420 | 2017-08-14 14:57:21 -0400 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | // A bind mount of a directory should create the destination dir. |
| 208 | TEST(setup_mount_destination, create_bind_dir) { |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 209 | TemporaryDir dir; |
| 210 | ASSERT_TRUE(dir.is_valid()); |
Mike Frysinger | eaab420 | 2017-08-14 14:57:21 -0400 | [diff] [blame] | 211 | |
Jorge Lucangeli Obes | 1fc0518 | 2018-04-05 10:17:01 -0400 | [diff] [blame] | 212 | // Passing -1 for user ID/group ID tells chown to make no changes. |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 213 | std::string child_dir = dir.path + "/child_dir"; |
| 214 | EXPECT_EQ(0, setup_mount_destination(kValidDir, child_dir.c_str(), -1, -1, |
Jorge Lucangeli Obes | 3ce72e0 | 2022-06-07 19:41:11 -0400 | [diff] [blame] | 215 | true)); |
Mike Frysinger | eaab420 | 2017-08-14 14:57:21 -0400 | [diff] [blame] | 216 | // We check it's a directory by deleting it as such. |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 217 | EXPECT_EQ(0, rmdir(child_dir.c_str())); |
Mike Frysinger | eaab420 | 2017-08-14 14:57:21 -0400 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | // A bind mount of a file should create the destination file. |
| 221 | TEST(setup_mount_destination, create_bind_file) { |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 222 | TemporaryDir dir; |
| 223 | ASSERT_TRUE(dir.is_valid()); |
Mike Frysinger | eaab420 | 2017-08-14 14:57:21 -0400 | [diff] [blame] | 224 | |
Jorge Lucangeli Obes | 1fc0518 | 2018-04-05 10:17:01 -0400 | [diff] [blame] | 225 | // Passing -1 for user ID/group ID tells chown to make no changes. |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 226 | std::string child_file = dir.path + "/child_file"; |
| 227 | EXPECT_EQ(0, setup_mount_destination(kValidFile, child_file.c_str(), -1, -1, |
Jorge Lucangeli Obes | 3ce72e0 | 2022-06-07 19:41:11 -0400 | [diff] [blame] | 228 | true)); |
Mike Frysinger | eaab420 | 2017-08-14 14:57:21 -0400 | [diff] [blame] | 229 | // We check it's a file by deleting it as such. |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 230 | EXPECT_EQ(0, unlink(child_file.c_str())); |
Mike Frysinger | eaab420 | 2017-08-14 14:57:21 -0400 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | // A mount of a character device should create the destination char. |
| 234 | TEST(setup_mount_destination, create_char_dev) { |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 235 | TemporaryDir dir; |
| 236 | ASSERT_TRUE(dir.is_valid()); |
Mike Frysinger | eaab420 | 2017-08-14 14:57:21 -0400 | [diff] [blame] | 237 | |
Jorge Lucangeli Obes | 1fc0518 | 2018-04-05 10:17:01 -0400 | [diff] [blame] | 238 | // Passing -1 for user ID/group ID tells chown to make no changes. |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 239 | std::string child_dev = dir.path + "/child_dev"; |
| 240 | EXPECT_EQ(0, setup_mount_destination(kValidCharDev, child_dev.c_str(), -1, -1, |
Jorge Lucangeli Obes | 3ce72e0 | 2022-06-07 19:41:11 -0400 | [diff] [blame] | 241 | false)); |
Mike Frysinger | eaab420 | 2017-08-14 14:57:21 -0400 | [diff] [blame] | 242 | // We check it's a directory by deleting it as such. |
Luis Hector Chavez | c5f4f47 | 2018-07-11 12:27:18 -0700 | [diff] [blame] | 243 | EXPECT_EQ(0, rmdir(child_dev.c_str())); |
Mike Frysinger | 0b5cffa | 2017-08-15 18:06:18 -0400 | [diff] [blame] | 244 | } |
Jorge Lucangeli Obes | 32201f8 | 2019-06-12 14:45:06 -0400 | [diff] [blame] | 245 | |
| 246 | TEST(seccomp_actions_available, smoke) { |
| 247 | seccomp_ret_log_available(); |
| 248 | seccomp_ret_kill_process_available(); |
| 249 | } |
Jorge Lucangeli Obes | a8eef8b | 2022-07-20 19:20:06 -0400 | [diff] [blame] | 250 | |
| 251 | TEST(is_canonical_path, basic) { |
| 252 | EXPECT_FALSE(is_canonical_path("/proc/self")); |
| 253 | EXPECT_FALSE(is_canonical_path("relative")); |
| 254 | EXPECT_FALSE(is_canonical_path("/proc/./1")); |
| 255 | EXPECT_FALSE(is_canonical_path("/proc/../proc/1")); |
| 256 | |
| 257 | EXPECT_TRUE(is_canonical_path("/")); |
| 258 | EXPECT_TRUE(is_canonical_path("/proc")); |
| 259 | EXPECT_TRUE(is_canonical_path("/proc/1")); |
| 260 | } |
Jorge Lucangeli Obes | b5464b7 | 2022-08-09 21:22:40 +0000 | [diff] [blame^] | 261 | |
| 262 | TEST(is_canonical_path, trailing_slash) { |
| 263 | EXPECT_TRUE(is_canonical_path("/proc/1/")); |
| 264 | EXPECT_FALSE(is_canonical_path("/proc/1//")); |
| 265 | } |