inspec/test/functional/inspec_audit_log_test.rb

45 lines
1.9 KiB
Ruby
Raw Normal View History

CHEF-6440: Integrates audit logging feature (#6809) * Adds cli options to enable audit log and configure the audit log Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Updated code to validate the audit log options. Audit log options are only valid for inspec exec and inspec shell command as those commands use the backend to execute commands and for file operations Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Updates cli options documentation for audit log options Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Disable audit log in test environment unless and until explicitly --enable-audit-log option is provided in test Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Rename enable-audit-log cli option to disable-audit-log Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * CHEF-8210 Enables feature preview flag for audit logging Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Revert "Disable audit log in test environment unless and until explicitly --enable-audit-log option is provided in test" This reverts commit 50a42f0b44cf2fde6d927a00e444370cdd288a5d. * Adds functional test for audit logging feature Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Updates cli doc for audit loggin feature flag Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Debug why audit log functional test fails in ci environment Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Revert "Rename enable-audit-log cli option to disable-audit-log" This reverts commit d5169ec70539342ad476c409500a9fc0a5a5b404. * Revert "Debug why audit log functional test fails in ci environment" This reverts commit 6f43898ad06b317954260d0f643dcd00312f2bc3. * Removes the --enable-audit-log option from cli as feature flag will handle the enabling and disabling of audit log feature. And introduces few code changes after reverting renaming of --enable-audit-log option Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Updates the functional test for audit log Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * REVERT THIS ONCE THE TEST IS GREEN: This is just to test implementation of audit log against the train changes made for audit log Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Removes the right one Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Documentation for inspec audit logging feature Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Renames inspec audit log file Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Edits to audit log docs Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com> * Remove --audit-log-rotation and --audit-log-size option to set from CLI Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Make sure we delete audit log file before running each test Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Appends timestamp and process id to generate audit log file per invocation/execution Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Updates functional test for audit logging feature Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Fix typo in audit logging docs Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Appends the timestamp and process id to user provided audit log file so that unique audit log file created per invocation Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Updates the audit log functional test Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Minor code improvements Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Adds exception class for invalid audit log options Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Revert "REVERT THIS ONCE THE TEST IS GREEN: This is just to test implementation of audit log against the train changes made for audit log" This reverts commit a66137e70b08134a54c51beb4ed7895a944ff17e. * Upgrade train-core version pinning Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Docs review Signed-off-by: Ian Maddaus <ian.maddaus@progress.com> * Fix titles Signed-off-by: Ian Maddaus <ian.maddaus@progress.com> * Update the signature for features.yaml file Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> --------- Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com> Signed-off-by: Ian Maddaus <ian.maddaus@progress.com> Co-authored-by: Clinton Wolfe <clintoncwolfe@gmail.com> Co-authored-by: Ian Maddaus <ian.maddaus@progress.com>
2023-11-09 15:28:12 +00:00
require "functional/helper"
describe "inspec audit log feature" do
parallelize_me!
include FunctionalHelper
before do
FileUtils.rm_f Dir.glob("#{Inspec.log_dir}/*")
end
after do
FileUtils.rm_f Dir.glob("#{Inspec.log_dir}/*")
end
describe "When audit logging off" do
it "should not create create audit log file in the default location when inspec exec is run" do
skip_windows!
CHEF-6440: Integrates audit logging feature (#6809) * Adds cli options to enable audit log and configure the audit log Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Updated code to validate the audit log options. Audit log options are only valid for inspec exec and inspec shell command as those commands use the backend to execute commands and for file operations Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Updates cli options documentation for audit log options Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Disable audit log in test environment unless and until explicitly --enable-audit-log option is provided in test Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Rename enable-audit-log cli option to disable-audit-log Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * CHEF-8210 Enables feature preview flag for audit logging Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Revert "Disable audit log in test environment unless and until explicitly --enable-audit-log option is provided in test" This reverts commit 50a42f0b44cf2fde6d927a00e444370cdd288a5d. * Adds functional test for audit logging feature Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Updates cli doc for audit loggin feature flag Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Debug why audit log functional test fails in ci environment Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Revert "Rename enable-audit-log cli option to disable-audit-log" This reverts commit d5169ec70539342ad476c409500a9fc0a5a5b404. * Revert "Debug why audit log functional test fails in ci environment" This reverts commit 6f43898ad06b317954260d0f643dcd00312f2bc3. * Removes the --enable-audit-log option from cli as feature flag will handle the enabling and disabling of audit log feature. And introduces few code changes after reverting renaming of --enable-audit-log option Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Updates the functional test for audit log Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * REVERT THIS ONCE THE TEST IS GREEN: This is just to test implementation of audit log against the train changes made for audit log Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Removes the right one Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Documentation for inspec audit logging feature Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Renames inspec audit log file Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Edits to audit log docs Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com> * Remove --audit-log-rotation and --audit-log-size option to set from CLI Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Make sure we delete audit log file before running each test Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Appends timestamp and process id to generate audit log file per invocation/execution Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Updates functional test for audit logging feature Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Fix typo in audit logging docs Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Appends the timestamp and process id to user provided audit log file so that unique audit log file created per invocation Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Updates the audit log functional test Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Minor code improvements Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Adds exception class for invalid audit log options Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Revert "REVERT THIS ONCE THE TEST IS GREEN: This is just to test implementation of audit log against the train changes made for audit log" This reverts commit a66137e70b08134a54c51beb4ed7895a944ff17e. * Upgrade train-core version pinning Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Docs review Signed-off-by: Ian Maddaus <ian.maddaus@progress.com> * Fix titles Signed-off-by: Ian Maddaus <ian.maddaus@progress.com> * Update the signature for features.yaml file Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> --------- Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com> Signed-off-by: Ian Maddaus <ian.maddaus@progress.com> Co-authored-by: Clinton Wolfe <clintoncwolfe@gmail.com> Co-authored-by: Ian Maddaus <ian.maddaus@progress.com>
2023-11-09 15:28:12 +00:00
cli_args = "--audit-log-location #{Inspec.log_dir}/inspec-test-audit.log"
run_result = run_inspec_process("exec " + File.join(profile_path, "basic_profile") + " " + cli_args)
_(run_result.exit_status).must_equal 0
_(Dir.glob("#{Inspec.log_dir}/*").count).must_equal 0
end
end
describe "When audit logging on" do
it "should create audit log file in the default location when inspec exec is run" do
skip_windows!
CHEF-6440: Integrates audit logging feature (#6809) * Adds cli options to enable audit log and configure the audit log Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Updated code to validate the audit log options. Audit log options are only valid for inspec exec and inspec shell command as those commands use the backend to execute commands and for file operations Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Updates cli options documentation for audit log options Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Disable audit log in test environment unless and until explicitly --enable-audit-log option is provided in test Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Rename enable-audit-log cli option to disable-audit-log Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * CHEF-8210 Enables feature preview flag for audit logging Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Revert "Disable audit log in test environment unless and until explicitly --enable-audit-log option is provided in test" This reverts commit 50a42f0b44cf2fde6d927a00e444370cdd288a5d. * Adds functional test for audit logging feature Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Updates cli doc for audit loggin feature flag Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Debug why audit log functional test fails in ci environment Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Revert "Rename enable-audit-log cli option to disable-audit-log" This reverts commit d5169ec70539342ad476c409500a9fc0a5a5b404. * Revert "Debug why audit log functional test fails in ci environment" This reverts commit 6f43898ad06b317954260d0f643dcd00312f2bc3. * Removes the --enable-audit-log option from cli as feature flag will handle the enabling and disabling of audit log feature. And introduces few code changes after reverting renaming of --enable-audit-log option Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Updates the functional test for audit log Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * REVERT THIS ONCE THE TEST IS GREEN: This is just to test implementation of audit log against the train changes made for audit log Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Removes the right one Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Documentation for inspec audit logging feature Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Renames inspec audit log file Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Edits to audit log docs Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com> * Remove --audit-log-rotation and --audit-log-size option to set from CLI Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Make sure we delete audit log file before running each test Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Appends timestamp and process id to generate audit log file per invocation/execution Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Updates functional test for audit logging feature Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Fix typo in audit logging docs Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Appends the timestamp and process id to user provided audit log file so that unique audit log file created per invocation Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Updates the audit log functional test Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Minor code improvements Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Adds exception class for invalid audit log options Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Revert "REVERT THIS ONCE THE TEST IS GREEN: This is just to test implementation of audit log against the train changes made for audit log" This reverts commit a66137e70b08134a54c51beb4ed7895a944ff17e. * Upgrade train-core version pinning Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Docs review Signed-off-by: Ian Maddaus <ian.maddaus@progress.com> * Fix titles Signed-off-by: Ian Maddaus <ian.maddaus@progress.com> * Update the signature for features.yaml file Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> --------- Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com> Signed-off-by: Ian Maddaus <ian.maddaus@progress.com> Co-authored-by: Clinton Wolfe <clintoncwolfe@gmail.com> Co-authored-by: Ian Maddaus <ian.maddaus@progress.com>
2023-11-09 15:28:12 +00:00
cli_args = "--audit-log-location #{Inspec.log_dir}/inspec-test-audit.log"
run_result = run_inspec_process("exec " + File.join(profile_path, "basic_profile") + " " + cli_args, env: { CHEF_PREVIEW_AUDIT_LOGGING: "1" })
_(run_result.exit_status).must_equal 0
_(Dir.glob("#{Inspec.log_dir}/*").count).must_equal 1
_(File.basename(Dir.glob("#{Inspec.log_dir}/*")[0])).must_match(/inspec-test-audit-\d{4}\d{2}\d{2}T\d{2}\d{2}\d{2}-\b\d+\b.log/)
end
it "should create audit log file in the default location when inspec shell is run" do
skip_windows!
CHEF-6440: Integrates audit logging feature (#6809) * Adds cli options to enable audit log and configure the audit log Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Updated code to validate the audit log options. Audit log options are only valid for inspec exec and inspec shell command as those commands use the backend to execute commands and for file operations Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Updates cli options documentation for audit log options Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Disable audit log in test environment unless and until explicitly --enable-audit-log option is provided in test Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Rename enable-audit-log cli option to disable-audit-log Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * CHEF-8210 Enables feature preview flag for audit logging Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Revert "Disable audit log in test environment unless and until explicitly --enable-audit-log option is provided in test" This reverts commit 50a42f0b44cf2fde6d927a00e444370cdd288a5d. * Adds functional test for audit logging feature Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Updates cli doc for audit loggin feature flag Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Debug why audit log functional test fails in ci environment Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Revert "Rename enable-audit-log cli option to disable-audit-log" This reverts commit d5169ec70539342ad476c409500a9fc0a5a5b404. * Revert "Debug why audit log functional test fails in ci environment" This reverts commit 6f43898ad06b317954260d0f643dcd00312f2bc3. * Removes the --enable-audit-log option from cli as feature flag will handle the enabling and disabling of audit log feature. And introduces few code changes after reverting renaming of --enable-audit-log option Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Updates the functional test for audit log Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * REVERT THIS ONCE THE TEST IS GREEN: This is just to test implementation of audit log against the train changes made for audit log Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Removes the right one Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Documentation for inspec audit logging feature Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Renames inspec audit log file Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Edits to audit log docs Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com> * Remove --audit-log-rotation and --audit-log-size option to set from CLI Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Make sure we delete audit log file before running each test Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Appends timestamp and process id to generate audit log file per invocation/execution Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Updates functional test for audit logging feature Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Fix typo in audit logging docs Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Appends the timestamp and process id to user provided audit log file so that unique audit log file created per invocation Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Updates the audit log functional test Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Minor code improvements Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Adds exception class for invalid audit log options Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Revert "REVERT THIS ONCE THE TEST IS GREEN: This is just to test implementation of audit log against the train changes made for audit log" This reverts commit a66137e70b08134a54c51beb4ed7895a944ff17e. * Upgrade train-core version pinning Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> * Docs review Signed-off-by: Ian Maddaus <ian.maddaus@progress.com> * Fix titles Signed-off-by: Ian Maddaus <ian.maddaus@progress.com> * Update the signature for features.yaml file Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> --------- Signed-off-by: Vasu1105 <vasundhara.jagdale@progress.com> Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com> Signed-off-by: Ian Maddaus <ian.maddaus@progress.com> Co-authored-by: Clinton Wolfe <clintoncwolfe@gmail.com> Co-authored-by: Ian Maddaus <ian.maddaus@progress.com>
2023-11-09 15:28:12 +00:00
cli_args = " --audit-log-location #{Inspec.log_dir}/inspec-test-audit.log"
run_result = run_inspec_process("shell " + " " + cli_args, env: { CHEF_PREVIEW_AUDIT_LOGGING: "1" })
_(run_result.exit_status).must_equal 0
_(Dir.glob("#{Inspec.log_dir}/*").count).must_equal 1
_(File.basename(Dir.glob("#{Inspec.log_dir}/*")[0])).must_match(/inspec-test-audit-\d{4}\d{2}\d{2}T\d{2}\d{2}\d{2}-\b\d+\b.log/)
end
end
end