def test_omit_symbolic_name(InsightsCommand, InsightsFile, parse_file_spec): """ Files/commands are omitted based on their symbolic name in uploader.json """ c = InsightsConfig() data_collector = DataCollector(c) collection_rules = { 'files': [{ "file": "/etc/pam.d/vsftpd", "pattern": [], "symbolic_name": "vsftpd" }], 'commands': [{ "command": "/sbin/chkconfig --list", "pattern": [], "symbolic_name": "chkconfig" }], 'pre_commands': [] } rm_conf = {'files': ["vsftpd"], "commands": ["chkconfig"]} data_collector.run_collection(collection_rules, rm_conf, {}, '') parse_file_spec.assert_not_called() InsightsFile.assert_not_called() InsightsCommand.assert_not_called()
def test_symbolic_name_bc(_, InsightsArchive, InsightsFile, InsightsCommand): """ WICKED EDGE CASE: in case uploader.json is old and doesn't have symbolic names, don't crash """ c = InsightsConfig() data_collector = DataCollector(c) collection_rules = { 'files': [{ "file": "/etc/pam.d/vsftpd", "pattern": [] }], 'commands': [{ "command": "/sbin/chkconfig --list", "pattern": [] }], 'pre_commands': [] } rm_conf = {'files': ["vsftpd"], "commands": ["chkconfig"]} data_collector.run_collection(collection_rules, rm_conf, {}, {}) InsightsFile.assert_called_once() InsightsCommand.assert_called_once() InsightsArchive.return_value.add_to_archive.assert_has_calls( [call(InsightsFile.return_value), call(InsightsCommand.return_value)], any_order=True)
def test_read_pidfile_called(read_pidfile): ''' Pidfile is read when collection starts ''' dc = DataCollector(MagicMock(display_name=None)) dc.run_collection({'commands': [], 'files': []}, None, None, '') read_pidfile.assert_called_once()
def test_omit_after_parse_command(InsightsCommand, run_pre_command): """ Files are omitted based on the expanded paths of the uploader.json path """ c = InsightsConfig() data_collector = DataCollector(c) collection_rules = {'commands': [{"command": "/sbin/ethtool -i", "pattern": [], "pre_command": "iface", "symbolic_name": "ethtool"}], 'files': [], "pre_commands": {"iface": "/sbin/ip -o link | awk -F ': ' '/.*link\\/ether/ {print $2}'"}} rm_conf = {'commands': ["/sbin/ethtool -i eth0"]} data_collector.run_collection(collection_rules, rm_conf, {}) InsightsCommand.assert_not_called()
def test_omit_before_expanded_paths(InsightsFile, parse_file_spec): """ Files are omitted based on representation of exact string matching in uploader.json """ c = InsightsConfig() data_collector = DataCollector(c) collection_rules = {'files': [{"file": "/etc/pam.d/vsftpd", "pattern": [], "symbolic_name": "vsftpd"}], 'commands': {}} rm_conf = {'files': ["/etc/pam.d/vsftpd"]} data_collector.run_collection(collection_rules, rm_conf, {}) parse_file_spec.assert_not_called() InsightsFile.assert_not_called()
def test_omit_after_expanded_paths(InsightsFile, parse_file_spec): """ Files are omitted based on the expanded paths of the uploader.json path """ c = InsightsConfig() data_collector = DataCollector(c) collection_rules = {'files': [{"file": "/etc/yum.repos.d/()*.*\\.repo", "pattern": [], "symbolic_name": "yum_repos_d"}], 'commands': {}} rm_conf = {'files': ["/etc/yum/repos.d/test.repo"]} data_collector.run_collection(collection_rules, rm_conf, {}) parse_file_spec.assert_called_once() InsightsFile.assert_not_called()
def test_redact_called_classic(redact): ''' Verify that redact is always called during classic collection ''' conf = InsightsConfig() upload_conf = {'commands': [], 'files': [], 'globs': []} rm_conf = {'test': 'test'} branch_info = {'test1': 'test2'} blacklist_report = {'test3': 'test4'} dc = DataCollector(conf) dc.run_collection(upload_conf, rm_conf, branch_info, blacklist_report) redact.assert_called_once_with(rm_conf)
def test_run_collection_logs_skipped_commands_by_symbolic_name(warn): c = InsightsConfig() data_collector = DataCollector(c) collection_rules = { 'commands': [{ 'command': '/bin/date', 'pattern': [], 'symbolic_name': 'date' }], 'files': [], 'globs': [] } rm_conf = {'commands': ["date"]} data_collector.run_collection(collection_rules, rm_conf, {}, '') warn.assert_called_once_with("WARNING: Skipping command %s", "/bin/date")
def test_run_collection_logs_skipped_files_by_symbolic_name(warn): c = InsightsConfig() data_collector = DataCollector(c) collection_rules = { 'commands': [], 'files': [{ 'file': '/etc/machine-id', 'pattern': [], 'symbolic_name': 'etc_machine_id' }], 'globs': [] } rm_conf = {'files': ["etc_machine_id"]} data_collector.run_collection(collection_rules, rm_conf, {}, '') warn.assert_called_once_with("WARNING: Skipping file %s", "/etc/machine-id")
def test_run_collection_logs_skipped_globs(warn, parse_glob_spec): c = InsightsConfig() data_collector = DataCollector(c) collection_rules = { 'commands': [], 'files': [], 'globs': [{ 'glob': '/etc/yum.repos.d/*.repo', 'symbolic_name': 'yum_repos_d', 'pattern': [] }] } rm_conf = {'files': ["/etc/yum.repos.d/test.repo"]} data_collector.run_collection(collection_rules, rm_conf, {}, '') warn.assert_called_once_with("WARNING: Skipping file %s", "/etc/yum.repos.d/test.repo")
def test_run_collection_logs_skipped_files_by_wildcard(warn, parse_file_spec): c = InsightsConfig() data_collector = DataCollector(c) collection_rules = { 'commands': [], 'files': [{ 'file': '/etc/sysconfig/network-scripts/()*ifcfg-.*', 'pattern': [], 'symbolic_name': 'ifcfg' }], 'globs': [] } rm_conf = {'files': ["/etc/sysconfig/network-scripts/ifcfg-enp0s3"]} data_collector.run_collection(collection_rules, rm_conf, {}, '') warn.assert_called_once_with( "WARNING: Skipping file %s", "/etc/sysconfig/network-scripts/ifcfg-enp0s3")
def test_run_collection_logs_skipped_commands_by_pre_command( warn, parse_command_spec): c = InsightsConfig() data_collector = DataCollector(c) collection_rules = { 'commands': [{ 'command': '/sbin/ethtool', 'pattern': [], 'pre_command': 'iface', 'symbolic_name': 'ethtool' }], 'files': [], 'globs': [], 'pre_commands': { 'iface': '/sbin/ip -o link | awk -F \': \' \'/.*link\\/ether/ {print $2}\'' } } rm_conf = {'commands': ["/sbin/ethtool enp0s3"]} data_collector.run_collection(collection_rules, rm_conf, {}, '') warn.assert_called_once_with("WARNING: Skipping command %s", "/sbin/ethtool enp0s3")