moxxmpp/packages/moxxmpp_socket_tcp/integration_test/badxmpp_certificate_test.dart

59 lines
1.6 KiB
Dart

import 'package:logging/logging.dart';
import 'package:moxxmpp/moxxmpp.dart';
import 'package:moxxmpp_socket_tcp/moxxmpp_socket_tcp.dart';
import 'package:test/test.dart';
Future<void> _runTest(String domain) async {
var gotTLSException = false;
final socket = TCPSocketWrapper(true);
final log = Logger('TestLogger');
socket.getEventStream().listen((event) {
if (event is XmppSocketTLSFailedEvent) {
log.info('Got XmppSocketTLSFailedEvent from socket');
gotTLSException = true;
}
});
final connection = XmppConnection(
TestingReconnectionPolicy(),
AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(),
socket,
)..connectionSettings = ConnectionSettings(
jid: JID.fromString('testuser@$domain'),
password: 'abc123',
);
await connection.registerFeatureNegotiators([
StartTlsNegotiator(),
]);
final result = await connection.connect(
shouldReconnect: false,
waitUntilLogin: true,
enableReconnectOnSuccess: false,
);
expect(result.isType<XmppError>(), false);
expect(gotTLSException, true);
}
void main() {
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((record) {
// ignore: avoid_print
print('${record.level.name}: ${record.time}: ${record.message}');
});
for (final domain in [
'self-signed.badxmpp.eu',
'expired.badxmpp.eu',
'wrong-name.badxmpp.eu',
'missing-chain.badxmpp.eu',
// TODO(Unknown): Technically, this one should not fail
//'ecdsa.badxmpp.eu',
]) {
test('$domain with connectAwaitable', () async {
await _runTest(domain);
});
}
}