Ejemplo n.º 1
0
    def test_get_ossec_rule_filenames_2(self, ans_mock):
        """ Tests `get_ossec_rule_filenames`: should fail if response == dark or unreachable.
        """
        ans_mock.run_module.return_value = {'dark': self.sensor_ip}
        self.assertFalse(get_ossec_rule_filenames(self.sensor_ip)[0])
        ans_mock.run_module.assert_called_once()

        ans_mock.run_module.return_value = {'unreachable': True}
        self.assertFalse(get_ossec_rule_filenames(self.sensor_ip)[0])  # status is false
Ejemplo n.º 2
0
    def test_get_ossec_rule_filenames_3(self, ans_mock):
        """ Tests `get_ossec_rule_filenames`: exception raised.
        """
        err_msg = 'test err'
        ans_mock.run_module.side_effect = IOError(err_msg)
        status, result = get_ossec_rule_filenames(self.sensor_ip)

        self.assertEqual((False, err_msg), (status, result))
Ejemplo n.º 3
0
def get_ossec_rules_filenames(sensor_id):
    (ret, admin_ip) = get_sensor_ip_from_sensor_id(sensor_id)
    if not ret:
        current_app.logger.error("sensor: auth_sensor error: " + str(admin_ip))
        return make_bad_request(sensor_id)

    (success, data) = get_ossec_rule_filenames(admin_ip)
    if not success:
        current_app.logger.error("sensor: Can't get  sensor networks for  " + str(sensor_id) + " msg: " + str(data))
        return make_bad_request(sensor_id)
    else:
        return make_ok(rules=data)
Ejemplo n.º 4
0
def get_ossec_rules_filenames(sensor_id):
    (ret, admin_ip) = get_sensor_ip_from_sensor_id(sensor_id)
    if not ret:
        current_app.logger.error("sensor: auth_sensor error: " + str(admin_ip))
        return make_bad_request(sensor_id)

    (success, data) = get_ossec_rule_filenames(admin_ip)
    if not success:
        current_app.logger.error("sensor: Can't get  sensor networks for  " +
                                 str(sensor_id) + " msg: " + str(data))
        return make_bad_request(sensor_id)
    else:
        return make_ok(rules=data)
Ejemplo n.º 5
0
    def test_get_ossec_rule_filenames_1(self, ans_mock):
        """ Tests `get_ossec_rule_filenames`: should pass.
        """
        expected_list = ['rule1.xml', 'rule2.xml']
        ans_response = {
            'dark': '',
            'contacted': {
                self.sensor_ip: {
                    'stdout': '\n'.join(expected_list)}
                }
        }
        ans_mock.run_module.return_value = ans_response
        status, file_list = get_ossec_rule_filenames(self.sensor_ip)

        self.assertEqual((True, expected_list), (status, file_list))
        ans_mock.run_module.assert_called_once()