Skip to content
Snippets Groups Projects
Commit c9f73188 authored by Rajmund Hruška's avatar Rajmund Hruška
Browse files

Fix: Check GeoIP locations from config file. (Redmine issue: #7539)

parent 46ed419d
No related branches found
No related tags found
No related merge requests found
......@@ -25,7 +25,7 @@ from unittest.mock import call
#
from mentat.daemon.component.testsuite import DaemonComponentTestCase
from mentat.daemon.component.enricher import EnricherDaemonComponent
from mentat.const import CKEY_CORE_SERVICES, CKEY_CORE_SERVICES_GEOIP
#-------------------------------------------------------------------------------
# NOTE: Sorry for the long lines in this file. They are deliberate, because the
......@@ -84,6 +84,9 @@ class TestMentatDaemonEnricher(DaemonComponentTestCase):
# Setup daemon component.
self.component.setup(daemon)
asndb = daemon.config[CKEY_CORE_SERVICES][CKEY_CORE_SERVICES_GEOIP]['asndb']
citydb = daemon.config[CKEY_CORE_SERVICES][CKEY_CORE_SERVICES_GEOIP]['citydb']
config = "{'asn': '%s',\n 'city': '%s',\n 'country': None}" % (asndb, citydb)
self._verbose_print("TEST01: Daemon mock calls after component setup", daemon.mock_calls)
daemon.c.assert_has_calls([
......@@ -91,7 +94,7 @@ class TestMentatDaemonEnricher(DaemonComponentTestCase):
])
daemon.logger.assert_has_calls([
call.info("[STATUS] Component '%s': Configuring enrichment plugin '%s'.'%s'", 'enricher', 'mentat.plugin.enricher.geoip', 'GeoipEnricherPlugin'),
call.info("Initialized '%s' enricher plugin: %s", 'GeoipEnricherPlugin', "{'asn': '/usr/share/GeoIP/GeoLite2-ASN.mmdb',\n 'city': '/usr/share/GeoIP/GeoLite2-City.mmdb',\n 'country': None}"),
call.info("Initialized '%s' enricher plugin: %s", 'GeoipEnricherPlugin', config),
call.info("[STATUS] Component '%s': Configuring enrichment plugin '%s'.'%s'", 'enricher', 'mentat.plugin.enricher.logger', 'LoggerEnricherPlugin'),
call.debug("Initialized '%s' enricher plugin", 'LoggerEnricherPlugin'),
call.info("[STATUS] Component '%s': Successfully set up all enrichment plugins", 'enricher')
......
......@@ -25,6 +25,7 @@ from unittest.mock import call
#
from mentat.plugin.enricher.testsuite import MentatEnricherPluginTestCase
from mentat.plugin.enricher.geoip import GeoipEnricherPlugin
from mentat.const import CKEY_CORE_SERVICES, CKEY_CORE_SERVICES_GEOIP
#-------------------------------------------------------------------------------
......@@ -56,10 +57,13 @@ class TestMentatGeoipEnricherPlugin(MentatEnricherPluginTestCase):
mapplication = self._build_application_mock([])
self.plugin.setup(mapplication)
asndb = mapplication.config[CKEY_CORE_SERVICES][CKEY_CORE_SERVICES_GEOIP]['asndb']
citydb = mapplication.config[CKEY_CORE_SERVICES][CKEY_CORE_SERVICES_GEOIP]['citydb']
config = "{'asn': '%s',\n 'city': '%s',\n 'country': None}" % (asndb, citydb)
self._verbose_print("TEST01: daemon mock calls after plugin 'setup'", mapplication.mock_calls)
mapplication.assert_has_calls([
call.logger.info("Initialized '%s' enricher plugin: %s", 'GeoipEnricherPlugin', "{'asn': '/usr/share/GeoIP/GeoLite2-ASN.mmdb',\n 'city': '/usr/share/GeoIP/GeoLite2-City.mmdb',\n 'country': None}")
call.logger.info("Initialized '%s' enricher plugin: %s", 'GeoipEnricherPlugin', config)
])
def test_02_process_01(self):
......@@ -76,10 +80,6 @@ class TestMentatGeoipEnricherPlugin(MentatEnricherPluginTestCase):
}
self.plugin.setup(mapplication)
mapplication.assert_has_calls([
call.logger.info("Initialized '%s' enricher plugin: %s", 'GeoipEnricherPlugin', "{'asn': '/usr/share/GeoIP/GeoLite2-ASN.mmdb',\n 'city': '/usr/share/GeoIP/GeoLite2-City.mmdb',\n 'country': None}"),
])
mapplication.reset_mock()
result = self.plugin.process(mapplication, 'msgid', msg)
self._verbose_print("TEST02: daemon mock calls after plugin 'setup'", mapplication.mock_calls)
......@@ -114,10 +114,6 @@ class TestMentatGeoipEnricherPlugin(MentatEnricherPluginTestCase):
}
self.plugin.setup(mapplication)
mapplication.assert_has_calls([
call.logger.info("Initialized '%s' enricher plugin: %s", 'GeoipEnricherPlugin', "{'asn': '/usr/share/GeoIP/GeoLite2-ASN.mmdb',\n 'city': '/usr/share/GeoIP/GeoLite2-City.mmdb',\n 'country': None}"),
])
mapplication.reset_mock()
result = self.plugin.process(mapplication, 'msgid', msg)
self._verbose_print("TEST02: daemon mock calls after plugin 'setup'", mapplication.mock_calls)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment