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 }
2827EXAMPLE_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
3339class 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
6979if __name__ == '__main__' : # pragma: no cover
0 commit comments