LCOV - code coverage report
Current view: top level - test - test-acl-util.c (source / functions) Hit Total Coverage
Test: main_coverage.info Lines: 29 33 87.9 %
Date: 2019-08-22 15:41:25 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /* SPDX-License-Identifier: LGPL-2.1+ */
       2             : 
       3             : #include <fcntl.h>
       4             : #include <stdlib.h>
       5             : #include <sys/stat.h>
       6             : #include <unistd.h>
       7             : 
       8             : #include "acl-util.h"
       9             : #include "fd-util.h"
      10             : #include "string-util.h"
      11             : #include "tmpfile-util.h"
      12             : #include "user-util.h"
      13             : 
      14           1 : static void test_add_acls_for_user(void) {
      15           1 :         char fn[] = "/tmp/test-empty.XXXXXX";
      16           1 :         _cleanup_close_ int fd = -1;
      17             :         char *cmd;
      18             :         uid_t uid;
      19             :         int r;
      20             : 
      21           1 :         fd = mkostemp_safe(fn);
      22           1 :         assert_se(fd >= 0);
      23             : 
      24             :         /* Use the mode that user journal files use */
      25           1 :         assert_se(fchmod(fd, 0640) == 0);
      26             : 
      27           5 :         cmd = strjoina("ls -l ", fn);
      28           1 :         assert_se(system(cmd) == 0);
      29             : 
      30           5 :         cmd = strjoina("getfacl -p ", fn);
      31           1 :         assert_se(system(cmd) == 0);
      32             : 
      33           1 :         if (getuid() == 0) {
      34           0 :                 const char *nobody = NOBODY_USER_NAME;
      35           0 :                 r = get_user_creds(&nobody, &uid, NULL, NULL, NULL, 0);
      36           0 :                 if (r < 0)
      37           0 :                         uid = 0;
      38             :         } else
      39           1 :                 uid = getuid();
      40             : 
      41           1 :         r = add_acls_for_user(fd, uid);
      42           1 :         assert_se(r >= 0);
      43             : 
      44           5 :         cmd = strjoina("ls -l ", fn);
      45           1 :         assert_se(system(cmd) == 0);
      46             : 
      47           5 :         cmd = strjoina("getfacl -p ", fn);
      48           1 :         assert_se(system(cmd) == 0);
      49             : 
      50             :         /* set the acls again */
      51             : 
      52           1 :         r = add_acls_for_user(fd, uid);
      53           1 :         assert_se(r >= 0);
      54             : 
      55           5 :         cmd = strjoina("ls -l ", fn);
      56           1 :         assert_se(system(cmd) == 0);
      57             : 
      58           5 :         cmd = strjoina("getfacl -p ", fn);
      59           1 :         assert_se(system(cmd) == 0);
      60             : 
      61           1 :         unlink(fn);
      62           1 : }
      63             : 
      64           1 : int main(int argc, char **argv) {
      65           1 :         test_add_acls_for_user();
      66             : 
      67           1 :         return 0;
      68             : }

Generated by: LCOV version 1.14