ladybird/Tests/Kernel/unveil-symlinks.cpp
Brian Gianforcaro fd0dbd1ebf 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.
2021-05-06 17:54:28 +02:00

77 lines
1.3 KiB
C++

/*
* 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;
}