def test_mysqllogger(self): """ Objective: Test if events can be stored to and retrieved from mysql properly. """ # instanciate our mysql logging infrastructure host = '127.0.0.1' port = 3306 username = '******' passphrase = '' db = 'conpot_unittest' logdevice = '' logsocket = 'tcp' sensorid = 'default' mysqllogger = MySQLlogger(host, port, db, username, passphrase, logdevice, logsocket, sensorid) # create a test event test_event = {} test_event['id'] = 1337 test_event['remote'] = "127.0.0.2" test_event['data_type'] = "unittest" test_event['data'] = {'request': 'foo', 'response': 'bar'} # lets do it, but do not retry in case of failure success = mysqllogger.log(test_event, 0) self.assertTrue(success, 'Could not log to mysql database') # now that we logged something, lets try to retrieve the event again.. retrieved_event = mysqllogger.select_session_data(test_event['id']) self.assertEqual(len(retrieved_event), 1, 'Retrieved wrong number of events (or no event at all)')
def test_mysqllogger(self): """ Objective: Test if events can be stored to and retrieved from mysql properly. """ # instanciate our mysql logging infrastructure host = "127.0.0.1" port = 3306 username = "******" passphrase = "" db = "conpot_unittest" logdevice = "" logsocket = "tcp" sensorid = "default" mysqllogger = MySQLlogger( host, port, db, username, passphrase, logdevice, logsocket, sensorid ) # create a test event test_event = dict() test_event["id"] = 1337 test_event["remote"] = "127.0.0.2" test_event["data_type"] = "unittest" test_event["data"] = {"request": "foo", "response": "bar"} # lets do it, but do not retry in case of failure success = mysqllogger.log(test_event, 0) self.assertTrue(success, "Could not log to mysql database") # now that we logged something, lets try to retrieve the event again.. retrieved_event = mysqllogger.select_session_data(test_event["id"]) self.assertEqual( len(retrieved_event), 1, "Retrieved wrong number of events (or no event at all)", )