[vm/io/ssl] Update test so it forces exception when server disconnect during handshake.

This is follow-up to https://dart.googlesource.com/sdk/+/c1677553d1ef529ecdbc1caba877ae2ab5e35bd4.

Fixes https://github.com/dart-lang/sdk/issues/45049

Change-Id: I9d66ae003897131ecb911fd68a8b30496f90ec24
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/185720
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
This commit is contained in:
Alexander Aprelev 2021-02-19 17:33:24 +00:00 committed by commit-bot@chromium.org
parent 02c72dda83
commit c051bdb43a
2 changed files with 35 additions and 24 deletions

View file

@ -11,6 +11,7 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';
import "package:async_helper/async_helper.dart";
import "package:expect/expect.dart";
String getFilename(String path) => Platform.script.resolve(path).toFilePath();
@ -45,6 +46,8 @@ void main(List<String> args) async {
exit(1);
}
asyncStart();
final serverProcess = await Process.start(
Platform.executable, [Platform.script.toFilePath(), 'server']);
final serverPortCompleter = Completer<int>();
@ -65,17 +68,20 @@ void main(List<String> args) async {
int port = await serverPortCompleter.future;
var thrownException;
try {
print('client connecting...');
await SecureSocket.connect('localhost', port,
final errorCompleter = Completer();
await runZoned(() async {
var socket = await SecureSocket.connect('localhost', port,
context: clientSecurityContext);
print('client connected.');
} catch (e) {
thrownException = e;
} finally {
await serverProcess.kill();
}
print('thrownException: $thrownException');
Expect.isTrue(thrownException is HandshakeException);
socket.write(<int>[1, 2, 3]);
}, onError: (e) async {
// Even if server disconnects during later parts of handshake, since
// TLS v1.3 client might not notice it until attempt to communicate with
// the server.
print('thrownException: $e');
errorCompleter.complete(e);
});
Expect.isTrue((await errorCompleter.future) is SocketException);
await serverProcess.kill();
asyncEnd();
}

View file

@ -11,6 +11,7 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';
import "package:async_helper/async_helper.dart";
import "package:expect/expect.dart";
String getFilename(String path) => Platform.script.resolve(path).toFilePath();
@ -44,6 +45,7 @@ void main(List<String> args) async {
print('server: exiting');
exit(1);
}
asyncStart();
final serverProcess = await Process.start(
Platform.executable, [Platform.script.toFilePath(), 'server']);
@ -65,17 +67,20 @@ void main(List<String> args) async {
int port = await serverPortCompleter.future;
var thrownException;
try {
print('client connecting...');
await SecureSocket.connect('localhost', port,
final errorCompleter = Completer();
await runZoned(() async {
var socket = await SecureSocket.connect('localhost', port,
context: clientSecurityContext);
print('client connected.');
} catch (e) {
thrownException = e;
} finally {
await serverProcess.kill();
}
print('thrownException: $thrownException');
Expect.isTrue(thrownException is HandshakeException);
socket.write(<int>[1, 2, 3]);
}, onError: (e) async {
// Even if server disconnects during later parts of handshake, since
// TLS v1.3 client might not notice it until attempt to communicate with
// the server.
print('thrownException: $e');
errorCompleter.complete(e);
});
Expect.isTrue((await errorCompleter.future) is SocketException);
await serverProcess.kill();
asyncEnd();
}