コード例 #1
0
def test_get_trusted():
    with session_scope():
        ecf = EventFactory()
        new_event = ecf.next_event('MASTER/MASTER', {})
        fcc = FeedCtrlConnection()
        fcc.add_event(new_event)
        trust_id1 = generate_random_feed_id()
        new_event = ecf.next_event('MASTER/Trust', {'feed_id': trust_id1})
        fcc.add_event(new_event)
        trust_id2 = generate_random_feed_id()
        new_event = ecf.next_event('MASTER/Trust', {'feed_id': trust_id2})
        fcc.add_event(new_event)
        trust_id3 = generate_random_feed_id()
        new_event = ecf.next_event('MASTER/Trust', {'feed_id': trust_id3})
        fcc.add_event(new_event)
        trust_id4 = generate_random_feed_id()
        new_event = ecf.next_event('MASTER/Name', {'name': trust_id4})
        fcc.add_event(new_event)
        trust_id4 = generate_random_feed_id()
        new_event = ecf.next_event('MASTER/NewFeed', {
            'feed_id': trust_id4,
            'app_name': 'TestApp'
        })
        fcc.add_event(new_event)
        new_event = ecf.next_event('MASTER/Radius', {'radius': 5})
        fcc.add_event(new_event)
        result = fcc.get_trusted(ecf.get_feed_id())
        assert result[0] == trust_id1
        assert result[1] == trust_id2
        assert result[2] == trust_id3
        assert len(result) == 3
コード例 #2
0
 def test_incoming_not_trusted(self):
     with session_scope():
         ecf = EventFactory()
         ver = Verification()
         new_event = ecf.next_event('MASTER/MASTER', {})
         fcc = FeedCtrlConnection()
         fcc.add_event(new_event)
         trust_id1 = generate_random_feed_id()
         assert ver.check_incoming(trust_id1, 'TestApp1') is False
コード例 #3
0
 def test_outgoing_master(self):
     with session_scope():
         fcc = FeedCtrlConnection()
         ecf = EventFactory()
         new_event = ecf.next_event('MASTER/MASTER', {})
         fcc.add_event(new_event)
         ver = Verification()
         result = ver.check_outgoing(ecf.get_feed_id())
         assert result is True
コード例 #4
0
 def test_outgoing_not_trusted(self):
     with session_scope():
         fcc = FeedCtrlConnection()
         ecf = EventFactory()
         new_event = ecf.next_event('MASTER/MASTER', {})
         fcc.add_event(new_event)
         trust_id1 = generate_random_feed_id()
         ver = Verification()
         result = ver.check_outgoing(trust_id1)
         assert result is False
コード例 #5
0
def test_event_factory():
    ecf = EventFactory()
    new_event = ecf.next_event('whateverapp/whateveraction', {
        'oneKey': 'somevalue',
        'someotherkey': 1
    })
    connector = DatabaseConnector()
    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'
コード例 #6
0
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'
コード例 #7
0
    def create_feed(self, article_feed_name):
        fcc = FeedCtrlConnection()
        ect = EventCreationTool()
        ect.set_path_to_keys(DIR_MAIN + '/' + 'Keys', False)

        event = self.db_connector.get_current_event(self.master_feed_id)
        ecf_master = EventFactory(event, DIR_MAIN + '/' + 'Keys', False)
        eventCreationWrapper = EventCreationWrapper(ecf_master)

        public_key = ect.generate_feed()
        new_feed_event = eventCreationWrapper.create_newFeed(
            public_key, 'bac_news')
        trust_feed_event = eventCreationWrapper.create_trust(public_key)
        first_event = ect.create_first_event(
            public_key, 'bac_news/new_article',
            {'master_feed': self.master_feed_id})

        fcc.add_event(new_feed_event)
        fcc.add_event(trust_feed_event)
        fcc.add_event(first_event)

        # creates event containing list name, host name and creation date (second event of the newly created feed)
        ect = EventCreationTool()
        ect.set_path_to_keys(DIR_MAIN + '/' + 'Keys', False)
        dictionary = {
            'host': self.get_event_content(self.master_feed_id, 2)[1]['name'],
            'list_name': article_feed_name,
            'date': datetime.now().isoformat()
        }
        second_event = ect.create_event_from_previous(first_event,
                                                      'bac_news/new_article',
                                                      dictionary)
        fcc.add_event(second_event)
