1bundle common test_meta
2{
3  vars:
4      "description" string => "A user not present gets added with several secondary groups";
5      "story_id" string => "5525";
6      "covers" string => "operational_repaired";
7}
8
9#######################################################
10
11body common control
12{
13      inputs => { "../../default.cf.sub",
14                  "user_queries.cf.sub",
15                  "disable_sudo_tty_requirement.cf.sub"
16                };
17      bundlesequence  => { default("$(this.promise_filename)") };
18}
19
20#######################################################
21
22body perms init_perms_body_bin
23{
24  groups => { "$(user_tests.group1)" };
25  mode => "664";
26}
27
28body perms init_perms_body_sys
29{
30  groups => { "$(user_tests.group2)" };
31  mode => "664";
32}
33
34bundle agent init
35{
36  # Remove him first, should he already be present.
37  users:
38    "johndoe"
39      policy => "absent";
40
41  files:
42    "$(G.testfile)"
43      create => "true",
44      perms => init_perms_body_bin;
45    "$(G.testfile).2"
46      create => "true",
47      perms => init_perms_body_sys;
48
49  methods:
50      "any" usebundle => disable_sudo_tty_requirement;
51}
52
53#######################################################
54
55body contain test_contain_body
56{
57  useshell => "useshell";
58}
59
60bundle agent test
61{
62  users:
63    "johndoe"
64      policy => "present",
65      groups_secondary => { "$(user_tests.group1)", "$(user_tests.group2)" };
66
67  commands:
68    sudo_works::
69      "sudo -u johndoe /bin/sh -c '$(G.echo) Succeeded > $(G.testfile)'"
70        contain => test_contain_body;
71      "sudo -u johndoe /bin/sh -c '$(G.echo) Succeeded > $(G.testfile).2'"
72        contain => test_contain_body;
73}
74
75#######################################################
76
77bundle agent check
78{
79  methods:
80    "any" usebundle => user_is_in_secondary_group("johndoe", "$(user_tests.group1)", "bin_success", "bin_failure"),
81      classes => always("bin_methods_run");
82    "any" usebundle => user_is_in_secondary_group("johndoe", "$(user_tests.group2)", "sys_success", "sys_failure"),
83      classes => always("sys_methods_run");
84
85  classes:
86    !windows::
87      "1_ok" not => strcmp("0", countlinesmatching("Succeeded", "$(G.testfile)"));
88      "2_ok" not => strcmp("0", countlinesmatching("Succeeded", "$(G.testfile).2"));
89
90  classes:
91      "ready" and => { "bin_methods_run", "sys_methods_run" };
92    sudo_works::
93      "ok" and => { "bin_success", "!bin_failure", "sys_success", "!sys_failure", "1_ok", "2_ok" };
94    !sudo_works::
95      "ok" and => { "bin_success", "!bin_failure", "sys_success", "!sys_failure" };
96
97  reports:
98    ok.ready::
99      "$(this.promise_filename) Pass";
100    !ok.ready::
101      "$(this.promise_filename) FAIL";
102}
103