bundle common test_meta
{
  vars:
      "description" string => "A user present gets the password set to the same as before";
      "story_id" string => "5525";
      "covers" string => "operational_kept";
}

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

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

      # Something in the Solaris chroot test environment makes it impossible
      # to test matching passwords, the pam module always returns error.
      # This should not happen in a production system though.
      # Since the error is not on our part, and likely unsolvable, we set
      # Redmine to zero. However, it would be nice to know if the problem ever
      # goes away, so using soft_fail.
      "test_soft_fail" string => "!hpux_trusted_mode_test.(solaris.!sunos_5_9)",
        meta => { "redmine0" };
      # On Solaris 9 PAM just crashes inside chroot.
      "test_skip_needs_work" string => "!hpux_trusted_mode_test.sunos_5_9";
  vars:
    # This is the same password as the plaintext one further down.
    "hash" string => "dTloMVpjYt1w2";

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

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

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

bundle agent test
{
  users:
    "johndoe"
      policy => "present",
      password => test_password,
      classes => if_repaired("kept_failed");
}

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

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

bundle agent check
{
  methods:
    # Make sure it is the same as before.
    !windows::
      "any" usebundle => user_has_password_hash("johndoe", "$(init.hash)", "success", "failure"),
        classes => always("methods_run");
    windows::
      "any" usebundle => user_has_password("johndoe", "J0hnd0eX", "success", "failure"),
        classes => always("methods_run");

  classes:
      "ready" expression => "methods_run";
      "ok" and => { "success", "!failure", "!kept_failed" };

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