コード例 #8
0
 def __init__(self):
     self._fcc = FeedCtrlConnection()
     # try catch or if None??
     lastEvent = self._fcc.get_my_last_event()
     if lastEvent is not None:
         self._ecf = EventFactory(lastEvent)
         self._eventCreationWrapper = EventCreationWrapper(self._ecf)
     else:
         self._ecf = EventFactory()
         self._eventCreationWrapper = EventCreationWrapper(self._ecf)
         _firstEvent = self._eventCreationWrapper.create_MASTER()
         _secondEvent = self._eventCreationWrapper.create_radius(1)
         _thirdEvent = self._eventCreationWrapper.create_name('Anon')
         self._fcc.add_event(_firstEvent)
         self._fcc.add_event(_secondEvent)
         self._fcc.add_event(_thirdEvent)
     self._masterID = self._fcc.get_host_master_id()
コード例 #9
0
def test_trash():
    with session_scope():
        ecf = EventFactory()
        cf = ChatFunction()
        new_event = ecf.next_event('MASTER/MASTER', {})
        fcc = FeedCtrlConnection()
        fcc.add_event(new_event)
        trust_id1 = generate_random_feed_id()
        new_event1 = ecf.next_event('MASTER/Trust', {'feed_id': trust_id1})
        fcc.add_event(new_event1)
        new_event2 = ecf.next_event('MASTER/Trash', {'feed_id': trust_id1})
        fcc.add_event(new_event2)
        new_event2 = ecf.next_event('MASTER/Trash', {'feed_id': trust_id1})
        fcc.add_event(new_event2)
        new_event2 = ecf.next_event('MASTER/Trash', {'feed_id': trust_id1})
        fcc.add_event(new_event2)
        result = cf.get_current_event(ecf.get_feed_id())
        assert result == new_event2
コード例 #10
0
 def setup_db(self, user_name=''):
     mas_id = self._fcc.get_host_master_id()
     if mas_id is not None:
         self.master_feed_id = self._fcc.get_host_master_id()
         self.db_connector = DatabaseConnector()
         self.user_name = self.get_user_name()
     else:
         make_dirs()
         self._ecf = EventFactory(None, DIR_MAIN + '/' + 'Keys', False)
         self._eventCreationWrapper = EventCreationWrapper(self._ecf)
         _firstEvent = self._eventCreationWrapper.create_MASTER()
         _secondEvent = self._eventCreationWrapper.create_radius(1)
         _thirdEvent = self._eventCreationWrapper.create_name(user_name)
         self._fcc.add_event(_firstEvent)
         self._fcc.add_event(_secondEvent)
         self._fcc.add_event(_thirdEvent)
         self.master_feed_id = self._fcc.get_host_master_id()
         self.db_connector = DatabaseConnector()
         self.user_name = user_name
