From 7471743be38110b9d0d1cdb878b79bca2253b681 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sat, 20 Aug 2022 11:28:43 +0200 Subject: [PATCH] chore: disable dynamic calls --- analysis_options.yaml | 1 + lib/fake_matrix_api.dart | 76 ++++++++------- lib/src/matrix_api.dart | 5 +- lib/src/model/matrix_exception.dart | 14 +-- lib/src/model/matrix_keys.dart | 2 +- lib/src/model/sync_update.dart | 110 ++++++++------------- test/map_copy_extension_test.dart | 17 ++-- test/matrix_api_test.dart | 146 +++++++++++++++++----------- 8 files changed, 194 insertions(+), 177 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 6e0d5c78..24559023 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -7,6 +7,7 @@ linter: constant_identifier_names: false prefer_final_locals: true prefer_final_in_for_each: true + avoid_dynamic_calls: true analyzer: errors: diff --git a/lib/fake_matrix_api.dart b/lib/fake_matrix_api.dart index 5b8d94f0..bc4e5fe2 100644 --- a/lib/fake_matrix_api.dart +++ b/lib/fake_matrix_api.dart @@ -33,12 +33,14 @@ Map decodeJson(dynamic data) { if (data is String) { return json.decode(data); } - if (data.isEmpty) { + if (data is Map && data.isEmpty) { return {}; } return data; } +T? tryCast(dynamic object) => object is T ? object : null; + /// A mock http client for testing purposes. class FakeMatrixApi extends MockClient { static final calledEndpoints = >{}; @@ -83,7 +85,7 @@ class FakeMatrixApi extends MockClient { } calledEndpoints[action]!.add(data); if (api.containsKey(method) && api[method]!.containsKey(action)) { - res = api[method]![action](data); + res = api[method]![action]?.call(data); if (res is Map && res.containsKey('errcode')) { statusCode = 405; } @@ -953,7 +955,7 @@ class FakeMatrixApi extends MockClient { ] }; - static final Map> api = { + static final Map> api = { 'GET': { '/path/to/auth/error': (var req) => { 'errcode': 'M_FORBIDDEN', @@ -1942,42 +1944,45 @@ class FakeMatrixApi extends MockClient { 'prev_batch': 'p1902', 'total_room_count_estimate': 115 }, - '/client/v3/keys/claim': (var req) => { - 'failures': {}, - 'one_time_keys': { - if (decodeJson(req)['one_time_keys']['@alice:example.com'] != - null) - '@alice:example.com': { - 'JLAFKJWSCS': { - 'signed_curve25519:AAAAAQ': { - 'key': 'ikMXajRlkS7Xi9CROrAh3jXnbygk8mLBdSaY9/al0X0', - 'signatures': { - '@alice:example.com': { - 'ed25519:JLAFKJWSCS': - 'XdboCa0Ljoh0Y0i/IVnmMqy/+T1hJyu8BA/nRYniJMQ7QWh/pGS5AsWswdARD+MAX+r4u98Qzk0y27HUddZXDA' - } + '/client/v3/keys/claim': (dynamic req) { + final request = decodeJson(req)["one_time_keys"]; + final keys = (request is Map) + ? request["one_time_keys"] as Map? + : null; + return { + 'failures': {}, + 'one_time_keys': { + if (keys?['@alice:example.com'] != null) + '@alice:example.com': { + 'JLAFKJWSCS': { + 'signed_curve25519:AAAAAQ': { + 'key': 'ikMXajRlkS7Xi9CROrAh3jXnbygk8mLBdSaY9/al0X0', + 'signatures': { + '@alice:example.com': { + 'ed25519:JLAFKJWSCS': + 'XdboCa0Ljoh0Y0i/IVnmMqy/+T1hJyu8BA/nRYniJMQ7QWh/pGS5AsWswdARD+MAX+r4u98Qzk0y27HUddZXDA' } } } - }, - if (decodeJson(req)['one_time_keys'] - ['@test:fakeServer.notExisting'] != - null) - '@test:fakeServer.notExisting': { - 'GHTYAJCE': { - 'signed_curve25519:AAAAAQ': { - 'key': 'qc72ve94cA28iuE0fXa98QO3uls39DHWdQlYyvvhGh0', - 'signatures': { - '@test:fakeServer.notExisting': { - 'ed25519:GHTYAJCE': - 'dFwffr5kTKefO7sjnWLMhTzw7oV31nkPIDRxFy5OQT2OP5++Ao0KRbaBZ6qfuT7lW1owKK0Xk3s7QTBvc/eNDA', - }, + } + }, + if (keys?['@test:fakeServer.notExisting'] != null) + '@test:fakeServer.notExisting': { + 'GHTYAJCE': { + 'signed_curve25519:AAAAAQ': { + 'key': 'qc72ve94cA28iuE0fXa98QO3uls39DHWdQlYyvvhGh0', + 'signatures': { + '@test:fakeServer.notExisting': { + 'ed25519:GHTYAJCE': + 'dFwffr5kTKefO7sjnWLMhTzw7oV31nkPIDRxFy5OQT2OP5++Ao0KRbaBZ6qfuT7lW1owKK0Xk3s7QTBvc/eNDA', }, }, }, }, - } - }, + }, + } + }; + }, '/client/v3/rooms/!localpart%3Aexample.com/invite': (var req) => {}, '/client/v3/rooms/!localpart%3Aexample.com/leave': (var req) => {}, '/client/v3/rooms/!localpart%3Aexample.com/forget': (var req) => {}, @@ -1992,8 +1997,11 @@ class FakeMatrixApi extends MockClient { '/client/v3/keys/upload': (var req) => { 'one_time_key_counts': { 'curve25519': 10, - 'signed_curve25519': - decodeJson(req)['one_time_keys']?.keys?.length ?? 0, + 'signed_curve25519': tryCast>>( + decodeJson(req))?['one_time_keys'] + ?.keys + .length ?? + 0, } }, '/client/v3/keys/query': (var req) => { diff --git a/lib/src/matrix_api.dart b/lib/src/matrix_api.dart index cb628958..e768c4d5 100644 --- a/lib/src/matrix_api.dart +++ b/lib/src/matrix_api.dart @@ -209,7 +209,10 @@ class MatrixApi extends Api { // fix invalid responses from synapse // https://github.com/matrix-org/synapse/pull/10922 - json['ttl'] = json['ttl'].toInt(); + final ttl = json['ttl']; + if (ttl is double) { + json['ttl'] = ttl.toInt(); + } return TurnServerCredentials.fromJson(json); } diff --git a/lib/src/model/matrix_exception.dart b/lib/src/model/matrix_exception.dart index 1555dfeb..94257427 100644 --- a/lib/src/model/matrix_exception.dart +++ b/lib/src/model/matrix_exception.dart @@ -106,12 +106,14 @@ class MatrixException implements Exception { /// to authenticate itself. Each flow comprises a series of stages. If this request /// doesn't need additional authentication, then this is null. List? get authenticationFlows { - if (!raw.containsKey('flows') || raw['flows'] is! List) return null; - return (raw['flows'] as List) - .map((flow) => flow['stages']) - .whereType() - .map((stages) => AuthenticationFlow(List.from(stages))) - .toList(); + final flows = raw['flows']; + return (flows is List>>) + ? flows + .map((flow) => flow['stages']) + .whereType>() + .map((stages) => AuthenticationFlow(List.from(stages))) + .toList() + : null; } /// This section contains any information that the client will need to know in order to use a given type diff --git a/lib/src/model/matrix_keys.dart b/lib/src/model/matrix_keys.dart index 01c0538a..65f47368 100644 --- a/lib/src/model/matrix_keys.dart +++ b/lib/src/model/matrix_keys.dart @@ -113,7 +113,7 @@ class MatrixDeviceKeys extends MatrixSignableKey { @override MatrixDeviceKeys.fromJson(Map json) - : algorithms = json['algorithms'].cast(), + : algorithms = (json['algorithms'] as List).cast(), deviceId = json['device_id'], super.fromJson(json); diff --git a/lib/src/model/sync_update.dart b/lib/src/model/sync_update.dart index 95aaf3e5..e1e7da52 100644 --- a/lib/src/model/sync_update.dart +++ b/lib/src/model/sync_update.dart @@ -54,24 +54,15 @@ class SyncUpdate { : nextBatch = json['next_batch'], rooms = json['rooms'] != null ? RoomsUpdate.fromJson(json['rooms']) : null, - presence = - (json['presence'] != null && json['presence']['events'] != null) - ? (json['presence']['events'] as List) - .map((i) => Presence.fromJson(i)) - .toList() - : null, - accountData = (json['account_data'] != null && - json['account_data']['events'] != null) - ? (json['account_data']['events'] as List) - .map((i) => BasicEvent.fromJson(i)) - .toList() - : null, - toDevice = - (json['to_device'] != null && json['to_device']['events'] != null) - ? (json['to_device']['events'] as List) - .map((i) => BasicEventWithSender.fromJson(i)) - .toList() - : null, + presence = ((json['presence'] as Map?)?['events'] as List?) + ?.map((i) => Presence.fromJson(i)) + .toList(), + accountData = ((json['account_data'] as Map?)?['events'] as List?) + ?.map((i) => BasicEvent.fromJson(i)) + .toList(), + toDevice = ((json['to_device'] as Map?)?['events'] as List?) + ?.map((i) => BasicEventWithSender.fromJson(i)) + .toList(), deviceLists = json['device_lists'] != null ? DeviceListsUpdate.fromJson(json['device_lists']) : null, @@ -183,34 +174,25 @@ class JoinedRoomUpdate extends SyncRoomUpdate { this.unreadNotifications, }); - JoinedRoomUpdate.fromJson(Map json) { - summary = - json['summary'] != null ? RoomSummary.fromJson(json['summary']) : null; - state = (json['state'] != null && json['state']['events'] != null) - ? (json['state']['events'] as List) - .map((i) => MatrixEvent.fromJson(i)) - .toList() - : null; - timeline = json['timeline'] != null - ? TimelineUpdate.fromJson(json['timeline']) - : null; - - ephemeral = - (json['ephemeral'] != null && json['ephemeral']['events'] != null) - ? (json['ephemeral']['events'] as List) - .map((i) => BasicRoomEvent.fromJson(i)) - .toList() + JoinedRoomUpdate.fromJson(Map json) + : summary = json['summary'] != null + ? RoomSummary.fromJson(json['summary']) + : null, + state = ((json['state'] as Map?)?['events'] as List?) + ?.map((i) => MatrixEvent.fromJson(i)) + .toList(), + timeline = json['timeline'] != null + ? TimelineUpdate.fromJson(json['timeline']) + : null, + ephemeral = ((json['ephemeral'] as Map?)?['events'] as List?) + ?.map((i) => BasicRoomEvent.fromJson(i)) + .toList(), + accountData = ((json['account_data'] as Map?)?['events'] as List?) + ?.map((i) => BasicRoomEvent.fromJson(i)) + .toList(), + unreadNotifications = json['unread_notifications'] != null + ? UnreadNotificationCounts.fromJson(json['unread_notifications']) : null; - accountData = - (json['account_data'] != null && json['account_data']['events'] != null) - ? (json['account_data']['events'] as List) - .map((i) => BasicRoomEvent.fromJson(i)) - .toList() - : null; - unreadNotifications = json['unread_notifications'] != null - ? UnreadNotificationCounts.fromJson(json['unread_notifications']) - : null; - } Map toJson() { final data = {}; @@ -247,14 +229,10 @@ class InvitedRoomUpdate extends SyncRoomUpdate { InvitedRoomUpdate({this.inviteState}); - InvitedRoomUpdate.fromJson(Map json) { - inviteState = - (json['invite_state'] != null && json['invite_state']['events'] != null) - ? (json['invite_state']['events'] as List) - .map((i) => StrippedStateEvent.fromJson(i)) - .toList() - : null; - } + InvitedRoomUpdate.fromJson(Map json) + : inviteState = ((json['invite_state'] as Map?)?['events'] as List?) + ?.map((i) => StrippedStateEvent.fromJson(i)) + .toList(); Map toJson() { final data = {}; @@ -278,22 +256,16 @@ class LeftRoomUpdate extends SyncRoomUpdate { this.accountData, }); - LeftRoomUpdate.fromJson(Map json) { - state = (json['state'] != null && json['state']['events'] != null) - ? (json['state']['events'] as List) - .map((i) => MatrixEvent.fromJson(i)) - .toList() - : null; - timeline = json['timeline'] != null - ? TimelineUpdate.fromJson(json['timeline']) - : null; - accountData = - (json['account_data'] != null && json['account_data']['events'] != null) - ? (json['account_data']['events'] as List) - .map((i) => BasicRoomEvent.fromJson(i)) - .toList() - : null; - } + LeftRoomUpdate.fromJson(Map json) + : state = ((json['state'] as Map?)?['events'] as List?) + ?.map((i) => MatrixEvent.fromJson(i)) + .toList(), + timeline = json['timeline'] != null + ? TimelineUpdate.fromJson(json['timeline']) + : null, + accountData = ((json['account_data'] as Map?)?['events'] as List?) + ?.map((i) => BasicRoomEvent.fromJson(i)) + .toList(); Map toJson() { final data = {}; diff --git a/test/map_copy_extension_test.dart b/test/map_copy_extension_test.dart index 329771d9..3578c624 100644 --- a/test/map_copy_extension_test.dart +++ b/test/map_copy_extension_test.dart @@ -35,10 +35,10 @@ void main() { }, }; final copy = original.copy(); - original['child']['attr'] = 'raccoon'; - expect(copy['child']['attr'], 'bunny'); - original['child']['list'].add(3); - expect(copy['child']['list'], [1, 2]); + (original['child'] as Map)['attr'] = 'raccoon'; + expect((copy['child'] as Map)['attr'], 'bunny'); + ((original['child'] as Map)['list'] as List).add(3); + expect((copy['child'] as Map)['list'], [1, 2]); }); test('should do arrays', () { final original = { @@ -48,10 +48,11 @@ void main() { ], }; final copy = original.copy(); - original['arr'][0].add(3); - expect(copy['arr'][0], [1, 2]); - original['arr'][1]['beep'] = 'blargh'; - expect(copy['arr'][1]['beep'], 'boop'); + ((original['arr'] as List)[0] as List).add(3); + expect((copy['arr'] as List)[0], [1, 2]); + ((original['arr'] as List)[1] as Map)['beep'] = 'blargh'; + expect( + ((copy['arr'] as List)[1] as Map)['beep'], 'boop'); }); }); } diff --git a/test/matrix_api_test.dart b/test/matrix_api_test.dart index 962050b6..af7de7c6 100644 --- a/test/matrix_api_test.dart +++ b/test/matrix_api_test.dart @@ -123,7 +123,7 @@ void main() { final supportedVersions = await matrixApi.getVersions(); expect(supportedVersions.versions.contains('r0.5.0'), true); expect(supportedVersions.unstableFeatures!['m.lazy_load_members'], true); - expect(FakeMatrixApi.api['GET']!['/client/versions']({}), + expect(FakeMatrixApi.api['GET']!['/client/versions']!.call({}), supportedVersions.toJson()); matrixApi.homeserver = null; }); @@ -146,7 +146,7 @@ void main() { matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting'); final loginTypes = await matrixApi.getLoginFlows(); expect(loginTypes?.first.type, 'm.login.password'); - expect(FakeMatrixApi.api['GET']!['/client/v3/login']({}), + expect(FakeMatrixApi.api['GET']!['/client/v3/login']!.call({}), {'flows': loginTypes?.map((x) => x.toJson()).toList()}); matrixApi.homeserver = null; }); @@ -156,7 +156,7 @@ void main() { LoginType.mLoginPassword, identifier: AuthenticationUserIdentifier(user: 'username'), ); - expect(FakeMatrixApi.api['POST']!['/client/v3/login']({}), + expect(FakeMatrixApi.api['POST']!['/client/v3/login']!.call({}), loginResponse.toJson()); matrixApi.homeserver = null; }); @@ -176,7 +176,9 @@ void main() { matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting'); final registerResponse = await matrixApi.register(kind: AccountKind.guest, username: 'test'); - expect(FakeMatrixApi.api['POST']!['/client/v3/register?kind=guest']({}), + expect( + FakeMatrixApi.api['POST']!['/client/v3/register?kind=guest']! + .call({}), registerResponse.toJson()); matrixApi.homeserver = null; }); @@ -192,8 +194,8 @@ void main() { idAccessToken: '1234', ); expect( - FakeMatrixApi - .api['POST']!['/client/v3/register/email/requestToken']({}), + FakeMatrixApi.api['POST']!['/client/v3/register/email/requestToken']! + .call({}), response.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; }); @@ -210,8 +212,8 @@ void main() { idAccessToken: '1234', ); expect( - FakeMatrixApi - .api['POST']!['/client/v3/register/email/requestToken']({}), + FakeMatrixApi.api['POST']!['/client/v3/register/email/requestToken']! + .call({}), response.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; }); @@ -280,7 +282,7 @@ void main() { matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting'); matrixApi.accessToken = '1234'; final response = await matrixApi.getAccount3PIDs(); - expect(FakeMatrixApi.api['GET']!['/client/v3/account/3pid']({}), + expect(FakeMatrixApi.api['GET']!['/client/v3/account/3pid']!.call({}), {'threepids': response?.map((t) => t.toJson()).toList()}); matrixApi.homeserver = matrixApi.accessToken = null; }); @@ -362,7 +364,7 @@ void main() { matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting'); matrixApi.accessToken = '1234'; final response = await matrixApi.getCapabilities(); - expect(FakeMatrixApi.api['GET']!['/client/v3/capabilities']({}), + expect(FakeMatrixApi.api['GET']!['/client/v3/capabilities']!.call({}), {'capabilities': response.toJson()}); matrixApi.homeserver = matrixApi.accessToken = null; }); @@ -497,8 +499,8 @@ void main() { ); expect( FakeMatrixApi.api['GET']![ - '/client/v3/sync?filter=%7B%7D&since=1234&full_state=false&set_presence=unavailable&timeout=15']( - {}) as Map?, + '/client/v3/sync?filter=%7B%7D&since=1234&full_state=false&set_presence=unavailable&timeout=15']! + .call({}) as Map?, response.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; }); @@ -575,8 +577,8 @@ void main() { expect( FakeMatrixApi.api['GET']![ - '/client/v3/rooms/!localpart%3Aserver.abc/messages?from=1234&to=1234&dir=b&limit=10&filter=%7B%22lazy_load_members%22%3Atrue%7D']( - {}) as Map?, + '/client/v3/rooms/!localpart%3Aserver.abc/messages?from=1234&to=1234&dir=b&limit=10&filter=%7B%22lazy_load_members%22%3Atrue%7D']! + .call({}) as Map?, timelineHistoryResponse.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -666,7 +668,8 @@ void main() { expect( FakeMatrixApi.api['GET']![ - '/client/v3/directory/room/%23testalias%3Aexample.com']({}), + '/client/v3/directory/room/%23testalias%3Aexample.com']! + .call({}), roomAliasInformation.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -828,7 +831,8 @@ void main() { expect( FakeMatrixApi.api['GET']![ - '/client/v3/publicRooms?limit=10&since=1234&server=example.com']({}), + '/client/v3/publicRooms?limit=10&since=1234&server=example.com']! + .call({}), response.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -850,7 +854,8 @@ void main() { expect( FakeMatrixApi - .api['POST']!['/client/v3/publicRooms?server=example.com']({}), + .api['POST']!['/client/v3/publicRooms?server=example.com']! + .call({}), response.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -864,7 +869,8 @@ void main() { expect( FakeMatrixApi.api['GET']![ - '/client/v1/rooms/${Uri.encodeComponent('!gPxZhKUssFZKZcoCKY:neko.dev')}/hierarchy']({}), + '/client/v1/rooms/${Uri.encodeComponent('!gPxZhKUssFZKZcoCKY:neko.dev')}/hierarchy']! + .call({}), response.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -878,7 +884,9 @@ void main() { limit: 10, ); - expect(FakeMatrixApi.api['POST']!['/client/v3/user_directory/search']({}), + expect( + FakeMatrixApi.api['POST']!['/client/v3/user_directory/search']! + .call({}), response.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -926,7 +934,8 @@ void main() { final response = await matrixApi.getUserProfile('@alice:example.com'); expect( FakeMatrixApi - .api['GET']!['/client/v3/profile/%40alice%3Aexample.com']({}), + .api['GET']!['/client/v3/profile/%40alice%3Aexample.com']! + .call({}), response.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -936,7 +945,7 @@ void main() { matrixApi.accessToken = '1234'; final response = await matrixApi.getTurnServer(); - expect(FakeMatrixApi.api['GET']!['/client/v3/voip/turnServer']({}), + expect(FakeMatrixApi.api['GET']!['/client/v3/voip/turnServer']!.call({}), response.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -1000,7 +1009,8 @@ void main() { ); expect( FakeMatrixApi.api['GET']![ - '/client/v3/presence/${Uri.encodeComponent('@alice:example.com')}/status']({}), + '/client/v3/presence/${Uri.encodeComponent('@alice:example.com')}/status']! + .call({}), response.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -1030,7 +1040,8 @@ void main() { ); expect( FakeMatrixApi.api['GET']![ - '/media/v3/preview_url?url=https%3A%2F%2Fmatrix.org&ts=10']({}), + '/media/v3/preview_url?url=https%3A%2F%2Fmatrix.org&ts=10']! + .call({}), openGraphData.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -1061,7 +1072,9 @@ void main() { matrixApi.accessToken = '1234'; final devices = await matrixApi.getDevices(); - expect(FakeMatrixApi.api['GET']!['/client/v3/devices']({})['devices'], + expect( + (FakeMatrixApi.api['GET']!['/client/v3/devices']!.call({}) + as Map?)?['devices'], devices?.map((i) => i.toJson()).toList()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -1131,8 +1144,8 @@ void main() { .deviceDisplayName, 'Alices mobile phone'); expect( - FakeMatrixApi - .api['POST']!['/client/v3/keys/query']({'device_keys': {}}), + FakeMatrixApi.api['POST']!['/client/v3/keys/query']! + .call({'device_keys': {}}), response.toJson()); matrixApi.homeserver = matrixApi.accessToken = null; @@ -1148,7 +1161,7 @@ void main() { timeout: 10, ); expect( - FakeMatrixApi.api['POST']!['/client/v3/keys/claim']({ + FakeMatrixApi.api['POST']!['/client/v3/keys/claim']!.call({ 'one_time_keys': { '@alice:example.com': {'JLAFKJWSCS': 'signed_curve25519'} } @@ -1207,7 +1220,7 @@ void main() { final response = await matrixApi.getPushers(); expect( - FakeMatrixApi.api['GET']!['/client/v3/pushers']({}), + FakeMatrixApi.api['GET']!['/client/v3/pushers']!.call({}), {'pushers': response?.map((i) => i.toJson()).toList()}, ); @@ -1245,7 +1258,8 @@ void main() { ); expect( FakeMatrixApi.api['GET']![ - '/client/v3/notifications?from=1234&limit=10&only=1234']({}), + '/client/v3/notifications?from=1234&limit=10&only=1234']! + .call({}), response.toJson(), ); @@ -1257,7 +1271,7 @@ void main() { final response = await matrixApi.getPushRules(); expect( - FakeMatrixApi.api['GET']!['/client/v3/pushrules']({}), + FakeMatrixApi.api['GET']!['/client/v3/pushrules']!.call({}), {'global': response.toJson()}, ); @@ -1270,8 +1284,8 @@ void main() { final response = await matrixApi.getPushRule('global', PushRuleKind.content, 'nocake'); expect( - FakeMatrixApi - .api['GET']!['/client/v3/pushrules/global/content/nocake']({}), + FakeMatrixApi.api['GET']!['/client/v3/pushrules/global/content/nocake']! + .call({}), response.toJson(), ); @@ -1371,7 +1385,8 @@ void main() { from: '1234', roomId: '!1234', timeout: 10); expect( FakeMatrixApi.api['GET']![ - '/client/v3/events?from=1234&timeout=10&room_id=%211234']({}), + '/client/v3/events?from=1234&timeout=10&room_id=%211234']! + .call({}), response.toJson(), ); @@ -1385,7 +1400,8 @@ void main() { '@alice:example.com', '!localpart:example.com'); expect( FakeMatrixApi.api['GET']![ - '/client/v3/user/%40alice%3Aexample.com/rooms/!localpart%3Aexample.com/tags']({}), + '/client/v3/user/%40alice%3Aexample.com/rooms/!localpart%3Aexample.com/tags']! + .call({}), {'tags': response?.map((k, v) => MapEntry(k, v.toJson()))}, ); @@ -1471,7 +1487,8 @@ void main() { final response = await matrixApi.getWhoIs('@alice:example.com'); expect( FakeMatrixApi - .api['GET']!['/client/v3/admin/whois/%40alice%3Aexample.com']({}), + .api['GET']!['/client/v3/admin/whois/%40alice%3Aexample.com']! + .call({}), response.toJson(), ); @@ -1485,7 +1502,8 @@ void main() { limit: 10, filter: '{}'); expect( FakeMatrixApi.api['GET']![ - '/client/v3/rooms/1234/context/1234?limit=10&filter=%7B%7D']({}), + '/client/v3/rooms/1234/context/1234?limit=10&filter=%7B%7D']! + .call({}), response.toJson(), ); @@ -1510,7 +1528,7 @@ void main() { final response = await matrixApi.getProtocols(); expect( - FakeMatrixApi.api['GET']!['/client/v3/thirdparty/protocols']({}), + FakeMatrixApi.api['GET']!['/client/v3/thirdparty/protocols']!.call({}), response.map((k, v) => MapEntry(k, v.toJson())), ); @@ -1522,7 +1540,8 @@ void main() { final response = await matrixApi.getProtocolMetadata('irc'); expect( - FakeMatrixApi.api['GET']!['/client/v3/thirdparty/protocol/irc']({}), + FakeMatrixApi.api['GET']!['/client/v3/thirdparty/protocol/irc']! + .call({}), response.toJson(), ); @@ -1534,7 +1553,8 @@ void main() { final response = await matrixApi.queryLocationByProtocol('irc'); expect( - FakeMatrixApi.api['GET']!['/client/v3/thirdparty/location/irc']({}), + FakeMatrixApi.api['GET']!['/client/v3/thirdparty/location/irc']! + .call({}), response.map((i) => i.toJson()).toList(), ); @@ -1546,7 +1566,7 @@ void main() { final response = await matrixApi.queryUserByProtocol('irc'); expect( - FakeMatrixApi.api['GET']!['/client/v3/thirdparty/user/irc']({}), + FakeMatrixApi.api['GET']!['/client/v3/thirdparty/user/irc']!.call({}), response.map((i) => i.toJson()).toList(), ); @@ -1558,8 +1578,8 @@ void main() { final response = await matrixApi.queryLocationByAlias('1234'); expect( - FakeMatrixApi - .api['GET']!['/client/v3/thirdparty/location?alias=1234']({}), + FakeMatrixApi.api['GET']!['/client/v3/thirdparty/location?alias=1234']! + .call({}), response.map((i) => i.toJson()).toList(), ); @@ -1571,7 +1591,8 @@ void main() { final response = await matrixApi.queryUserByID('1234'); expect( - FakeMatrixApi.api['GET']!['/client/v3/thirdparty/user?userid=1234']({}), + FakeMatrixApi.api['GET']!['/client/v3/thirdparty/user?userid=1234']! + .call({}), response.map((i) => i.toJson()).toList(), ); @@ -1583,8 +1604,8 @@ void main() { final response = await matrixApi.requestOpenIdToken('1234', {}); expect( - FakeMatrixApi - .api['POST']!['/client/v3/user/1234/openid/request_token']({}), + FakeMatrixApi.api['POST']!['/client/v3/user/1234/openid/request_token']! + .call({}), response.toJson(), ); @@ -1609,8 +1630,8 @@ void main() { }; final ret = await matrixApi.postRoomKeysVersion(algorithm, authData); expect( - FakeMatrixApi - .api['POST']!['/client/v3/room_keys/version']({})['version'], + (FakeMatrixApi.api['POST']!['/client/v3/room_keys/version']!.call({}) + as Map)['version'], ret); }); test('getRoomKeysVersionCurrent', () async { @@ -1618,7 +1639,8 @@ void main() { matrixApi.accessToken = '1234'; final ret = await matrixApi.getRoomKeysVersionCurrent(); - expect(FakeMatrixApi.api['GET']!['/client/v3/room_keys/version']({}), + expect( + FakeMatrixApi.api['GET']!['/client/v3/room_keys/version']!.call({}), ret.toJson()); }); test('putRoomKeysVersion', () async { @@ -1659,7 +1681,8 @@ void main() { roomId, sessionId, '5', session); expect( FakeMatrixApi.api['PUT']![ - '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5']({}), + '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5']! + .call({}), ret.toJson()); }); test('getRoomKeyBySessionId', () async { @@ -1671,7 +1694,8 @@ void main() { final ret = await matrixApi.getRoomKeyBySessionId(roomId, sessionId, '5'); expect( FakeMatrixApi.api['GET']![ - '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5']({}), + '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5']! + .call({}), ret.toJson()); }); test('deleteRoomKeyBySessionId', () async { @@ -1684,7 +1708,8 @@ void main() { await matrixApi.deleteRoomKeyBySessionId(roomId, sessionId, '5'); expect( FakeMatrixApi.api['DELETE']![ - '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5']({}), + '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}/${Uri.encodeComponent('ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU')}?version=5']! + .call({}), ret.toJson()); }); test('putRoomKeysByRoomId', () async { @@ -1711,7 +1736,8 @@ void main() { final ret = await matrixApi.putRoomKeysByRoomId(roomId, '5', session); expect( FakeMatrixApi.api['PUT']![ - '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}?version=5']({}), + '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}?version=5']! + .call({}), ret.toJson()); }); test('getRoomKeysByRoomId', () async { @@ -1722,7 +1748,8 @@ void main() { final ret = await matrixApi.getRoomKeysByRoomId(roomId, '5'); expect( FakeMatrixApi.api['GET']![ - '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}?version=5']({}), + '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}?version=5']! + .call({}), ret.toJson()); }); test('deleteRoomKeysByRoomId', () async { @@ -1733,7 +1760,8 @@ void main() { final ret = await matrixApi.deleteRoomKeysByRoomId(roomId, '5'); expect( FakeMatrixApi.api['DELETE']![ - '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}?version=5']({}), + '/client/v3/room_keys/keys/${Uri.encodeComponent('!726s6s6q:example.com')}?version=5']! + .call({}), ret.toJson()); }); test('putRoomKeys', () async { @@ -1763,7 +1791,8 @@ void main() { }); final ret = await matrixApi.putRoomKeys('5', session); expect( - FakeMatrixApi.api['PUT']!['/client/v3/room_keys/keys?version=5']({}), + FakeMatrixApi.api['PUT']!['/client/v3/room_keys/keys?version=5']! + .call({}), ret.toJson()); }); test('getRoomKeys', () async { @@ -1772,7 +1801,8 @@ void main() { final ret = await matrixApi.getRoomKeys('5'); expect( - FakeMatrixApi.api['GET']!['/client/v3/room_keys/keys?version=5']({}), + FakeMatrixApi.api['GET']!['/client/v3/room_keys/keys?version=5']! + .call({}), ret.toJson()); }); test('deleteRoomKeys', () async { @@ -1781,8 +1811,8 @@ void main() { final ret = await matrixApi.deleteRoomKeys('5'); expect( - FakeMatrixApi - .api['DELETE']!['/client/v3/room_keys/keys?version=5']({}), + FakeMatrixApi.api['DELETE']!['/client/v3/room_keys/keys?version=5']! + .call({}), ret.toJson()); }); test('AuthenticationData', () {