Beispiel #1
0
    def test_homeserver_url_parsing(self):
        host, path = HttpClient._parse_homeserver("https://example.org:8080")
        assert host == "example.org:8080"
        assert path == ""

        host, path = HttpClient._parse_homeserver("example.org:8080")
        assert host == "example.org:8080"
        assert path == ""

        host, path = HttpClient._parse_homeserver("example.org/_matrix")
        assert host == "example.org:443"
        assert path == "_matrix"

        host, path = HttpClient._parse_homeserver(
            "https://example.org:8008/_matrix")
        assert host == "example.org:8008"
        assert path == "_matrix"
Beispiel #2
0
    def test_http_client_get_profile(self, http_client: HttpClient):
        http_client.connect(TransportType.HTTP2)

        name = faker.name()
        avatar = faker.avatar_url().replace("#auto", "")

        http_client.user_id = ALICE_ID

        _, _ = http_client.get_profile()
        http_client.receive(self.get_profile_byte_response(name, avatar, 1))
        response = http_client.next_response()

        assert isinstance(response, ProfileGetResponse)
        assert response.displayname == name
        assert response.avatar_url.replace("#auto", "") == avatar
Beispiel #3
0
    def test_client_protocol_error(self):
        client = Client(USER, DEVICE_ID)

        with pytest.raises(LocalProtocolError):
            client.olm_account_shared

        with pytest.raises(LocalProtocolError):
            client.blacklist_device(faker.olm_device())

        with pytest.raises(LocalProtocolError):
            client.unblacklist_device(faker.olm_device())

        with pytest.raises(LocalProtocolError):
            client.verify_device(faker.olm_device())

        with pytest.raises(LocalProtocolError):
            client.unverify_device(faker.olm_device())

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

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

        with pytest.raises(LocalProtocolError):
            client.device_store

        client = HttpClient(HOST, USER, DEVICE_ID)

        with pytest.raises(LocalProtocolError):
            client.share_group_session(None)

        with pytest.raises(LocalProtocolError):
            client.keys_claim(None)

        with pytest.raises(LocalProtocolError):
            client.keys_query(None)
Beispiel #4
0
    async def start(self):

        self.logger.info("Initializing client.")

        self.client = AsyncClient(self.homeserver)
        self.client.access_token = self.access_token
        self.client.user_id = self.user_id
        self.client.device_id = self.device_id

        self.logger.info("Initializing http client.")
        self.http_client = HttpClient(self.homeserver)

        self.logger.info("Register callbacks.")

        self.client.add_response_callback(self.on_error, SyncError)
        self.client.add_response_callback(self.on_sync, SyncResponse)
        # self.client.add_event_callback(self.on_invite, InviteMemberEvent)
        self.client.add_event_callback(self.on_message, RoomMessageText)
        self.client.add_event_callback(self.on_unknown, UnknownEvent)
        self.client.add_event_callback(self.on_image, RoomMessageImage)

        self.logger.info("Starting initial sync")

        await self.client.sync_forever(timeout=30000)
Beispiel #5
0
def synced_client(tempdir):
    http_client = HttpClient("example.org", "ephemeral", "DEVICEID", tempdir)
    http_client.connect(TransportType.HTTP2)

    http_client.login("1234")
    http_client.receive(TestClass().login_byte_response)
    response = http_client.next_response()
    assert isinstance(response, LoginResponse)
    assert http_client.access_token == "ABCD"

    http_client.sync()
    http_client.receive(TestClass().sync_byte_response)
    response = http_client.next_response()
    assert isinstance(response, SyncResponse)
    assert http_client.access_token == "ABCD"

    return http_client
Beispiel #6
0
def http_client(tempdir):
    return HttpClient("example.org", "ephemeral", "DEVICEID", tempdir)