コード例 #11
0
 def test_in_radius(self):
     with session_scope():
         ver = Verification()
         fcc = FeedCtrlConnection()
         ecf1 = EventFactory()
         new_event = ecf1.next_event('MASTER/MASTER', {})
         fcc.add_event(new_event)
         last_event = ecf1.next_event('MASTER/Radius', {'radius': 5})
         fcc.add_event(last_event)
         ecf2 = EventFactory()
         new_event = ecf2.next_event('MASTER/MASTER', {})
         fcc.add_event(new_event)
         last_event = ecf2.next_event('MASTER/Radius', {'radius': 3})
         fcc.add_event(last_event)
         ecf3 = EventFactory()
         new_event = ecf3.next_event('MASTER/MASTER', {})
         fcc.add_event(new_event)
         new_event = ecf3.next_event('MASTER/Radius', {'radius': 3})
         fcc.add_event(new_event)
         trusted_id1 = generate_random_feed_id()
         new_event = ecf3.next_event('MASTER/NewFeed', {
             'feed_id': trusted_id1,
             'app_name': 'TestApp'
         })
         fcc.add_event(new_event)
         trusted_id2 = generate_random_feed_id()
         new_event = ecf2.next_event('MASTER/NewFeed', {
             'feed_id': trusted_id2,
             'app_name': 'TestApp'
         })
         fcc.add_event(new_event)
         new_event = ecf1.next_event('MASTER/Trust',
                                     {'feed_id': trusted_id2})
         fcc.add_event(new_event)
         new_event = ecf2.next_event('MASTER/Trust',
                                     {'feed_id': trusted_id1})
         fcc.add_event(new_event)
         result = ver._check_in_radius('TestApp')
         assert result
コード例 #12
0
def test_get_master_id_from_feed():
    with session_scope():
        ecf = EventFactory()
        fcc = FeedCtrlConnection()
        new_event = ecf.next_event('MASTER/MASTER', {})
        fcc.add_event(new_event)
        trust_id1 = generate_random_feed_id()
        new_event = ecf.next_event('MASTER/NewFeed', {
            'feed_id': trust_id1,
            'app_name': 'Test1'
        })
        fcc.add_event(new_event)
        ecf2 = EventFactory()
        new_event = ecf2.next_event('MASTER/MASTER', {})
        fcc.add_event(new_event)
        trust_id2 = generate_random_feed_id()
        new_event = ecf2.next_event('MASTER/NewFeed', {
            'feed_id': trust_id2,
            'app_name': 'Test2'
        })
        fcc.add_event(new_event)
        new_event = ecf2.next_event('MASTER/Name', {'name': 'Alice'})
        fcc.add_event(new_event)
        trust_id5 = generate_random_feed_id()
        new_event = ecf.next_event('MASTER/Trust', {'feed_id': trust_id5})
        fcc.add_event(new_event)
        trust_id5 = generate_random_feed_id()
        new_event = ecf.next_event('MASTER/NewFeed', {
            'feed_id': trust_id5,
            'app_name': 'TestApp'
        })
        fcc.add_event(new_event)
        new_event = ecf.next_event('MASTER/Radius', {'radius': 5})
        fcc.add_event(new_event)
        new_event = ecf.next_event('MASTER/Name', {'name': 'Patrice'})
        fcc.add_event(new_event)
        result1 = fcc.get_master_id_from_feed(trust_id1)
        result2 = fcc.get_master_id_from_feed(trust_id2)
        assert result1 == ecf.get_feed_id()
        assert result2 == ecf2.get_feed_id()
コード例 #13
0
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)

            new_event = feed3.next_event('chat/MASTER',
                                         {'master_feed': ecf.get_feed_id()})
            cf.insert_event(new_event)

            new_event = feed.next_event('chat/whateveraction', {
                'messagekey': 'hallo zusammen',
                'chat_id': '1',
                'timestampkey': 10
            })
            cf.insert_event(new_event)

            new_event = feed.next_event('chat/whateveraction', {
                'messagekey': 'wie gehts?',
                'chat_id': '1',
                'timestampkey': 20
            })
            cf.insert_event(new_event)

            new_event = feed.next_event(
                'chat/whateveraction', {
                    'messagekey': 'schönes Wetter heute',
                    'chat_id': '1',
                    'timestampkey': 30
                })
            cf.insert_event(new_event)

            print(log_cap)
            q = cf.get_chat_since(15, '1')
            assert q[0][0] == 'wie gehts?'
            assert q[1][0] == 'schönes Wetter heute'
            t = cf.get_full_chat('1')
            assert t[0][0] == 'hallo zusammen'
            assert t[1][0] == 'wie gehts?'
            assert t[2][0] == 'schönes Wetter heute'
        assert True
