bundle common test_meta
{
  vars:
    "description"
      string => "A user present gets enabled and the password changed";

    "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";

  users:
    "johndoe" policy => "locked";
}

#######################################################
bundle agent test
{
  vars:
    "hash" string => "dTloMVpjYt1w2";

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

body password test_password
{
  !windows::
    format => "hash";
    data => "$(test.hash)";

  windows::
    format => "plaintext";
    data => "Unlocked0P4SSW0RD";
}

#######################################################
bundle agent check
{
  methods:
    "any"
      usebundle => user_is_unlocked(
        "johndoe", "unlock_success", "unlock_failure"
      ),
      classes => always("unlock_methods_run");

    !windows::
      "any"
        usebundle => user_has_password_hash(
          "johndoe", "$(test.hash)", "hash_success", "hash_failure"
        ),
        classes => always("hash_methods_run");

    windows::
      "any"
        usebundle => user_has_password(
          "johndoe", "Unlocked0P4SSW0RD", "hash_success", "hash_failure"
        ),
        classes => always("hash_methods_run");

  classes:
    "ready" and => { "unlock_methods_run", "hash_methods_run" };

    "ok"
      and => {
        "unlock_success", "!unlock_failure", "hash_success", "!hash_failure"
      };

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

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