import 'package:moxxmpp/moxxmpp.dart'; import 'package:test/test.dart'; import '../helpers/logging.dart'; import '../helpers/xmpp.dart'; void main() { initLogger(); test('Test simple Bind2 negotiation', () async { final fakeSocket = StubTCPSocket([ StringExpectation( "", ''' PLAIN PLAIN ''', ), StanzaExpectation( "moxxmppPapaTutuWawa's awesome deviceAHBvbHlub21kaXZpc2lvbgBhYWFh", ''' polynomdivision@test.server/random.resource ''', ), ]); final conn = XmppConnection( TestingReconnectionPolicy(), AlwaysConnectedConnectivityManager(), fakeSocket, )..setConnectionSettings( ConnectionSettings( jid: JID.fromString('polynomdivision@test.server'), password: 'aaaa', useDirectTLS: true, ), ); await conn.registerManagers([ PresenceManager(), RosterManager(TestingRosterStateManager('', [])), DiscoManager([]), ]); await conn.registerFeatureNegotiators([ SaslPlainNegotiator(), ResourceBindingNegotiator(), Bind2Negotiator(), 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, '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'); }); }