bundle common test_meta
{
  vars:
      "description" string => "A user not present gets added with several attributes";
      "story_id" string => "5525";
      "covers" string => "operational_repaired";
}

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

body common control
{
      inputs => { "../../default.sub.cf", "user_queries.cf.sub" };
      bundlesequence  => { default("$(this.promise_filename)") };
}

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

bundle common hpux_trusted
{
  classes:
      "hpux_trusted_mode_test"
        expression => regcmp(".*hpux_trusted.*", $(this.promise_filename));
}

bundle agent init
{
  meta:
      "test_skip_unsupported" string => "hpux_trusted_mode_test.!hpux";

  # Remove him first, should he already be present.
  users:
    "johndoe"
      policy => "absent";
}

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

bundle agent test
{
  vars:
      "desc_string" string => "This description should make the CFEngine test pass";
    aix::
      # AIX only allows certain shells.
      "shell" string => "/bin/csh";
    !aix::
      "shell" string => "$(G.echo)";

  users:
    "johndoe"
      policy => "present",
      uid => "9876",
      group_primary => "$(user_tests.group1)",
      groups_secondary => { "$(user_tests.group2)" },
      home_dir => "/home/user-johndoe",
      shell => "$(shell)",
      description => "$(desc_string)";
}

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

bundle agent check
{
  methods:
      "any" usebundle => remove_stale_groups;

  methods:
    "any" usebundle => user_has_uid("johndoe", "9876", "uid_success", "uid_failure"),
      classes => always("uid_methods_run");

    "any" usebundle => user_is_in_primary_group("johndoe", "$(user_tests.group1)", "pgroup_success", "pgroup_failure"),
      classes => always("pgroup_methods_run");

    "any" usebundle => user_is_in_secondary_group("johndoe", "$(user_tests.group2)", "sgroup_success", "sgroup_failure"),
      classes => always("sgroup_methods_run");

    "any" usebundle => user_has_home_dir("johndoe", "/home/user-johndoe", "home_success", "home_failure"),
      classes => always("home_methods_run");

    "any" usebundle => user_has_shell("johndoe", "$(test.shell)", "shell_success", "shell_failure"),
      classes => always("shell_methods_run");

    "any" usebundle => user_has_description("johndoe", "$(test.desc_string)", "desc_success", "desc_failure"),
      classes => always("desc_methods_run");

  classes:
      "ready" and => { "uid_methods_run", "pgroup_methods_run", "sgroup_methods_run",
                       "home_methods_run", "shell_methods_run", "desc_methods_run" };
    !windows::
      "unix_ok" and => { "uid_success", "!uid_failure", "shell_success", "!shell_failure", };
    windows::
      "unix_ok" expression => "any";
    any::
      "ok" and => { "pgroup_success", "!pgroup_failure", "sgroup_success", "!sgroup_failure",
                    "home_success", "!home_failure", "desc_success", "!desc_failure",
                    "unix_ok" };

  reports:
    ok.ready::
      "$(this.promise_filename) Pass";
    !ok.ready::
      "$(this.promise_filename) FAIL";
}
