body common control
{
  inputs => { "../plucked.cf.sub" };
}

bundle agent test
{
  vars:
    "unsafe_functions" slist => {
      "execresult",
      "execresult_as_data",
      "returnszero",
      "usemodule"
    };

    "test_1" string => execresult("touch $(sys.statedir)$(const.dirsep)execresult_safe", useshell),
      meta => { "simulate_safe" };
    "test_2" string => execresult("touch $(sys.statedir)$(const.dirsep)execresult_unsafe", useshell);
    "test_3" data => execresult_as_data("touch $(sys.statedir)$(const.dirsep)execresult_as_data_safe", useshell),
      meta => { "simulate_safe" };
    "test_4" data => execresult_as_data("touch $(sys.statedir)$(const.dirsep)execresult_as_data_unsafe", useshell);

  classes:
    "test_5" expression => returnszero("touch $(sys.statedir)$(const.dirsep)returnszero_safe", useshell),
      meta => { "simulate_safe" };
    "test_6" expression => returnszero("touch $(sys.statedir)$(const.dirsep)returnszero_unsafe", useshell);
    "test_7" expression => usemodule("usemodule_safe.sh", useshell),
      meta => { "simulate_safe" };
    "test_8" expression => usemodule("usemodule_unsafe.sh", useshell);

}

bundle agent check
{
  classes:
    "pass_$(test.unsafe_functions)" expression => not(fileexists("$(sys.statedir)$(const.dirsep)$(test.unsafe_functions)_unsafe"));
    "fail_$(test.unsafe_functions)" expression => fileexists("$(sys.statedir)$(const.dirsep)$(test.unsafe_functions)_unsafe");

  reports:
    "$(this.promise_filename) FAIL"
      if => classmatch("fail_.*");
    "$(this.promise_filename) Pass"
      if => strcmp(countclassesmatching("fail.*"), 0);
}

bundle agent __main__
{
  methods:
    "init";
    "test";
    "check";
}
