def setUp(self): app.app.config['WTF_CSRF_ENABLED'] = False app.app.config['CERT_PATH'] = os.path.join(os.path.dirname(__file__), 'beeswarmcfg.json.test') app.app.config['SERVER_CONFIG'] = os.path.join(os.path.dirname(__file__), 'beeswarmcfg.json.test') self.app = app.app.test_client() self.authenticator = Authenticator() database.setup_db('sqlite://') session = database.get_session() #dummy entities self.authenticator.add_user('test', 'test', 0) self.client_id = str(uuid.uuid4()) self.client_password = str(uuid.uuid4()) self.authenticator.add_user(self.client_id, self.client_password, 2) self.honeypot_id = str(uuid.uuid4()) self.honeypot_password = str(uuid.uuid4()) self.authenticator.add_user(self.honeypot_id, self.honeypot_password, 1) session.add_all([Client(id=self.client_id, configuration='test_client_config'), Honeypot(id=self.honeypot_id, configuration='test_honeypot_config') ]) session.commit()
def setUp(self): #'sqlite://' gives a in-memory sqlite database database.setup_db('sqlite://') self.client_id = str(uuid.uuid4()) self.honeypot_id = str(uuid.uuid4()) self.bait_session_id = str(uuid.uuid4()) self.bait_session_datetime = datetime.utcnow() db_session = database.get_session() client = Client(id=self.client_id) honeypot = Honeypot(id=self.honeypot_id) bait_session = BaitSession(id=self.bait_session_id, source_ip='321', destination_ip='123', received=datetime.utcnow(), timestamp=self.bait_session_datetime, protocol='pop3', source_port=1, destination_port=1, did_complete=True, client=client, honeypot=honeypot) authentication = Authentication(id=str(uuid.uuid4()), username='******', password='******', successful=True, timestamp=datetime.utcnow()) bait_session.authentication.append(authentication) db_session.add_all([client, honeypot, bait_session]) db_session.commit()
sessions.append(session) while len(sessions) < 200: session = Session(id=str(uuid.uuid4()), timestamp=datetime.now(), source_ip=random.choice(source_ips), source_port=random.randint(1024, 65535), destination_ip='4.3.2.1', destination_port='1111') session.protocol, session.destination_port = random.choice(protocols) session.honeypot = random.choice(honeypots) session.classification = db_session.query(Classification).filter(Classification.type == 'credentials_reuse').one() username = ''.join(random.choice(string.lowercase) for x in range(8)) password = ''.join(random.choice(string.lowercase) for x in range(8)) authentication = Authentication(id=str(uuid.uuid4()), username=username, password=password) session.authentication.append(authentication) authentications.append(authentication) sessions.append(session) db_session.add_all(authentications) db_session.add_all(sessions) db_session.add_all(honeypots) db_session.add_all(client) db_session.commit() if __name__ == '__main__': database.setup_db('sqlite:///server_sqlite.db') fill_dummy_data()