######################################################
#
#  ACL tests
#
#####################################################
body common control
{
      inputs => { "../../default.sub.cf" };
      bundlesequence  => { default("$(this.promise_filename)") };
      version => "1.0";
}

#######################################################

bundle agent init
{
  classes:
      "cfengine_internal_getfacl" expression => fileexists("/var/cfengine/bin/getfacl");
      "system_getfacl" expression => fileexists("/usr/bin/getfacl");

  vars:
    linux.cfengine_internal_getfacl::
      "cmd" string => "/var/cfengine/bin/getfacl";
    linux.!cfengine_internal_getfacl.system_getfacl::
      "cmd" string => "/usr/bin/getfacl";

  files:
      "$(G.testdir)$(const.dirsep)file"
      create => "true",
      acl => acl_sanity_check;
}

body acl acl_sanity_check
{
      acl_method => "append";
      aces => { "all:=rwx:allow" };
}

#######################################################

bundle agent test
{
  meta:
      "test_skip_needs_work" string => "windows";

  vars:
    linux::
      "sanity_perms" string => execresult("$(init.cmd) $(G.testdir)$(const.dirsep)file 2>&1 | $(G.grep) -v 'Removing leading'", "noshell");
  classes:
    linux::
      # Some filesystems don't have ACL capability, so we do this sanity check.
      "linux_go_ahead" expression => regcmp(".*other::rwx.*", "$(sanity_perms)");
  vars:
    linux_go_ahead|windows::
      "result" string => execresult("$(sys.cf_agent) -Kf $(this.promise_filename).sub", "noshell");
    !linux_go_ahead.!windows::
      "result" string => "";

  reports:
    DEBUG.!linux_go_ahead.!windows::
      "ACL support not detected. Try remounting the filesystem with -o acl.";
}

#######################################################

bundle agent check
{
  classes:
      "ok" not => regcmp(".*(error|failed).*", "$(test.result)");
  reports:
    DEBUG::
      "Tests various ACL features";
    DEBUG.!ok::
      "Subtest(s) failing: $(test.result)";
    ok::
      "$(this.promise_filename) Pass";
    !ok::
      "$(this.promise_filename) FAIL";

  files:
      "$(G.testdir)$(const.dirsep)file"
      acl => acl_sanity_check_reset;
}

body acl acl_sanity_check_reset
{
      acl_method => "append";
      aces => { "all:-rwx:allow" };
}
### PROJECT_ID: core
### CATEGORY_ID: 27
