summaryrefslogtreecommitdiff
path: root/Tests/Kernel/unveil-symlinks.cpp
diff options
context:
space:
mode:
authorBrian Gianforcaro <bgianf@serenityos.org>2021-05-06 01:14:50 -0700
committerAndreas Kling <kling@serenityos.org>2021-05-06 17:54:28 +0200
commitfd0dbd1ebfbcbc29d46393061daa49dc7390caa7 (patch)
tree278ea94a46900e47ff7dae46b1017cd31095971a /Tests/Kernel/unveil-symlinks.cpp
parent6e641fadfa61d4b890db52fb60cc3709352336b6 (diff)
downloadserenity-fd0dbd1ebfbcbc29d46393061daa49dc7390caa7.zip
Tests: Establish root Tests directory, move Userland/Tests there
With the goal of centralizing all tests in the system, this is a first step to establish a Tests sub-tree. It will contain all of the unit tests and test harnesses for the various components in the system.
Diffstat (limited to 'Tests/Kernel/unveil-symlinks.cpp')
-rw-r--r--Tests/Kernel/unveil-symlinks.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/Tests/Kernel/unveil-symlinks.cpp b/Tests/Kernel/unveil-symlinks.cpp
new file mode 100644
index 0000000000..11569e6477
--- /dev/null
+++ b/Tests/Kernel/unveil-symlinks.cpp
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2020, the SerenityOS developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+int main()
+{
+ rmdir("/tmp/foo/1");
+ rmdir("/tmp/foo");
+ unlink("/tmp/bar");
+
+ if (mkdir("/tmp/foo", 0755) < 0) {
+ perror("mkdir");
+ return 1;
+ }
+
+ if (mkdir("/tmp/foo/1", 0755) < 0) {
+ perror("mkdir");
+ return 1;
+ }
+
+ if (symlink("/tmp/foo", "/tmp/bar")) {
+ perror("symlink");
+ return 1;
+ }
+
+ if (unveil("/tmp/foo", "r") < 0) {
+ perror("unveil");
+ return 1;
+ }
+
+ if (unveil(nullptr, nullptr) < 0) {
+ perror("unveil");
+ return 1;
+ }
+
+ int fd = open("/tmp/foo/1", O_RDONLY);
+ if (fd < 0) {
+ perror("open");
+ return 1;
+ }
+ close(fd);
+
+ fd = open("/tmp/bar/1", O_RDONLY);
+ if (fd >= 0) {
+ fprintf(stderr, "FAIL, symlink was not unveiled\n");
+ return 1;
+ }
+
+ if (chdir("/tmp")) {
+ perror("chdir");
+ return 1;
+ }
+
+ fd = open("./foo/1", O_RDONLY);
+ if (fd < 0) {
+ perror("open");
+ return 1;
+ }
+ close(fd);
+
+ fd = open("./bar/1", O_RDONLY);
+ if (fd >= 0) {
+ fprintf(stderr, "FAIL, symlink was not unveiled\n");
+ return 1;
+ }
+
+ printf("PASS\n");
+ return 0;
+}