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

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

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

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

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

  methods:
      "any" usebundle => disable_sudo_tty_requirement;
}

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

bundle agent test
{
  vars:
    aix::
      # AIX only allows certain shells.
      "shell" string => "/bin/csh";
    !aix::
      "shell" string => "$(G.cat)";

  users:
    "johndoe"
      policy => "present",
      shell => "$(shell)";
}

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

bundle agent check
{
  vars:
    "currentdir" string => dirname("$(this.promise_filename)");

  classes:
    !windows.!aix::
      "ok" expression => regcmp(".*Succeeded.*", execresult("sudo su johndoe $(currentdir)$(const.dirsep)add_user_with_shell.txt", "useshell"));

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

  classes:
    aix::
      "ok" and => { "shell_success", "!shell_failure" };

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