Exemple #1
0
    def test_execute2(self, isfile_mock):
        """
        positive case with cast_to_string set to true.
        Test should pass
        """
        def _mock_osquery(cmd, timeout, python_shell):
            return {
                'pid': 1,
                'retcode': 0,
                'stdout': '[\n{"count": 1}\n]',
                'stderr': ''
            }

        isfile_mock.return_value = True
        osquery.__grains__ = {'osquerybinpath': 'dummy path'}
        osquery.__mods__ = {'cmd.run_all': _mock_osquery}
        block_dict = {
            "args": {
                "query": "sample query",
                "cast_to_string": True
            }
        }
        check_id = "test-5"
        status, res = osquery.execute(check_id, block_dict, {})
        self.assertTrue(status)
        self.assertEqual(res, {'result': [{'count': '1'}]})
Exemple #2
0
    def test_execute3(self):
        """
        negative case. Osquery binary not found
        Test should fail
        """
        def _mock_osquery(cmd, timeout, python_shell):
            return {
                'pid': 1,
                'retcode': 0,
                'stdout': '[\n{"count": 1}\n]',
                'stderr': ''
            }

        osquery.__grains__ = {'osquerybinpath': 'dummy path'}
        osquery.__mods__ = {'cmd.run_all': _mock_osquery}
        block_dict = {"args": {"query": "sample query"}}
        check_id = "test-6"
        status, res = osquery.execute(check_id, block_dict, {})
        self.assertFalse(status)