Ejemplo n.º 1
0
    def test_client_account_sharing(self, client):
        client.receive_response(self.login_response)

        with pytest.raises(ValueError):
            client.decrypt_event(None)

        assert not client.olm_account_shared
        assert client.should_upload_keys
        assert client.device_store

        client.receive_response(KeysUploadResponse(49, 49))
        assert client.should_upload_keys
        client.receive_response(KeysUploadResponse(50, 50))
        assert not client.should_upload_keys
Ejemplo n.º 2
0
    async def test_room_key_on_client_sync_stream(self, client):
        await client.receive_response(self.login_response)
        await client.receive_response(
            SyncResponse.from_dict(self.initial_sync_response))
        await client.receive_response(
            KeysUploadResponse.from_dict(self.keys_upload_response))
        await client.receive_response(
            KeysQueryResponse.from_dict(self.keys_query_response))

        BobId = "@bob:example.org"
        Bob_device = "BOBDEVICE"

        bob_olm = Olm(BobId, Bob_device,
                      SqliteMemoryStore("ephemeral", "DEVICEID"))

        alice_device = OlmDevice(client.user_id, client.device_id,
                                 client.olm.account.identity_keys)

        bob_device = OlmDevice(bob_olm.user_id, bob_olm.device_id,
                               bob_olm.account.identity_keys)

        client.olm.device_store.add(bob_device)
        bob_olm.device_store.add(alice_device)
        bob_olm.store.save_device_keys(
            {client.user_id: {
                client.device_id: alice_device
            }})

        client.olm.account.generate_one_time_keys(1)
        one_time = list(
            client.olm.account.one_time_keys["curve25519"].values())[0]
        client.olm.account.mark_keys_as_published()

        bob_olm.create_session(one_time, alice_device.curve25519)

        _, to_device = bob_olm.share_group_session(
            TEST_ROOM_ID, [client.user_id], ignore_unverified_devices=True)
        outbound_session = bob_olm.outbound_group_sessions[TEST_ROOM_ID]
        olm_content = to_device["messages"][client.user_id][client.device_id]

        payload = {
            "sender": bob_olm.user_id,
            "type": "m.room.encrypted",
            "content": olm_content,
        }

        sync_response = self.empty_sync
        sync_response["to_device"]["events"].append(payload)

        session = client.olm.inbound_group_store.get(TEST_ROOM_ID,
                                                     bob_device.curve25519,
                                                     outbound_session.id)
        assert not session

        client.handle_to_device_from_sync_body(sync_response)

        session = client.olm.inbound_group_store.get(TEST_ROOM_ID,
                                                     bob_device.curve25519,
                                                     outbound_session.id)
        assert session
Ejemplo n.º 3
0
    def test_client_key_query(self, client):
        assert not client.should_query_keys

        client.receive_response(self.login_response)
        client.receive_response(KeysUploadResponse(50, 50))

        assert not client.should_query_keys
        client.receive_response(self.sync_response)

        assert not client.device_store.users

        assert client.rooms[TEST_ROOM_ID]
        room = client.rooms[TEST_ROOM_ID]

        assert room.encrypted
        assert room.summary
        assert len(room.users) == 1
        assert room.member_count == 2
        assert room.summary.joined_member_count == 2
        assert client.should_query_keys
        assert not client.device_store.users

        client.receive_response(self.keys_query_response)

        assert not client.should_query_keys
        assert client.device_store.users

        assert not room.members_synced

        client.receive_response(self.joined_members)

        assert room.members_synced
        assert client.should_query_keys

        assert client.users_for_key_query == set([BOB_ID])
Ejemplo n.º 4
0
    def test_client_room_creation(self, client):
        client.receive_response(self.login_response)
        client.receive_response(KeysUploadResponse(50, 50))

        assert not client.should_query_keys
        client.receive_response(self.sync_response)

        assert client.rooms[TEST_ROOM_ID]
        room = client.rooms[TEST_ROOM_ID]

        assert room.encrypted
        assert client.should_query_keys
Ejemplo n.º 5
0
    def test_device_store(self, tempdir):
        client = Client("ephemeral", "DEVICEID", tempdir)
        client.receive_response(self.login_response)
        client.receive_response(KeysUploadResponse(50, 50))

        assert not client.should_query_keys

        client.receive_response(self.sync_response)
        client.receive_response(self.keys_query_response)

        assert list(client.device_store.users) == [ALICE_ID]
        alice_device = client.device_store[ALICE_ID][ALICE_DEVICE_ID]
        assert alice_device

        client = Client("ephemeral", "DEVICEID", tempdir)
        client.receive_response(self.login_response)
        assert list(client.device_store.users) == [ALICE_ID]
        alice_device = client.device_store[ALICE_ID][ALICE_DEVICE_ID]
        assert alice_device
Ejemplo n.º 6
0
    def test_query_rule(self):
        client = Client("ephemeral", "DEVICEID", ephemeral_dir)
        client.receive_response(self.login_response)
        assert client.store is not None
        client.receive_response(KeysUploadResponse(50, 50))
        assert not client.should_query_keys

        client.receive_response(self.sync_response)
        assert client.should_query_keys
        client.receive_response(self.keys_query_response)
        assert client.olm.tracked_users == set([ALICE_ID])
        assert list(client.device_store.users) == [ALICE_ID]
        assert not client.should_query_keys

        del client

        client = Client("ephemeral", "DEVICEID", ephemeral_dir)
        client.receive_response(self.login_response)
        assert not client.should_upload_keys
        assert not client.should_query_keys

        assert list(client.device_store.users) == [ALICE_ID]
        assert client.device_store.active_user_devices(ALICE_ID)

        alice_device = client.device_store[ALICE_ID][ALICE_DEVICE_ID]
        assert alice_device

        client.receive_response(self.second_sync)
        assert client.should_query_keys

        client.users_for_key_query == set([ALICE_ID])

        client.receive_response(self.joined_members)

        client.users_for_key_query == set([ALICE_ID, BOB_ID])

        client.receive_response(self.keys_query_response)
        assert client.olm.tracked_users == set([ALICE_ID])
        assert client.users_for_key_query == set([BOB_ID])
        assert client.should_query_keys