moxxmpp/packages/moxxmpp_socket_tcp/integration_test/badxmpp_certificate_test.dart

59 lines
1.6 KiB
Dart
Raw Permalink Normal View History

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(
2023-03-30 14:15:44 +00:00
TestingReconnectionPolicy(),
AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(),
socket,
)..connectionSettings = ConnectionSettings(
jid: JID.fromString('testuser@$domain'),
password: 'abc123',
);
2023-04-02 12:38:32 +00:00
await connection.registerFeatureNegotiators([
StartTlsNegotiator(),
]);
2023-03-30 14:15:44 +00:00
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) {
2023-03-30 14:15:44 +00:00
// 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);
});
}
}