diff --git a/packages/moxxmpp/lib/src/xeps/xep_0386.dart b/packages/moxxmpp/lib/src/xeps/xep_0386.dart index 7bc40b2..033a82f 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0386.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0386.dart @@ -10,6 +10,9 @@ import 'package:moxxmpp/src/types/result.dart'; class Bind2Negotiator extends Sasl2FeatureNegotiator { Bind2Negotiator() : super(0, false, bind2Xmlns, bind2Negotiator); + /// A tag to sent to the server when requesting Bind2. + String? tag; + @override Future> negotiate( XMLNode nonza, @@ -23,6 +26,13 @@ class Bind2Negotiator extends Sasl2FeatureNegotiator { XMLNode.xmlns( tag: 'bind', xmlns: bind2Xmlns, + children: [ + if (tag != null) + XMLNode( + tag: 'tag', + text: tag, + ), + ], ), ]; } diff --git a/packages/moxxmpp/test/xeps/xep_0386_test.dart b/packages/moxxmpp/test/xeps/xep_0386_test.dart index c9aaccf..b7b5864 100644 --- a/packages/moxxmpp/test/xeps/xep_0386_test.dart +++ b/packages/moxxmpp/test/xeps/xep_0386_test.dart @@ -78,4 +78,77 @@ void main() { expect(result.isType(), false); expect(conn.resource, 'random.resource'); }); + + test('Test simple Bind2 negotiation with a provided tag', () async { + final fakeSocket = StubTCPSocket([ + StringExpectation( + "", + ''' + + + + PLAIN + + + PLAIN + + + + + + + + ''', + ), + StanzaExpectation( + "moxxmppPapaTutuWawa's awesome deviceAHBvbHlub21kaXZpc2lvbgBhYWFhmoxxmpp", + ''' + + polynomdivision@test.server/moxxmpp.random.resource + + ''', + ), + ]); + final conn = XmppConnection( + TestingReconnectionPolicy(), + AlwaysConnectedConnectivityManager(), + fakeSocket, + )..setConnectionSettings( + ConnectionSettings( + jid: JID.fromString('polynomdivision@test.server'), + password: 'aaaa', + useDirectTLS: true, + ), + ); + await conn.registerManagers([ + RosterManager(TestingRosterStateManager('', [])), + DiscoManager([]), + ]); + await conn.registerFeatureNegotiators([ + SaslPlainNegotiator(), + ResourceBindingNegotiator(), + Bind2Negotiator() + ..tag = 'moxxmpp', + Sasl2Negotiator( + userAgent: const UserAgent( + id: 'd4565fa7-4d72-4749-b3d3-740edbf87770', + software: 'moxxmpp', + device: "PapaTutuWawa's awesome device", + ), + ), + ]); + + final result = await conn.connect( + waitUntilLogin: true, + shouldReconnect: false, + enableReconnectOnSuccess: false, + ); + expect(result.isType(), false); + expect(conn.resource, 'moxxmpp.random.resource'); + }); }