From c051bdb43afc71126c3d7333714a0ee2c17387ec Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Fri, 19 Feb 2021 17:33:24 +0000 Subject: [PATCH] [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 Commit-Queue: Alexander Aprelev --- ...nnection_closed_during_handshake_test.dart | 30 +++++++++++-------- ...nnection_closed_during_handshake_test.dart | 29 ++++++++++-------- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/tests/standalone/io/https_connection_closed_during_handshake_test.dart b/tests/standalone/io/https_connection_closed_during_handshake_test.dart index eed79c26dd1..ca22cb084c7 100644 --- a/tests/standalone/io/https_connection_closed_during_handshake_test.dart +++ b/tests/standalone/io/https_connection_closed_during_handshake_test.dart @@ -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 args) async { exit(1); } + asyncStart(); + final serverProcess = await Process.start( Platform.executable, [Platform.script.toFilePath(), 'server']); final serverPortCompleter = Completer(); @@ -65,17 +68,20 @@ void main(List 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([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(); } diff --git a/tests/standalone_2/io/https_connection_closed_during_handshake_test.dart b/tests/standalone_2/io/https_connection_closed_during_handshake_test.dart index eed79c26dd1..4ef2fef29e2 100644 --- a/tests/standalone_2/io/https_connection_closed_during_handshake_test.dart +++ b/tests/standalone_2/io/https_connection_closed_during_handshake_test.dart @@ -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 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 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([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(); }