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
def test_get_username():
    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/Name', {'name': 'Alice'})
        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/Name', {'name': 'Bob'})
        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_username(ecf.get_feed_id())
        result2 = fcc.get_username(ecf2.get_feed_id())
        assert result1 == 'Patrice'
        assert result2 == 'Bob'
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
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
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
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
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
Пример #8
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
Пример #9
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'
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()
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_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
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)
Пример #14
0
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)

new_event = feed2.next_event('KotlinUI/username',