def setUp(self): """Makes preparations before running an individual test.""" output_mediator = self._CreateOutputMediator() self._output_writer = cli_test_lib.TestOutputWriter() self._formatter = l2t_csv.L2TCSVOutputModule(output_mediator) self._formatter.SetOutputWriter(self._output_writer) self._event_object = L2TTestEvent()
def testWriteEventBody(self): """Tests the WriteEventBody function.""" test_file_object = io.StringIO() output_mediator = self._CreateOutputMediator() formatters_directory_path = self._GetTestFilePath(['formatters']) output_mediator.ReadMessageFormattersFromDirectory( formatters_directory_path) output_module = l2t_csv.L2TCSVOutputModule(output_mediator) output_module._file_object = test_file_object event, event_data, event_data_stream = ( containers_test_lib.CreateEventFromValues(self._TEST_EVENTS[0])) event_tag = events.EventTag() event_tag.AddLabels(['Malware', 'Printed']) output_module.WriteEventBody( event, event_data, event_data_stream, event_tag) expected_event_body = ( '06/27/2012,18:17:01,UTC,M...,FILE,Test log file,Content Modification ' 'Time,-,ubuntu,Reporter <CRON> PID: 8442 (pam_unix(cron:session): ' 'session closed for user root),Reporter <CRON> PID: 8442 ' '(pam_unix(cron:session): session closed for user root),' '2,FAKE:log/syslog.1,-,Malware Printed,test_parser,a_binary_field: ' 'binary; my_number: 123; some_additional_foo: True\n') event_body = test_file_object.getvalue() self.assertEqual(event_body, expected_event_body) # Ensure that the only commas returned are the 16 delimiters. self.assertEqual(event_body.count(','), 16)
def setUp(self): """Sets up the objects needed for this test.""" output_mediator = self._CreateOutputMediator() self._output_writer = cli_test_lib.TestOutputWriter() self.formatter = l2t_csv.L2TCSVOutputModule(output_mediator) self.formatter.SetOutputWriter(self._output_writer) self.event_object = L2tTestEvent()
def testWriteHeader(self): """Tests the WriteHeader function.""" test_file_object = io.StringIO() output_mediator = self._CreateOutputMediator() output_module = l2t_csv.L2TCSVOutputModule(output_mediator) output_module._file_object = test_file_object output_module.WriteHeader() expected_header = ( 'date,time,timezone,MACB,source,sourcetype,type,user,host,short,desc,' 'version,filename,inode,notes,format,extra\n') header = test_file_object.getvalue() self.assertEqual(header, expected_header)