bundle common test_meta
{
  vars:
      "description" string => "A user present gets the password changed";
      "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";

  vars:
    "hash" string => "dTloMVpjYt1w2";

  users:
    "johndoe"
      policy => "present",
      password => init_password;
}

body password init_password
{
  data => "$(init.hash)";
  !windows::
    format => "hash";
  windows::
    format => "plaintext";
}

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

bundle agent test
{
  users:
    "johndoe"
      policy => "present",
      password => test_password;
}

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

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

bundle agent check
{
  methods:
    !windows::
      # Make sure it is *not* the same as before.
      "any" usebundle => user_has_password_hash("johndoe", "$(init.hash)", "failure", "success"),
        classes => always("methods_run");
    windows::
      "any" usebundle => user_has_password("johndoe", "New0P4SSW0RD", "success", "failure"),
        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";
      "ok" and => { "success", "!failure", "no_pw_update_ok", "!no_pw_update_fail" };

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