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

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

body common control
{
      inputs => { "../../default.cf.sub", "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
{
  users:
    "johndoe"
      policy => "present",
      password => test_password;
}

body password test_password
{
  format => "plaintext";
  data => "J0hnd0eX";
}

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

bundle agent check
{
  methods:
    !windows::
      "any" usebundle => user_get_password_hash("johndoe"),
        classes => always("methods_run");
    windows::
      "any" usebundle => user_has_password("johndoe", "J0hnd0eX", "pw_ok", "pw_fail"),
        classes => always("methods_run");

    any::
      "any" usebundle => user_does_not_need_password_update("johndoe", "no_pw_update_ok", "no_pw_update_fail");

  classes:
      "ready" expression => "methods_run";
    !windows::
      # Make sure the password field has grown to more than a few characters.
      "pw_ok" expression => regcmp("^[^:][^:][^:][^:][^:][^:][^:][^:][^:][^:].*", "$(user_get_password_hash.hash)");

    any::
      "ok" and => { "pw_ok", "!pw_fail", "no_pw_update_ok", "!no_pw_update_fail" };

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