2023-04-02 15:20:14 +00:00
|
|
|
import 'package:logging/logging.dart';
|
|
|
|
import 'package:moxxmpp/moxxmpp.dart';
|
|
|
|
import 'package:moxxmpp_socket_tcp/moxxmpp_socket_tcp.dart';
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
|
|
|
class TestingTCPSocketWrapper extends TCPSocketWrapper {
|
|
|
|
@override
|
|
|
|
bool onBadCertificate(dynamic certificate, String domain) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
Logger.root.level = Level.ALL;
|
|
|
|
Logger.root.onRecord.listen((record) {
|
|
|
|
// ignore: avoid_print
|
|
|
|
print(
|
|
|
|
'[${record.level.name}] (${record.loggerName}) ${record.time}: ${record.message}',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2023-04-04 13:48:26 +00:00
|
|
|
test('Test authenticating against Prosody with SASL2, Bind2, and FAST',
|
|
|
|
() async {
|
2023-04-02 15:20:14 +00:00
|
|
|
final conn = XmppConnection(
|
|
|
|
TestingReconnectionPolicy(),
|
|
|
|
AlwaysConnectedConnectivityManager(),
|
2023-04-04 13:48:26 +00:00
|
|
|
ClientToServerNegotiator(),
|
2023-04-02 15:20:14 +00:00
|
|
|
TestingTCPSocketWrapper(),
|
2023-04-04 13:48:26 +00:00
|
|
|
)..connectionSettings = ConnectionSettings(
|
|
|
|
jid: JID.fromString('testuser@localhost'),
|
|
|
|
password: 'abc123',
|
|
|
|
host: '127.0.0.1',
|
|
|
|
port: 5222,
|
2023-04-02 15:20:14 +00:00
|
|
|
);
|
|
|
|
final csi = CSIManager();
|
|
|
|
await csi.setInactive(sendNonza: false);
|
|
|
|
await conn.registerManagers([
|
|
|
|
RosterManager(TestingRosterStateManager('', [])),
|
|
|
|
DiscoManager([]),
|
|
|
|
]);
|
|
|
|
await conn.registerFeatureNegotiators([
|
|
|
|
SaslPlainNegotiator(),
|
|
|
|
ResourceBindingNegotiator(),
|
|
|
|
FASTSaslNegotiator(),
|
|
|
|
Bind2Negotiator(),
|
|
|
|
StartTlsNegotiator(),
|
|
|
|
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<bool>(), true);
|
2023-04-04 13:48:26 +00:00
|
|
|
expect(
|
|
|
|
conn.getNegotiatorById<Sasl2Negotiator>(sasl2Negotiator)!.state,
|
|
|
|
NegotiatorState.done,
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
conn
|
|
|
|
.getNegotiatorById<FASTSaslNegotiator>(saslFASTNegotiator)!
|
|
|
|
.fastToken !=
|
|
|
|
null,
|
|
|
|
true,
|
|
|
|
);
|
2023-04-02 15:20:14 +00:00
|
|
|
});
|
|
|
|
}
|