示例#1
0
    def test_openscap_xccdf_eval_success_with_failing_rules(self):
        with patch(
                'salt.modules.openscap.Popen',
                MagicMock(return_value=Mock(
                    **{
                        'returncode': 2,
                        'communicate.return_value': ('', 'some error')
                    }))):
            response = openscap.xccdf('eval --profile Default {0}'.format(
                self.policy_file))

            self.assertEqual(openscap.tempfile.mkdtemp.call_count, 1)
            expected_cmd = [
                'oscap', 'xccdf', 'eval', '--oval-results', '--results',
                'results.xml', '--report', 'report.html', '--profile',
                'Default', self.policy_file
            ]
            openscap.Popen.assert_called_once_with(
                expected_cmd,
                cwd=openscap.tempfile.mkdtemp.return_value,
                stderr=PIPE,
                stdout=PIPE)
            openscap.Caller().cmd.assert_called_once_with(
                'cp.push_dir', self.random_temp_dir)
            self.assertEqual(openscap.shutil.rmtree.call_count, 1)
            self.assertEqual(
                response, {
                    'upload_dir': self.random_temp_dir,
                    'error': 'some error',
                    'success': True,
                    'returncode': 2
                })
示例#2
0
    def test_openscap_xccdf_eval_success(self):
        response = openscap.xccdf(
            'eval --profile Default {0}'.format(self.policy_file))

        self.assertEqual(openscap.tempfile.mkdtemp.call_count, 1)
        expected_cmd = [
            'oscap',
            'xccdf',
            'eval',
            '--oval-results',
            '--results', 'results.xml',
            '--report', 'report.html',
            '--profile', 'Default',
            self.policy_file
        ]
        openscap.Popen.assert_called_once_with(
            expected_cmd,
            cwd=openscap.tempfile.mkdtemp.return_value,
            stderr=PIPE,
            stdout=PIPE)
        openscap.Caller().cmd.assert_called_once_with(
            'cp.push_dir', self.random_temp_dir)
        self.assertEqual(openscap.shutil.rmtree.call_count, 1)
        self.assertEqual(
            response,
            {
                'upload_dir': self.random_temp_dir,
                'error': '',
                'success': True,
                'returncode': 0
            }
        )