From 65c0f8119c2c1a23bfdcc5ed1583468c0aa492df Mon Sep 17 00:00:00 2001 From: td Date: Wed, 28 Aug 2024 17:00:14 +0200 Subject: [PATCH] fix: actually make sure clientBox has a account --- lib/fake_matrix_api.dart | 5 +++-- lib/src/client.dart | 7 ++++++- test/client_test.dart | 25 ++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/lib/fake_matrix_api.dart b/lib/fake_matrix_api.dart index 941bc50a..cb89faad 100644 --- a/lib/fake_matrix_api.dart +++ b/lib/fake_matrix_api.dart @@ -133,7 +133,8 @@ class FakeMatrixApi extends BaseClient { } if (!servers.contains(request.url.origin)) { return Response( - 'Not found...', 404); + 'Not found ${request.url.origin}...', + 404); } if (!{ @@ -1158,7 +1159,7 @@ class FakeMatrixApi extends BaseClient { '/media/v3/config': (var req) => {'m.upload.size': 50000000}, '/client/v1/media/config': (var req) => {'m.upload.size': 50000000}, '/.well-known/matrix/client': (var req) => { - 'm.homeserver': {'base_url': 'https://matrix.example.com'}, + 'm.homeserver': {'base_url': 'https://fakeserver.notexisting'}, 'm.identity_server': {'base_url': 'https://identity.example.com'}, 'org.example.custom.property': { 'app_url': 'https://custom.app.example.org' diff --git a/lib/src/client.dart b/lib/src/client.dart index fc6778f2..77fbb5f5 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -1880,7 +1880,12 @@ class Client extends MatrixApi { final account = await this.database?.getClient(clientName); newRefreshToken ??= account?.tryGet('refresh_token'); - if (account != null) { + // can have discovery_information so make sure it also has the proper + // account creds + if (account != null && + account['homeserver_url'] != null && + account['user_id'] != null && + account['token'] != null) { _id = account['client_id']; homeserver = Uri.parse(account['homeserver_url']); accessToken = this.accessToken = account['token']; diff --git a/test/client_test.dart b/test/client_test.dart index e9e6dcd7..461f43c7 100644 --- a/test/client_test.dart +++ b/test/client_test.dart @@ -70,6 +70,28 @@ void main() { matrix = await getClient(); }); + test('barebones client login', () async { + final client = Client( + 'testclient', + httpClient: FakeMatrixApi(), + databaseBuilder: getDatabase, + ); + expect(client.isLogged(), false); + await client.init(); + expect(client.isLogged(), false); + await client.login( + LoginType.mLoginPassword, + token: 'abcd', + identifier: + AuthenticationUserIdentifier(user: '@test:fakeServer.notExisting'), + deviceId: 'GHTYAJCE', + ); + + expect(client.isLogged(), true); + + await client.logout(); + }); + test('Login', () async { matrix = Client( 'testclient', @@ -1173,7 +1195,8 @@ void main() { final client = await getClient(); expect(client.wellKnown, null); await client.getWellknown(); - expect(client.wellKnown?.mHomeserver.baseUrl.host, 'matrix.example.com'); + expect( + client.wellKnown?.mHomeserver.baseUrl.host, 'fakeserver.notexisting'); }); test('refreshAccessToken', () async {