Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #14302: Enhance ncf audit test #999

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion tests/acceptance/30_generic_methods/command_execution.cf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ bundle agent init
vars:
"command_name" string => "/bin/date | egrep '[0-9]'";
"canonified_command_name" string => canonify("${command_name}");

"file_name" string => execresult("echo $RANDOM", "useshell");
"audit_command_name" string => "touch ${file_name}";
"canonified_audit_command_name" string => canonify("${audit_command_name}");
}

#######################################################
Expand All @@ -32,14 +36,23 @@ bundle agent test
{
methods:
"ph1" usebundle => command_execution("${init.command_name}");

"enable" usebundle => set_dry_run_mode("true");
"ph1" usebundle => command_execution("${init.audit_command_name}");
"disable" usebundle => set_dry_run_mode("false");
}

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

bundle agent check
{
classes:
"ok" expression => "command_execution_${init.canonified_command_name}_ok.!command_execution_${init.canonified_command_name}_error";
"enforce_ok" expression => "command_execution_${init.canonified_command_name}_ok.!command_execution_${init.canonified_command_name}_error";

"file_exists" expression => fileexists("${init.file_name}");
"audit_ok" expression => "command_execution_${init.canonified_audit_command_name}_error.!command_execution_${init.canonified_audit_command_name}_repaired.!command_execution_${init.canonified_audit_command_name}_ok.!file_exists";

"ok" expression => "enforce_ok.audit_ok";

reports:
ok::
Expand Down
27 changes: 26 additions & 1 deletion tests/acceptance/30_generic_methods/command_execution_result.cf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ bundle agent init
vars:
"command_0" string => "exit 0";
"canonified_command_0" string => canonify("${command_name}");

"file_name" string => execresult("echo $RANDOM", "useshell");
"audit_command_line" string => "touch ${file_name} &&";
"canonified_audit_command_name" string => canonify("${audit_command_line}");
}

#######################################################
Expand All @@ -40,20 +44,41 @@ bundle agent test
"phC" usebundle => command_execution_result("exit 3", "${kept_codes}", "${repaired_codes}");
"phD" usebundle => command_execution_result("exit 4", "${kept_codes}", "${repaired_codes}");
"phE" usebundle => command_execution_result("exit 5", "${kept_codes}", "${repaired_codes}");

"enable" usebundle => set_dry_run_mode("true");
"phF" usebundle => command_execution_result("${init.audit_command_line} exit 0", "${kept_codes}", "${repaired_codes}");
"phG" usebundle => command_execution_result("${init.audit_command_line} exit 2", "${kept_codes}", "${repaired_codes}");
"phH" usebundle => command_execution_result("${init.audit_command_line} exit 3", "${kept_codes}", "${repaired_codes}");
"phI" usebundle => command_execution_result("${init.audit_command_line} exit 4", "${kept_codes}", "${repaired_codes}");
"phJ" usebundle => command_execution_result("${init.audit_command_line} exit 5", "${kept_codes}", "${repaired_codes}");
"disable" usebundle => set_dry_run_mode("false");
}

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

bundle agent check
{
vars:
"audit_report" string => "command_execution_result_${init.canonified_audit_command_name}_exit";

classes:
"ok_A" expression => "command_execution_result_exit_0_kept.!command_execution_result_exit_0_repaired.!command_execution_result_exit_0_error";
"ok_B" expression => "command_execution_result_exit_2_kept.!command_execution_result_exit_2_repaired.!command_execution_result_exit_2_error";
"ok_C" expression => "!command_execution_result_exit_3_kept.command_execution_result_exit_3_repaired.!command_execution_result_exit_3_error";
"ok_D" expression => "!command_execution_result_exit_4_kept.command_execution_result_exit_4_repaired.!command_execution_result_exit_4_error";
"ok_E" expression => "!command_execution_result_exit_5_kept.!command_execution_result_exit_5_repaired.command_execution_result_exit_5_error";

"ok" expression => "ok_A.ok_B.ok_C.ok_D.ok_E";

"file_exists" expression => fileexists("${init.file_name}");
"ok_F" expression => "!${audit_report}_0_kept.!${audit_report}_0_repaired.${audit_report}_0_error";
"ok_G" expression => "!${audit_report}_2_kept.!${audit_report}_2_repaired.${audit_report}_2_error";
"ok_H" expression => "!${audit_report}_3_kept.!${audit_report}_3_repaired.${audit_report}_3_error";
"ok_I" expression => "!${audit_report}_4_kept.!${audit_report}_4_repaired.${audit_report}_4_error";
"ok_J" expression => "!${audit_report}_5_kept.!${audit_report}_5_repaired.${audit_report}_5_error";

"enforce_ok" expression => "ok_A.ok_B.ok_C.ok_D.ok_E";
"audit_ok" expression => "ok_F.ok_G.ok_H.ok_I.ok_J.!file_exists";
"ok" expression => "enforce_ok.audit_ok";

reports:
ok::
Expand Down
20 changes: 19 additions & 1 deletion tests/acceptance/30_generic_methods/condition_from_command.cf
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ bundle agent test
"phE" usebundle => condition_from_command("classE", "exit 5", "${true_codes}", "${false_codes}"); # error
"phF" usebundle => condition_from_command("classF", "${init.very_long_command}", "${true_codes}", "${false_codes}"); # true

"enable" usebundle => set_dry_run_mode("true");
"phG" usebundle => condition_from_command("classG", "exit 0", "${true_codes}", "${false_codes}"); # error
"phH" usebundle => condition_from_command("classH", "exit 2", "${true_codes}", "${false_codes}"); # error
"phI" usebundle => condition_from_command("classI", "exit 3", "${true_codes}", "${false_codes}"); # error
"phJ" usebundle => condition_from_command("classJ", "exit 4", "${true_codes}", "${false_codes}"); # error
"phK" usebundle => condition_from_command("classK", "exit 5", "${true_codes}", "${false_codes}"); # error
"phL" usebundle => condition_from_command("classL", "${init.very_long_command}", "${true_codes}", "${false_codes}"); # true
"disable" usebundle => set_dry_run_mode("false");
}

