Exemple #1
0
    def test_new_store_account_saving(self, matrix_store):
        account = OlmAccount()
        matrix_store.save_account(account)

        store2 = MatrixStore(matrix_store.user_id, matrix_store.device_id,
                             matrix_store.store_path)
        loaded_account = store2.load_account()

        assert account.identity_keys == loaded_account.identity_keys
Exemple #2
0
    def test_two_stores(self):
        try:
            account = self._create_ephemeral_account()
            store = self.ephemeral_store
            loaded_account = store.load_account()
            assert account.identity_keys == loaded_account.identity_keys

            store2 = MatrixStore("ephemeral2", "DEVICEID2", ephemeral_dir)
            assert not store2.load_account()

            loaded_account = store.load_account()
            assert account.identity_keys == loaded_account.identity_keys

        finally:
            os.remove(os.path.join(ephemeral_dir, "ephemeral2_DEVICEID2.db"))
    def test_real_db_upgrade(self, tempdir):
        path = os.path.abspath("tests/data/weechat_test.db")
        copyfile(path, os.path.join(tempdir, "weechat_test.db"))
        print(path)
        store = MatrixStore("@pjtest:termina.org.uk",
                            "LHNALLSCNA",
                            tempdir,
                            "DEFAULT_KEY",
                            database_name="weechat_test.db")
        store.save_encrypted_rooms([TEST_ROOM])

        account = store.load_account()
        encrypted_rooms = store.load_encrypted_rooms()

        assert TEST_ROOM in encrypted_rooms
        assert account.identity_keys == {
            "curve25519": "si7g1tFp4uhI+vzesW/zxss6Au/7Ufp+AKi7EGO+PHU",
            "ed25519": "JO4Q52p01yLoC9GuIYrded+heHBtI0ZxhZssvZ0xOt8"
        }
Exemple #4
0
 def copy_store(self, old_store):
     return MatrixStore(old_store.user_id, old_store.device_id,
                        old_store.store_path)
Exemple #5
0
 def ephemeral_store(self):
     return MatrixStore("@ephemeral:example.org", "DEVICEID", ephemeral_dir)
Exemple #6
0
    def test_db_upgrade(self, tempdir):
        user = "******"
        device_id = "DEVICE_ID"
        user2 = "alice"
        device_id2 = "ALICE_ID"

        store = MatrixStore(user, device_id, tempdir, database_name="test.db")
        account = OlmAccount()
        session = OutboundSession(account, BOB_CURVE, BOB_ONETIME)
        out_group = OutboundGroupSession()
        in_group = InboundGroupSession(out_group.session_key,
                                       account.identity_keys["ed25519"],
                                       account.identity_keys["curve25519"],
                                       TEST_ROOM, TEST_FORWARDING_CHAIN)
        devices = self.example_devices
        assert len(devices) == 11

        store.save_account(account)
        store.save_session(BOB_CURVE, session)
        store.save_inbound_group_session(in_group)
        store.save_device_keys(devices)

        store2 = MatrixStore(user2,
                             device_id2,
                             tempdir,
                             database_name="test.db")
        account2 = OlmAccount()
        store2.save_account(account2)
        del store

        store = MatrixStore(user, device_id, tempdir, database_name="test.db")
        loaded_account = store.load_account()

        assert account.identity_keys == loaded_account.identity_keys
        session_store = store.load_sessions()
        loaded_session = session_store.get(BOB_CURVE)
        session_store = store.load_inbound_group_sessions()

        assert loaded_session
        assert session.id == loaded_session.id

        loaded_session = session_store.get(TEST_ROOM,
                                           account.identity_keys["curve25519"],
                                           in_group.id)
        device_store = store.load_device_keys()

        # pdb.set_trace()

        assert loaded_session
        assert in_group.id == loaded_session.id
        assert (sorted(
            loaded_session.forwarding_chain) == sorted(TEST_FORWARDING_CHAIN))
        bob_device = device_store[BOB_ID][BOB_DEVICE]
        assert bob_device
        assert bob_device.user_id == BOB_ID
        assert bob_device.id == BOB_DEVICE
        assert bob_device.ed25519 == BOB_ONETIME
        assert bob_device.curve25519 == BOB_CURVE
        assert not bob_device.deleted
        assert len(device_store.users) == 11
Exemple #7
0
def matrix_store(tempdir):
    return MatrixStore("ephemeral", "DEVICEID", tempdir)
Exemple #8
0
def store(tempdir):
    store = MatrixStore("ephemeral", "DEVICEID", tempdir)
    account = OlmAccount()
    store.save_account(account)
    return store