from feedCtrl.uiFunctionsHandler import UiFunctionHandler from feedCtrl.uiFunctionsHandler import generate_test_data # noqa: F401 from logStore.verific.verify_insertion import Verification # noqa: F401 from logStore.funcs.EventCreationTool import EventFactory # noqa: F401 from logStore.appconn.feed_ctrl_connection import FeedCtrlConnection # noqa: F401 import secrets from nacl.signing import SigningKey from logStore.funcs.log import create_logger import sys logger = create_logger('test_feed_ctrl_connection') class bcolors: TRUSTED = '\033[32m' BLOCKED = '\033[91m' ENDC = '\033[0m' def split_inp(inp): _inp = inp.split(" ") return _inp def cli(): running = True # CLI test ufh = UiFunctionHandler()
from testfixtures import LogCapture import os from contextlib import contextmanager from logStore.appconn.chat_connection import ChatFunction from logStore.funcs.EventCreationTool import EventFactory from logStore.funcs.log import create_logger logger = create_logger('test_chat_connection') def test_get_chat_event(): with session_scope(): with LogCapture() as log_cap: ecf = EventFactory() cf = ChatFunction() new_event = ecf.next_event('MASTER/MASTER', {}) cf.insert_event(new_event) feed = EventFactory() feed2 = EventFactory() feed3 = EventFactory() new_event = feed.next_event('chat/MASTER', {'master_feed': ecf.get_feed_id()}) cf.insert_event(new_event) new_event = feed2.next_event('chat/MASTER', {'master_feed': ecf.get_feed_id()}) cf.insert_event(new_event)
from logStore.appconn.feed_ctrl_connection import FeedCtrlConnection from logStore.funcs.log import create_logger logger = create_logger('Radius') class Radius: def __init__(self): self._fcc = FeedCtrlConnection() self._hostID = self._fcc.get_host_master_id() def calculate_radius(self): radius = self._fcc.get_radius() self.__check_trusted(self._hostID, radius, 'MASTER') def __check_trusted( self, master_id, radius, prev_app_name, step=1, ): if radius and step is not None: if radius < 1 or step > radius: return trusted = self._fcc.get_trusted(master_id) if not len(trusted) == 0: for trusted_id in trusted: application_name = self._fcc.get_application_name( trusted_id) master = None
import secrets # Comes with python from contextlib import contextmanager import os from nacl.signing import SigningKey from logStore.funcs.log import create_logger from logStore.verific.verify_insertion import Verification from logStore.funcs.EventCreationTool import EventFactory from logStore.appconn.feed_ctrl_connection import FeedCtrlConnection logger = create_logger('test_verify_insertion') class TestVerification: """Tests if incoming master_ids is accepted""" def test_incoming_master(self): with session_scope(): master_id = generate_random_feed_id() ver = Verification() result = ver.check_incoming(master_id, 'MASTER') assert result is True """Tests if incoming trusted feed_id is accepted""" def test_incoming_trusted(self): with session_scope(): ver = Verification() ecf = EventFactory() new_event = ecf.next_event('MASTER/MASTER', {}) fcc = FeedCtrlConnection() fcc.add_event(new_event) trust_id1 = generate_random_feed_id()
import hashlib # Comes with python import secrets # Comes with python from nacl.signing import SigningKey from testfixtures import LogCapture from contextlib import contextmanager import os from logStore.funcs.event import Content, Event, Meta from logStore.transconn.database_connector import DatabaseConnector from logStore.funcs.EventCreationTool import EventFactory from logStore.funcs.log import create_logger logger = create_logger('test_database_connector') def test_event_factory(): ecf = EventFactory() new_event = ecf.next_event('whateverapp/whateveraction', { 'oneKey': 'somevalue', 'someotherkey': 1 }) connector = DatabaseConnector( path_to_db= 'C:\\Users\\user\\Google Drive\\Studies\\4. Semester\\30526-01 - Introduction to Internet and Security\\Project\\BACnet\\groups\\07-logStore' ) connector.add_event(new_event) result = connector.get_current_event(ecf.get_feed_id()) result = Event.from_cbor(result) assert result.content.content[0] == 'whateverapp/whateveraction' def test_get_current_event():