コード例 #14
0



buffer_size = 1024  # The max buffer size of one packet to be sent by the server. Should be higher for our use case?
ip_address = ''
port = 0
cf = RatchetChatFunction()
function = Function()

try:
    os.mkdir(os.getcwd() + '/public_key')
except FileExistsError:
    pass
if not EventCreationTool().get_stored_feed_ids(directory_path=os.getcwd() + '/public_key'):
    ecf = EventFactory(path_to_keys=os.getcwd() + '/public_key')
    #print('new feed generated')
    #print('feed_id: ,', ecf.get_feed_id())

else:
    start_feed_id = EventCreationTool().get_stored_feed_ids(directory_path=os.getcwd() + '/public_key')
    current_event = function.get_current_event(feed_id=start_feed_id[0])
    ecf = EventFactory(path_to_keys=os.getcwd() + '/public_key', last_event=current_event)
    #print('use old feed')


def retrieve_new_messages_alice(alice) -> None:
    #print("X3DH status:", alice.x3dh_status)
    event_list = cf.get_all_saved_events(1)
    # print('len(event_list):', len(event_list))
    content = None
コード例 #15
0
def test_get_feed_ids_from_application_in_master_id():
    with session_scope():
        ecf = EventFactory()
        fcc = FeedCtrlConnection()
        new_event = ecf.next_event('MASTER/MASTER', {})
        fcc.add_event(new_event)
        trust_id1 = generate_random_feed_id()
        new_event = ecf.next_event('MASTER/NewFeed', {
            'feed_id': trust_id1,
            'app_name': 'Test1'
        })
        fcc.add_event(new_event)
        trust_id3 = generate_random_feed_id()
        new_event = ecf.next_event('MASTER/NewFeed', {
            'feed_id': trust_id3,
            'app_name': 'Test1'
        })
        fcc.add_event(new_event)
        ecf2 = EventFactory()
        new_event = ecf2.next_event('MASTER/MASTER', {})
        fcc.add_event(new_event)
        trust_id2 = generate_random_feed_id()
        new_event = ecf2.next_event('MASTER/NewFeed', {
            'feed_id': trust_id2,
            'app_name': 'Test2'
        })
        fcc.add_event(new_event)
        new_event = ecf2.next_event('MASTER/Name', {'name': 'Alice'})
        fcc.add_event(new_event)
        trust_id5 = generate_random_feed_id()
        new_event = ecf.next_event('MASTER/Trust', {'feed_id': trust_id5})
        fcc.add_event(new_event)
        trust_id5 = generate_random_feed_id()
        new_event = ecf.next_event('MASTER/NewFeed', {
            'feed_id': trust_id5,
            'app_name': 'TestApp'
        })
        fcc.add_event(new_event)
        new_event = ecf.next_event('MASTER/Radius', {'radius': 5})
        fcc.add_event(new_event)
        new_event = ecf.next_event('MASTER/Name', {'name': 'Patrice'})
        fcc.add_event(new_event)
        result1 = fcc.get_feed_ids_from_application_in_master_id(
            ecf.get_feed_id(), 'Test1')
        result2 = fcc.get_feed_ids_from_application_in_master_id(
            ecf2.get_feed_id(), 'Test2')
        logger.error(result1)
        assert result1[0] == trust_id1
        assert result2[0] == trust_id2
        assert result1[1] == trust_id3
