]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
tests: jail: Check file ownership
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 16 Aug 2022 12:41:04 +0000 (12:41 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 16 Aug 2022 12:41:04 +0000 (12:41 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/libpakfire/jail.c

index 2b5240bc4d7871dd21fd145427a97fc9e99a4921..008e05ef7352e575458785775a2ea3d6a4ba6eab 100644 (file)
@@ -35,6 +35,10 @@ static const char* cmd_fork_bomb[] = {
        "/command", "fork-bomb", NULL,
 };
 
+static const char* cmd_stat_ownership[] = {
+       "/command", "stat-ownership", NULL,
+};
+
 static int test_create(const struct test* t) {
        struct pakfire_jail* jail = NULL;
 
@@ -210,7 +214,6 @@ static int test_pid_limit(const struct test* t) {
        struct pakfire_jail* jail = NULL;
        int r = EXIT_FAILURE;
 
-
        // Create cgroup
        ASSERT_SUCCESS(pakfire_cgroup_open(&cgroup, t->pakfire, "pakfire-test", 0));
 
@@ -240,6 +243,26 @@ FAIL:
        return r;
 }
 
+static int test_file_ownership(const struct test* t) {
+       int r = EXIT_FAILURE;
+       char* output = NULL;
+
+       // Execute a simple command
+       ASSERT_SUCCESS(pakfire_jail_run(t->pakfire, cmd_stat_ownership, 0, &output));
+
+       // Check if the file has been mapped to root/root
+       ASSERT_STRING_EQUALS(output, "uid=0 gid=0\n");
+
+       // Success
+       r = EXIT_SUCCESS;
+
+FAIL:
+       if (output)
+               free(output);
+
+       return r;
+}
+
 int main(int argc, const char* argv[]) {
        testsuite_add_test(test_create);
        testsuite_add_test(test_env);
@@ -248,6 +271,7 @@ int main(int argc, const char* argv[]) {
        testsuite_add_test(test_nice);
        testsuite_add_test(test_memory_limit);
        testsuite_add_test(test_pid_limit);
+       testsuite_add_test(test_file_ownership);
 
        return testsuite_run(argc, argv);
 }