From c504afc944bce9680e01aa0796c5cdc09814c865 Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Sat, 23 Sep 2023 14:14:23 +0200 Subject: [PATCH] fix(xep): Fix joining a MUC making it stuck --- .../lib/src/xeps/xep_0045/xep_0045.dart | 1 + packages/moxxmpp/pubspec.yaml | 2 +- packages/moxxmpp/test/xeps/xep_0045_test.dart | 165 ++++++++++++++++++ 3 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 packages/moxxmpp/test/xeps/xep_0045_test.dart diff --git a/packages/moxxmpp/lib/src/xeps/xep_0045/xep_0045.dart b/packages/moxxmpp/lib/src/xeps/xep_0045/xep_0045.dart index bbb9156..ba9b281 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0045/xep_0045.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0045/xep_0045.dart @@ -181,6 +181,7 @@ class MUCManager extends XmppManagerBase { ), ], ), + awaitable: false, ), ); } diff --git a/packages/moxxmpp/pubspec.yaml b/packages/moxxmpp/pubspec.yaml index 686f02e..852dccb 100644 --- a/packages/moxxmpp/pubspec.yaml +++ b/packages/moxxmpp/pubspec.yaml @@ -28,5 +28,5 @@ dependencies: dev_dependencies: build_runner: ^2.1.11 - test: ^1.16.0 + test: ^1.18.0 very_good_analysis: ^3.0.1 diff --git a/packages/moxxmpp/test/xeps/xep_0045_test.dart b/packages/moxxmpp/test/xeps/xep_0045_test.dart new file mode 100644 index 0000000..4dd8aea --- /dev/null +++ b/packages/moxxmpp/test/xeps/xep_0045_test.dart @@ -0,0 +1,165 @@ +import 'package:logging/logging.dart'; +import 'package:moxxmpp/moxxmpp.dart'; +import 'package:test/test.dart'; +import '../helpers/logging.dart'; +import '../helpers/xmpp.dart'; + +void main() { + initLogger(); + + test( + 'Test connecting to MUCs after a reconnection without stream resumption', + () async { + final fakeSocket = StubTCPSocket([ + StringExpectation( + "", + ''' + + + + PLAIN + + + + + ''', + ), + StringExpectation( + "AHBvbHlub21kaXZpc2lvbgBhYWFh", + '', + ), + StringExpectation( + "", + ''' + + + + + + + + + + + +''', + ), + StanzaExpectation( + '', + 'polynomdivision@test.server/MU29eEZn', + ignoreId: true, + ), + StanzaExpectation( + '', + '', + ignoreId: true, + ), + StringExpectation( + "", + ''' + + + + PLAIN + + + + + ''', + ), + StringExpectation( + "AHBvbHlub21kaXZpc2lvbgBhYWFh", + '', + ), + StringExpectation( + "", + ''' + + + + + + + + + + + +''', + ), + StanzaExpectation( + '', + 'polynomdivision@test.server/MU29eEZn', + ignoreId: true, + ), + StanzaExpectation( + '', + '', + ignoreId: true, + ), + ]); + final conn = XmppConnection( + TestingSleepReconnectionPolicy(1), + AlwaysConnectedConnectivityManager(), + ClientToServerNegotiator(), + fakeSocket, + ) + ..connectionSettings = ConnectionSettings( + jid: JID.fromString('polynomdivision@test.server'), + password: 'aaaa', + ) + ..setResource('test-resource', triggerEvent: false); + await conn.registerManagers([ + DiscoManager([]), + MUCManager(), + ]); + + await conn.registerFeatureNegotiators([ + SaslPlainNegotiator(), + ResourceBindingNegotiator(), + ]); + + await conn.connect( + waitUntilLogin: true, + shouldReconnect: true, + ); + + // Join a groupchat + final joinResult = + await conn.getManagerById(mucManager)!.joinRoom( + JID.fromString('channel@muc.example.org'), + 'test', + maxHistoryStanzas: 0, + ); + expect(joinResult.isType(), true); + expect(joinResult.get(), true); + + // Trigger a reconnection reason. + Logger('Test').info('Injecting socket fault'); + fakeSocket.injectSocketFault(); + + await Future.delayed(const Duration(seconds: 4)); + expect(fakeSocket.getState(), 10); + }, + ); +}