コード例 #16
0
def test_get_feed_ids_in_radius():
    with session_scope():
        ecf = EventFactory()
        fcc = FeedCtrlConnection()
        new_event = ecf.next_event('MASTER/MASTER', {})
        fcc.add_event(new_event)
        new_event = ecf.next_event('MASTER/Radius', {'radius': 3})
        fcc.add_event(new_event)
        ecf2 = EventFactory()
        new_event = ecf2.next_event('MASTER/MASTER', {})
        fcc.add_event(new_event)
        new_event = ecf2.next_event('MASTER/Radius', {'radius': 5})
        fcc.add_event(new_event)
        ecf3 = EventFactory()
        new_event = ecf3.next_event('MASTER/MASTER', {})
        fcc.add_event(new_event)
        new_event = ecf3.next_event('MASTER/Radius', {'radius': 1})
        fcc.add_event(new_event)
        ecf4 = EventFactory()
        new_event = ecf4.next_event('MASTER/MASTER', {})
        fcc.add_event(new_event)
        new_event = ecf4.next_event('MASTER/Radius', {'radius': 2})
        fcc.add_event(new_event)
        new_event = ecf4.next_event('MASTER/Name', {'name': 'Alice'})
        fcc.add_event(new_event)
        new_event = ecf2.next_event('MASTER/Name', {'name': 'Alice'})
        fcc.add_event(new_event)
        trust_id5 = generate_random_feed_id()
        new_event = ecf.next_event('MASTER/Trust', {'feed_id': trust_id5})
        fcc.add_event(new_event)
        trust_id5 = generate_random_feed_id()
        new_event = ecf.next_event('MASTER/NewFeed', {
            'feed_id': trust_id5,
            'app_name': 'TestApp'
        })
        fcc.add_event(new_event)
        new_event = ecf.next_event('MASTER/Radius', {'radius': 5})
        fcc.add_event(new_event)
        new_event = ecf.next_event('MASTER/Name', {'name': 'Patrice'})
        fcc.add_event(new_event)
        result = fcc.get_feed_ids_in_radius()
        assert result[0] == ecf.get_feed_id()
        assert result[1] == ecf3.get_feed_id()
        assert result[2] == ecf4.get_feed_id()
        assert len(result) == 3
コード例 #17
0
def test_set_radius():
    with session_scope():
        ecf = EventFactory()
        fcc = FeedCtrlConnection()
        new_event = ecf.next_event('MASTER/MASTER', {})
        fcc.add_event(new_event)
        last_event = ecf.next_event('MASTER/Radius', {'radius': 5})
        fcc.add_event(last_event)
        ecf2 = EventFactory()
        new_event = ecf2.next_event('MASTER/MASTER', {})
        fcc.add_event(new_event)
        new_event = ecf2.next_event('MASTER/Radius', {'radius': 3})
        fcc.add_event(new_event)
        new_event = ecf2.next_event('MASTER/Name', {'name': 'Alice'})
        fcc.add_event(new_event)
        new_event = ecf2.next_event('MASTER/Name', {'name': 'Alice'})
        fcc.add_event(new_event)
        trust_id5 = generate_random_feed_id()
        new_event = ecf.next_event('MASTER/Trust', {'feed_id': trust_id5})
        fcc.add_event(new_event)
        trust_id5 = generate_random_feed_id()
        new_event = ecf.next_event('MASTER/NewFeed', {
            'feed_id': trust_id5,
            'app_name': 'TestApp'
        })
        fcc.add_event(new_event)
        new_event = ecf.next_event('MASTER/Radius', {'radius': 5})
        fcc.add_event(new_event)
        new_event = ecf.next_event('MASTER/Name', {'name': 'Patrice'})
        fcc.add_event(new_event)
        fcc.set_feed_ids_radius(ecf.get_feed_id(), 6)
        fcc.set_feed_ids_radius(ecf2.get_feed_id(), 10)
        result = fcc.get_radius()
        assert result == 6
