Skip to content

Commit ff92f9f

Browse files
author
Sebastian Wagner
committed
Merge remote-tracking branch 'upstream/pr/1674' into develop
2 parents 19490b9 + 57c430e commit ff92f9f

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

intelmq/bots/parsers/generic/parser_csv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def parse_line(self, row, report):
131131
value = self.type_translation[value]
132132
elif not hasattr(self.parameters, 'type'):
133133
continue
134-
if event.add(key, value, raise_failure=False):
134+
if event.add(key, value, raise_failure=False) is not False:
135135
break
136136
else:
137137
# if the value sill remains unadded we need to inform if the key is needed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
01/Aug/2018:09:49:41 +0200,127.0.0.1,-
2-
01/Aug/2018:09:49:41 +0200,127.0.0.1,example.com
2+
01/Aug/2018:09:49:41 +0200,127.0.0.1,example.com
3+
01/Aug/2018:09:49:41 +0200,-,example.com
4+
01/Aug/2018:09:49:41 +0200,127.0.0.1,.

intelmq/tests/bots/parsers/generic/test_parser_csv_invalid_values.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,20 @@
2121
"time.source": "2018-08-01T07:49:41+00:00",
2222
"classification.type": "malware",
2323
"source.ip": "127.0.0.1",
24-
"source.fqdn": "example.com",
25-
"raw": utils.base64_encode(SAMPLE_SPLIT[1]+'\r\n'),
24+
"raw": utils.base64_encode(SAMPLE_SPLIT[0]+'\r\n'),
2625
"time.observation": "2015-01-01T00:00:00+00:00",
2726
}
2827
EXAMPLE_EVENT2 = EXAMPLE_EVENT.copy()
29-
del EXAMPLE_EVENT2['source.fqdn']
30-
EXAMPLE_EVENT2["raw"] = utils.base64_encode(SAMPLE_SPLIT[0]+'\r\n')
28+
EXAMPLE_EVENT2['source.fqdn'] = "example.com"
29+
EXAMPLE_EVENT2["raw"] = utils.base64_encode(SAMPLE_SPLIT[1]+'\r\n')
3130

31+
EXAMPLE_EVENT3 = EXAMPLE_EVENT.copy()
32+
del EXAMPLE_EVENT3['source.ip']
33+
EXAMPLE_EVENT3['source.fqdn'] = "example.com"
34+
EXAMPLE_EVENT3["raw"] = utils.base64_encode(SAMPLE_SPLIT[2]+'\r\n')
35+
36+
EXAMPLE_EVENT4 = EXAMPLE_EVENT.copy()
37+
EXAMPLE_EVENT4["raw"] = utils.base64_encode(SAMPLE_SPLIT[3]+'\r\n')
3238

3339
class TestGenericCsvParserBot(test.BotTestCase, unittest.TestCase):
3440
"""
@@ -45,13 +51,15 @@ def set_bot(cls):
4551
"type": "malware",
4652
"default_url_protocol": "http://"}
4753

48-
def test_error(self):
54+
def test_invalid_value(self):
4955
""" Test if the error is raised. """
50-
self.allowed_error_count = 1
51-
self.run_bot()
56+
self.run_bot(allowed_error_count=1)
57+
5258
self.assertMessageEqual(0, EXAMPLE_EVENT)
59+
self.assertMessageEqual(1, EXAMPLE_EVENT2)
60+
self.assertMessageEqual(2, EXAMPLE_EVENT3)
5361
self.assertLogMatches("Failed to parse line.")
54-
self.assertLogMatches("intelmq.lib.exceptions.InvalidValue: invalid value '-' \(<class 'str'>\) for key 'source.fqdn'")
62+
self.assertLogMatches("intelmq.lib.exceptions.InvalidValue: invalid value '.' \(<class 'str'>\) for key 'source.fqdn'")
5563

5664
def test_error_ignore(self):
5765
self.sysconfig = {"columns": ["time.source", "source.ip",
@@ -61,9 +69,11 @@ def test_error_ignore(self):
6169
"default_url_protocol": "http://",
6270
"columns_required": [True, True, False],
6371
}
64-
self.run_bot()
65-
self.assertMessageEqual(0, EXAMPLE_EVENT2)
66-
self.assertMessageEqual(1, EXAMPLE_EVENT)
72+
self.run_bot(allowed_error_count=1)
73+
self.assertMessageEqual(0, EXAMPLE_EVENT)
74+
self.assertMessageEqual(1, EXAMPLE_EVENT2)
75+
self.assertMessageEqual(2, EXAMPLE_EVENT3)
76+
self.assertMessageEqual(3, EXAMPLE_EVENT4)
6777

6878

6979
if __name__ == '__main__': # pragma: no cover

0 commit comments

Comments
 (0)