#######################################################
Expand All @@ -55,7 +63,17 @@ bundle agent check
"ok_E" expression => "!condition_from_command_classE_kept.!condition_from_command_classE_repaired.condition_from_command_classE_error.!classE_true.!classE_false";
"ok_F" expression => "condition_from_command_classF_kept.!condition_from_command_classF_repaired.!condition_from_command_classF_error.classA_true.!classF_false";

"ok" expression => "ok_A.ok_B.ok_C.ok_D.ok_E.ok_F";
# No classes are defined in audit mode since we do not execute the command
"ok_G" expression => "!condition_from_command_classG_kept.!condition_from_command_classG_repaired.condition_from_command_classG_error.!classG_true.!classG_false";
"ok_H" expression => "!condition_from_command_classH_kept.!condition_from_command_classH_repaired.condition_from_command_classH_error.!classH_true.!classH_false";
"ok_I" expression => "!condition_from_command_classI_kept.!condition_from_command_classI_repaired.condition_from_command_classI_error.!classI_true.!classI_false";
"ok_J" expression => "!condition_from_command_classJ_kept.!condition_from_command_classJ_repaired.condition_from_command_classJ_error.!classJ_true.!classJ_false";
"ok_K" expression => "!condition_from_command_classK_kept.!condition_from_command_classK_repaired.condition_from_command_classK_error.!classK_true.!classK_false";
"ok_L" expression => "!condition_from_command_classL_kept.!condition_from_command_classL_repaired.condition_from_command_classL_error.!classL_true.!classL_false";

"enforce_ok" expression => "ok_A.ok_B.ok_C.ok_D.ok_E.ok_F";
"audit_ok" expression => "ok_G.ok_H.ok_I.ok_J.ok_K.ok_L";
"ok" expression => "enforce_ok.audit_ok";

reports:
ok::
Expand Down
17 changes: 14 additions & 3 deletions tests/acceptance/30_generic_methods/condition_from_expression.cf
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,28 @@ bundle agent test
"ph1" usebundle => condition_from_expression("class1", "any");
"ph2" usebundle => condition_from_expression("class2", "!any");

"enable" usebundle => set_dry_run_mode("true");
"ph3" usebundle => condition_from_expression("class3", "any");
"ph4" usebundle => condition_from_expression("class4", "!any");
"disable" usebundle => set_dry_run_mode("false");

}

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

bundle agent check
{
classes:
"ok_class1" expression => "condition_from_expression_class1_ok.class1_true";
"ok_class2" expression => "condition_from_expression_class2_ok.class2_false";
"ok_class1" expression => "condition_from_expression_class1_ok.class1_true.!condition_from_expression_class1_error.!condition_from_expression_class1_repaired";
"ok_class2" expression => "condition_from_expression_class2_ok.class2_false.!condition_from_expression_class2_error.!condition_from_expression_class2_repaired";

"ok_class3" expression => "condition_from_expression_class3_ok.class3_true.!condition_from_expression_class3_error.!condition_from_expression_class3_repaired";
"ok_class4" expression => "condition_from_expression_class4_ok.class4_false.!condition_from_expression_class4_error.!condition_from_expression_class4_repaired";

"enforce_ok" expression => "ok_class1.ok_class2";
"audit_ok" expression => "ok_class3.ok_class4";

"ok" expression => "ok_class1.ok_class2";
"ok" expression => "enforce_ok.audit_ok";

reports:
ok::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ bundle agent test
"ph2" usebundle => condition_from_variable_existence("class2", "my_prefix.my_empty_variable");
"ph3" usebundle => condition_from_variable_existence("class3", "my_prefix.my_undefined_variable");

"enable" usebundle => set_dry_run_mode("true");
"ph4" usebundle => condition_from_variable_existence("class4", "my_prefix.my_variable");
"ph5" usebundle => condition_from_variable_existence("class5", "my_prefix.my_empty_variable");
"ph6" usebundle => condition_from_variable_existence("class6", "my_prefix.my_undefined_variable");
"disable" usebundle => set_dry_run_mode("false");
}