コード例 #18
0
def test_get_all_master_ids():
    with session_scope():
        ecf = EventFactory()
        fcc = FeedCtrlConnection()
        new_event = ecf.next_event('MASTER/MASTER', {})
        fcc.add_event(new_event)
        ecf2 = EventFactory()
        new_event1 = ecf2.next_event('MASTER/MASTER', {})
        fcc.add_event(new_event1)
        trust_id2 = generate_random_feed_id()
        new_event = ecf.next_event('MASTER/Trust', {'feed_id': trust_id2})
        fcc.add_event(new_event)
        new_event = ecf.next_event('MASTER/Block', {'feed_id': trust_id2})
        fcc.add_event(new_event)
        fcc.add_event(new_event)
        trust_id5 = generate_random_feed_id()
        new_event = ecf.next_event('MASTER/Trust', {'feed_id': trust_id5})
        fcc.add_event(new_event)
        trust_id5 = generate_random_feed_id()
        new_event = ecf.next_event('MASTER/Name', {'name': trust_id5})
        fcc.add_event(new_event)
        trust_id5 = generate_random_feed_id()
        new_event = ecf.next_event('MASTER/NewFeed', {
            'feed_id': trust_id5,
            'app_name': 'TestApp'
        })
        fcc.add_event(new_event)
        new_event = ecf.next_event('MASTER/Radius', {'radius': 5})
        fcc.add_event(new_event)
        result1 = fcc.get_all_master_ids()
        assert result1[0] == ecf2.get_feed_id()
        assert len(result1) == 1
コード例 #19
0
def test_get_ratchet_chat_event():
    with LogCapture() as log_cap:
        ecf = EventFactory()

        cf = RatchetChatFunction()

        private_key1 = secrets.token_bytes(32)
        private_key2 = secrets.token_bytes(32)
        private_key3 = secrets.token_bytes(32)

        special_key1 = secrets.token_bytes(32)
        special_key2 = secrets.token_bytes(32)
        special_key3 = secrets.token_bytes(32)

        new_event = ecf.next_event('MASTER/MASTER', {})
        cf.insert_event(new_event)

        feed = EventFactory()
        feed2 = EventFactory()
        feed3 = EventFactory()

        new_event = feed.next_event('ratchet/MASTER', {'master_feed': ecf.get_feed_id()})
        cf.insert_event(new_event)

        new_event = feed2.next_event('ratchet/MASTER', {'master_feed': ecf.get_feed_id()})
        cf.insert_event(new_event)

        new_event = feed3.next_event('ratchet/MASTER', {'master_feed': ecf.get_feed_id()})
        cf.insert_event(new_event)

        new_event = feed.next_event('ratchet/whateveraction',
                                    {'messagekey': private_key1, 'chat_id': '1', 'timestampkey': 10,
                                     'special_key': special_key1})
        cf.insert_event(new_event)

        new_event = feed.next_event('ratchet/whateveraction',
                                    {'messagekey': private_key2, 'chat_id': '1', 'timestampkey': 20,
                                     'special_key': special_key2})
        cf.insert_event(new_event)

        new_event = feed.next_event('ratchet/whateveraction',
                                    {'messagekey': private_key3, 'chat_id': '1', 'timestampkey': 30,
                                     'special_key': special_key3})
        cf.insert_event(new_event)

        print(log_cap)
        q = cf.get_ratchet_chat_since(15, '1')
        assert q[0][0] == private_key2
        assert q[1][0] == private_key3
        t = cf.get_full_ratchet_chat('1')
        assert t[0][0] == private_key1
        assert t[1][0] == private_key2
        assert t[2][0] == private_key3
    assert True

    try:
        if os.path.exists('cborDatabase.sqlite'):
            os.remove('cborDatabase.sqlite')
            directory = "./"
            files_in_directory = os.listdir(directory)
            filtered_files = [file for file in files_in_directory if file.endswith(".key")]
            for file in filtered_files:
                path_to_file = os.path.join(directory, file)
                os.remove(path_to_file)
        else:
            assert False

    except Exception as e:
        logger.error(e)
コード例 #20
0
from logStore.appconn.kotlin_connection import KotlinFunction
from logStore.funcs.EventCreationTool import EventFactory
import os
import shutil

ecf = EventFactory()
kf = KotlinFunction()

new_event = ecf.next_event('MASTER/MASTER', {})
kf.insert_event(new_event)

feed = EventFactory()
feed2 = EventFactory()
feed3 = EventFactory()

# master feeds
new_event = feed.next_event('KotlinUI/MASTER', {'master_feed': ecf.get_feed_id()})
kf.insert_event(new_event)

