| Index: tests/standalone/io/secure_socket_alpn_test.dart
|
| diff --git a/tests/standalone/io/secure_socket_alpn_test.dart b/tests/standalone/io/secure_socket_alpn_test.dart
|
| index 6b835e677b30bab87777a01f2cb2cbb293d699d6..bc459e207414685e0f77a1905d2de3b65b0de669 100644
|
| --- a/tests/standalone/io/secure_socket_alpn_test.dart
|
| +++ b/tests/standalone/io/secure_socket_alpn_test.dart
|
| @@ -12,8 +12,7 @@ import 'dart:convert';
|
| import 'package:expect/expect.dart';
|
| import 'package:async_helper/async_helper.dart';
|
|
|
| -const String NAME_LENGTH_ERROR =
|
| - 'Length of protocol must be between 1 and 255';
|
| +const String NAME_LENGTH_ERROR = 'Length of protocol must be between 1 and 255';
|
|
|
| const String MESSAGE_LENGTH_ERROR =
|
| 'The maximum message length supported is 2^13-1';
|
| @@ -26,22 +25,23 @@ SecurityContext clientContext() => new SecurityContext()
|
| SecurityContext serverContext() => new SecurityContext()
|
| ..useCertificateChain(localFile('certificates/server_chain.pem'))
|
| ..usePrivateKey(localFile('certificates/server_key.pem'),
|
| - password: 'dartdart');
|
| + password: 'dartdart');
|
|
|
| // Tests that client/server with same protocol can securely establish a
|
| // connection, negotiate the protocol and can send data to each other.
|
| void testSuccessfulAlpnNegotiationConnection(List<String> clientProtocols,
|
| - List<String> serverProtocols,
|
| - String selectedProtocol) {
|
| + List<String> serverProtocols, String selectedProtocol) {
|
| asyncStart();
|
| var sContext = serverContext()..setAlpnProtocols(serverProtocols, true);
|
| - SecureServerSocket.bind('localhost', 0, sContext)
|
| - .then((SecureServerSocket server) {
|
| -
|
| + SecureServerSocket
|
| + .bind('localhost', 0, sContext)
|
| + .then((SecureServerSocket server) {
|
| asyncStart();
|
| server.first.then((SecureSocket socket) {
|
| Expect.equals(selectedProtocol, socket.selectedProtocol);
|
| - socket..write('server message')..close();
|
| + socket
|
| + ..write('server message')
|
| + ..close();
|
| socket.transform(ASCII.decoder).join('').then((String s) {
|
| Expect.equals('client message', s);
|
| asyncEnd();
|
| @@ -49,10 +49,14 @@ void testSuccessfulAlpnNegotiationConnection(List<String> clientProtocols,
|
| });
|
|
|
| asyncStart();
|
| - SecureSocket.connect('localhost', server.port, context: clientContext(),
|
| - supportedProtocols: clientProtocols).then((socket) {
|
| + SecureSocket
|
| + .connect('localhost', server.port,
|
| + context: clientContext(), supportedProtocols: clientProtocols)
|
| + .then((socket) {
|
| Expect.equals(selectedProtocol, socket.selectedProtocol);
|
| - socket..write('client message')..close();
|
| + socket
|
| + ..write('client message')
|
| + ..close();
|
| socket.transform(ASCII.decoder).join('').then((String s) {
|
| Expect.equals('server message', s);
|
| server.close();
|
| @@ -70,8 +74,8 @@ void testInvalidArgument(List<String> protocols, String errorIncludes) {
|
| testInvalidArgumentClientConnect(protocols, errorIncludes);
|
| }
|
|
|
| -void testInvalidArgumentServerContext(List<String> protocols,
|
| - String errorIncludes) {
|
| +void testInvalidArgumentServerContext(
|
| + List<String> protocols, String errorIncludes) {
|
| Expect.throws(() => serverContext().setAlpnProtocols(protocols, true), (e) {
|
| Expect.isTrue(e is ArgumentError);
|
| Expect.isTrue(e.toString().contains(errorIncludes));
|
| @@ -79,8 +83,8 @@ void testInvalidArgumentServerContext(List<String> protocols,
|
| });
|
| }
|
|
|
| -void testInvalidArgumentClientContext(List<String> protocols,
|
| - String errorIncludes) {
|
| +void testInvalidArgumentClientContext(
|
| + List<String> protocols, String errorIncludes) {
|
| Expect.throws(() => clientContext().setAlpnProtocols(protocols, false), (e) {
|
| Expect.isTrue(e is ArgumentError);
|
| Expect.isTrue(e.toString().contains(errorIncludes));
|
| @@ -88,8 +92,8 @@ void testInvalidArgumentClientContext(List<String> protocols,
|
| });
|
| }
|
|
|
| -void testInvalidArgumentClientConnect(List<String> protocols,
|
| - String errorIncludes) {
|
| +void testInvalidArgumentClientConnect(
|
| + List<String> protocols, String errorIncludes) {
|
| asyncStart();
|
| var sContext = serverContext()..setAlpnProtocols(['abc'], true);
|
| SecureServerSocket.bind('localhost', 0, sContext).then((server) async {
|
| @@ -99,11 +103,15 @@ void testInvalidArgumentClientConnect(List<String> protocols,
|
| "Unexpected connection made to server, with bad client argument");
|
| }, onError: (e) {
|
| Expect.fail("Unexpected error on server stream: $e");
|
| - }, onDone: () { asyncEnd();});
|
| + }, onDone: () {
|
| + asyncEnd();
|
| + });
|
|
|
| asyncStart();
|
| - SecureSocket.connect('localhost', server.port, context: clientContext(),
|
| - supportedProtocols: protocols).then((socket) {
|
| + SecureSocket
|
| + .connect('localhost', server.port,
|
| + context: clientContext(), supportedProtocols: protocols)
|
| + .then((socket) {
|
| Expect.fail(
|
| "Unexpected connection made from client, with bad client argument");
|
| }, onError: (e) {
|
| @@ -127,75 +135,50 @@ main() {
|
|
|
| // This produces a message of (1 << 13) - 2 bytes. 2^12 -1 strings are each
|
| // encoded by 1 length byte and 1 ascii byte.
|
| - final List<String> manyProtocols = new Iterable.generate(
|
| - (1 << 12) - 1, (i) => '0').toList();
|
| + final List<String> manyProtocols =
|
| + new Iterable.generate((1 << 12) - 1, (i) => '0').toList();
|
|
|
| // This produces a message of (1 << 13) bytes. 2^12 strings are each
|
| // encoded by 1 length byte and 1 ascii byte.
|
| - final List<String> tooManyProtocols = new Iterable.generate(
|
| - (1 << 12), (i) => '0').toList();
|
| + final List<String> tooManyProtocols =
|
| + new Iterable.generate((1 << 12), (i) => '0').toList();
|
|
|
| // Protocols are in order of decreasing priority. The server will select
|
| // the first protocol from its list that has a match in the client list.
|
| // Test successful negotiation, including priority.
|
| - testSuccessfulAlpnNegotiationConnection(['a'],
|
| - ['a'],
|
| - 'a');
|
| -
|
| - testSuccessfulAlpnNegotiationConnection([longname255],
|
| - [longname255],
|
| - longname255);
|
| -
|
| - testSuccessfulAlpnNegotiationConnection([strangelongname255],
|
| - [strangelongname255],
|
| - strangelongname255);
|
| - testSuccessfulAlpnNegotiationConnection(manyProtocols,
|
| - manyProtocols,
|
| - '0');
|
| - testSuccessfulAlpnNegotiationConnection(['a', 'b', 'c'],
|
| - ['a', 'b', 'c'],
|
| - 'a');
|
| -
|
| - testSuccessfulAlpnNegotiationConnection(['a', 'b', 'c'],
|
| - ['c'],
|
| - 'c');
|
| + testSuccessfulAlpnNegotiationConnection(['a'], ['a'], 'a');
|
| +
|
| + testSuccessfulAlpnNegotiationConnection(
|
| + [longname255], [longname255], longname255);
|
| +
|
| + testSuccessfulAlpnNegotiationConnection(
|
| + [strangelongname255], [strangelongname255], strangelongname255);
|
| + testSuccessfulAlpnNegotiationConnection(manyProtocols, manyProtocols, '0');
|
| + testSuccessfulAlpnNegotiationConnection(
|
| + ['a', 'b', 'c'], ['a', 'b', 'c'], 'a');
|
| +
|
| + testSuccessfulAlpnNegotiationConnection(['a', 'b', 'c'], ['c'], 'c');
|
|
|
| // Server precedence.
|
| - testSuccessfulAlpnNegotiationConnection(['a', 'b', 'c'],
|
| - ['c', 'b', 'a'],
|
| - 'c');
|
| + testSuccessfulAlpnNegotiationConnection(
|
| + ['a', 'b', 'c'], ['c', 'b', 'a'], 'c');
|
|
|
| - testSuccessfulAlpnNegotiationConnection(['c'],
|
| - ['a', 'b', 'c'],
|
| - 'c');
|
| + testSuccessfulAlpnNegotiationConnection(['c'], ['a', 'b', 'c'], 'c');
|
|
|
| - testSuccessfulAlpnNegotiationConnection(['s1', 'b', 'e1'],
|
| - ['s2', 'b', 'e2'],
|
| - 'b');
|
| + testSuccessfulAlpnNegotiationConnection(
|
| + ['s1', 'b', 'e1'], ['s2', 'b', 'e2'], 'b');
|
| // Test no protocol negotiation support
|
| - testSuccessfulAlpnNegotiationConnection(null,
|
| - null,
|
| - null);
|
| + testSuccessfulAlpnNegotiationConnection(null, null, null);
|
|
|
| - testSuccessfulAlpnNegotiationConnection(['a', 'b', 'c'],
|
| - null,
|
| - null);
|
| + testSuccessfulAlpnNegotiationConnection(['a', 'b', 'c'], null, null);
|
|
|
| - testSuccessfulAlpnNegotiationConnection(null,
|
| - ['a', 'b', 'c'],
|
| - null);
|
| + testSuccessfulAlpnNegotiationConnection(null, ['a', 'b', 'c'], null);
|
|
|
| - testSuccessfulAlpnNegotiationConnection([],
|
| - [],
|
| - null);
|
| + testSuccessfulAlpnNegotiationConnection([], [], null);
|
|
|
| - testSuccessfulAlpnNegotiationConnection(['a', 'b', 'c'],
|
| - [],
|
| - null);
|
| + testSuccessfulAlpnNegotiationConnection(['a', 'b', 'c'], [], null);
|
|
|
| - testSuccessfulAlpnNegotiationConnection([],
|
| - ['a', 'b', 'c'],
|
| - null);
|
| + testSuccessfulAlpnNegotiationConnection([], ['a', 'b', 'c'], null);
|
|
|
| // Test non-overlapping protocols. The ALPN RFC says the connection
|
| // should be terminated, but OpenSSL continues as if no ALPN is present.
|
|
|