#######################################################
Expand All @@ -47,7 +52,13 @@ bundle agent check
"ok_class2" expression => "condition_from_variable_existence_class2_my_prefix_my_empty_variable_ok.class2_true";
"ok_class3" expression => "condition_from_variable_existence_class3_my_prefix_my_undefined_variable_ok.class3_false";

"ok" expression => "ok_class1.ok_class2.ok_class3";
"ok_class4" expression => "condition_from_variable_existence_class1_my_prefix_my_variable_ok.class4_true";
"ok_class5" expression => "condition_from_variable_existence_class2_my_prefix_my_empty_variable_ok.class5_true";
"ok_class6" expression => "condition_from_variable_existence_class3_my_prefix_my_undefined_variable_ok.class6_false";

"enforce_ok" expression => "ok_class1.ok_class2.ok_class3";
"audit_ok" expression => "ok_class4.ok_class5.ok_class6";
"ok" expression => "enforce_ok.audit_ok";

reports:
!ok_class1::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ bundle agent init
text
on
multiline");

"enable" usebundle => set_dry_run_mode("true");
"method_call" usebundle => variable_string("my_audit_prefix", "my_variable", "Some text");
"method_call" usebundle => variable_string("my_audit_prefix", "my_empty_variable", "");
"method_call" usebundle => variable_string("my_audit_prefix", "my_multiline_variable", "some
text
on
multiline");
"disable" usebundle => set_dry_run_mode("false");
}

#######################################################
Expand All @@ -42,6 +51,11 @@ bundle agent test
"ph4" usebundle => condition_from_variable_match("class4", "my_prefix.my_variable", "nonmatching.*regex");
"ph5" usebundle => condition_from_variable_match("class5", "my_prefix.my_undefined_variable", "nonmatching.*regex");

"ph6" usebundle => condition_from_variable_match("class6", "my_audit_prefix.my_variable", "Some.*");
"ph7" usebundle => condition_from_variable_match("class7", "my_audit_prefix.my_empty_variable", ".*");
"ph8" usebundle => condition_from_variable_match("class8", "my_audit_prefix.my_multiline_variable", ".*on\s*multi.*");
"ph9" usebundle => condition_from_variable_match("class9", "my_audit_prefix.my_variable", "nonmatching.*regex");
"ph10" usebundle => condition_from_variable_match("class10", "my_audit_prefix.my_undefined_variable", "nonmatching.*regex");
}

#######################################################
Expand All @@ -55,31 +69,20 @@ bundle agent check
"ok_class4" expression => "condition_from_variable_match_class4_my_prefix_my_variable_ok.class4_false";
"ok_class5" expression => "condition_from_variable_match_class5_my_prefix_my_undefined_variable_error.class5_false";

"ok" expression => "ok_class1.ok_class2.ok_class3.ok_class4.ok_class5";
"ok_class6" expression => "condition_from_variable_match_class6_my_audit_prefix_my_variable_ok.class6_true";
"ok_class7" expression => "condition_from_variable_match_class7_my_audit_prefix_my_empty_variable_ok.class7_true";
"ok_class8" expression => "condition_from_variable_match_class8_my_audit_prefix_my_multiline_variable_ok.class8_true";
"ok_class9" expression => "condition_from_variable_match_class9_my_audit_prefix_my_variable_ok.class9_false";
"ok_class10" expression => "condition_from_variable_match_class10_my_audit_prefix_my_undefined_variable_error.class10_false";

"enforce_ok" expression => "ok_class1.ok_class2.ok_class3.ok_class4.ok_class5";
"audit_ok" expression => "ok_class6.ok_class7.ok_class8.ok_class9.ok_class10";
"ok" expression => "enforce_ok.audit_ok";

reports:
ok_class1::
"Test 1 succeed";
ok_class2::
"Test 2 succeed";
ok_class3::
"Test 3 succeed";
ok_class4::
"Test 4 succeed";
ok_class5::
"Test 5 succeed";
!ok_class1::
"Test 1 failed";
!ok_class2::
"Test 2 failed";
!ok_class3::
"Test 3 failed";
!ok_class4::
"Test 4 failed";
!ok_class5::
"Test 5 failed";
ok::
"$(this.promise_filename) Pass";
!ok::
"$(this.promise_filename) FAIL";
}

1 change: 1 addition & 0 deletions tree/30_generic_methods/condition_from_command.cf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# * If the exit code is in the `true_codes` list, this will produce a kept outcome class and a `${condition_prefix}_true` condition
# * If the exit code is in the `false_codes` list, this will produce a repaired outcome class and a `${condition_prefix}_false` condition
# * If the exit code is not in the list, or if the command is not present, this will produce an error outcome class and no classes with `${condition_prefix}`
# * In audit mode no condition will be defined and an error outcome class will be defined since we can not know what the command result could be.
#
# The created condition is global to the agent.
#
Expand Down