new_event = feed2.next_event('KotlinUI/MASTER', {'master_feed': ecf.get_feed_id()})
kf.insert_event(new_event)

new_event = feed3.next_event('KotlinUI/MASTER', {'master_feed': ecf.get_feed_id()})
kf.insert_event(new_event)

# usernames
new_event = feed.next_event('KotlinUI/username',
                            {'newUsername': '******', 'oldUsername': '',
                             'timestamp': 1})
kf.insert_event(new_event)
コード例 #21
0
def generate_test_data():
    ufh = UiFunctionHandler()

    fcc = FeedCtrlConnection()
    ecf = EventFactory()
    new_event = ecf.next_event('MASTER/MASTER', {})
    fcc.add_event(new_event)
    trust_id1 = generate_random_feed_id()
    new_event = ecf.next_event('MASTER/NewFeed', {'feed_id': trust_id1, 'app_name': 'TestApp1'})
    fcc.add_event(new_event)
    trust_id2 = generate_random_feed_id()
    new_event = ecf.next_event('MASTER/NewFeed', {'feed_id': trust_id2, 'app_name': 'TestApp2'})
    fcc.add_event(new_event)
    new_event = ecf.next_event('MASTER/Name', {'name': 'Alice'})
    fcc.add_event(new_event)

    ecf2 = EventFactory()
    new_event = ecf2.next_event('MASTER/MASTER', {})
    fcc.add_event(new_event)
    trust_id3 = generate_random_feed_id()
    new_event = ecf2.next_event('MASTER/NewFeed', {'feed_id': trust_id3, 'app_name': 'TestApp1'})
    fcc.add_event(new_event)
    trust_id4 = generate_random_feed_id()
    new_event = ecf2.next_event('MASTER/NewFeed', {'feed_id': trust_id4, 'app_name': 'TestApp2'})
    fcc.add_event(new_event)
    new_event = ecf2.next_event('MASTER/Name', {'name': 'Bob'})
    fcc.add_event(new_event)

    new_event = ecf.next_event('MASTER/Trust', {'feed_id': trust_id3})

    ufh.set_trusted(trust_id1, True)
    ufh.set_trusted(trust_id4, True)
    ufh.set_trusted(trust_id2, False)

    ufh.set_radius(2)
コード例 #22
0
def test_add_event_and_get_host_master_id():
    with session_scope():
        ecf = EventFactory()
        cf = ChatFunction()
        new_event = ecf.next_event('MASTER/MASTER', {})
        fcc = FeedCtrlConnection()
        fcc.add_event(new_event)
        feed = EventFactory()
        new_event = feed.next_event('chat/MASTER',
                                    {'master_feed': ecf.get_feed_id()})
        fcc.add_event(new_event)
        new_event = feed.next_event('chat/whateveraction', {
            'messagekey': 'hallo zusammen',
            'chat_id': '1',
            'timestampkey': 10
        })
        fcc.add_event(new_event)
        new_event = feed.next_event('chat/whateveraction', {
            'messagekey': 'hallo zusammen',
            'chat_id': '1',
            'timestampkey': 10
        })
        fcc.add_event(new_event)
        trust_id5 = generate_random_feed_id()
        new_event = ecf.next_event('MASTER/Trust', {'feed_id': trust_id5})
        fcc.add_event(new_event)
        trust_id5 = generate_random_feed_id()
        new_event = ecf.next_event('MASTER/Name', {'name': trust_id5})
        fcc.add_event(new_event)
        trust_id5 = generate_random_feed_id()
        new_event = ecf.next_event('MASTER/NewFeed', {
            'feed_id': trust_id5,
            'app_name': 'TestApp'
        })
        fcc.add_event(new_event)
        new_event = ecf.next_event('MASTER/Radius', {'radius': 5})
        fcc.add_event(new_event)
        result = cf.get_full_chat('1')
        logger.error(result)
        result = fcc.get_host_master_id()
        assert result == ecf.get_feed_id()