| Index: dart/tests/standalone/io/secure_socket_alpn_test.dart
|
| diff --git a/dart/tests/standalone/io/secure_socket_alpn_test.dart b/dart/tests/standalone/io/secure_socket_alpn_test.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a5d10298bbf1a0bca0f453ee7f2ef8c49ed43e5c
|
| --- /dev/null
|
| +++ b/dart/tests/standalone/io/secure_socket_alpn_test.dart
|
| @@ -0,0 +1,129 @@
|
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +//
|
| +// This test tests TLS session resume, by making multiple client connections
|
| +// on the same port to the same server, with a delay of 200 ms between them.
|
| +// The unmodified secure_server_test creates all sessions simultaneously,
|
| +// which means that no handshake completes and caches its keys in the session
|
| +// cache in time for other connections to use it.
|
| +
|
| +import 'dart:io';
|
| +import 'dart:convert';
|
| +
|
| +import 'package:expect/expect.dart';
|
| +import 'package:async_helper/async_helper.dart';
|
| +
|
| +
|
| +void InitializeSSL() {
|
| + var testPkcertDatabase = Platform.script.resolve('pkcert').toFilePath();
|
| + SecureSocket.initialize(database: testPkcertDatabase,
|
| + password: 'dartdart');
|
| +}
|
| +
|
| +
|
| +// Tests that client/server with same protocol can securly establish a
|
| +// connection, negogiate the protocol and can send data to each other.
|
| +void testSuccessfulAlpnNegogiationConnection(List<String> clientProtocols,
|
| + List<String> serverProtocols,
|
| + String selectedProtocol) {
|
| + asyncStart();
|
| + SecureServerSocket.bind('localhost', 0, 'localhost_cert',
|
| + supportedProtocols: serverProtocols).then((SecureServerSocket server) {
|
| +
|
| + asyncStart();
|
| + server.first.then((SecureSocket socket) {
|
| + Expect.equals(socket.selectedProtocol, selectedProtocol);
|
| + socket..write('server message')..close();
|
| + socket.transform(ASCII.decoder).join('').then((String s) {
|
| + Expect.equals(s, 'client message');
|
| + asyncEnd();
|
| + });
|
| + });
|
| +
|
| + asyncStart();
|
| + SecureSocket.connect('localhost', server.port,
|
| + supportedProtocols: clientProtocols).then((socket) {
|
| + Expect.equals(socket.selectedProtocol, selectedProtocol);
|
| + socket..write('client message')..close();
|
| + socket.transform(ASCII.decoder).join('').then((String s) {
|
| + Expect.equals(s, 'server message');
|
| + server.close();
|
| + asyncEnd();
|
| + });
|
| + });
|
| +
|
| + asyncEnd();
|
| + });
|
| +}
|
| +
|
| +void testFailedAlpnNegogiationConnection(List<String> clientProtocols,
|
| + List<String> serverProtocols) {
|
| + asyncStart();
|
| + SecureServerSocket.bind('localhost', 0, 'localhost_cert',
|
| + supportedProtocols: serverProtocols).then((SecureServerSocket server) {
|
| +
|
| + asyncStart();
|
| + server.first.catchError((error, stack) {
|
| + asyncEnd();
|
| + });
|
| +
|
| + asyncStart();
|
| + SecureSocket.connect('localhost',
|
| + server.port,
|
| + supportedProtocols: clientProtocols)
|
| + .catchError((error, stack) {
|
| + asyncEnd();
|
| + });
|
| +
|
| + asyncEnd();
|
| + });
|
| +}
|
| +
|
| +main() {
|
| + InitializeSSL();
|
| +
|
| + // Protocols are in order of decreasing priority. First matching protocol
|
| + // will be taken.
|
| +
|
| + // Test successfull negotiation, including priority.
|
| + testSuccessfulAlpnNegogiationConnection(['a'],
|
| + ['a'],
|
| + 'a');
|
| +
|
| + testSuccessfulAlpnNegogiationConnection(['a', 'b', 'c'],
|
| + ['a', 'b', 'c'],
|
| + 'a');
|
| +
|
| + testSuccessfulAlpnNegogiationConnection(['a', 'b', 'c'],
|
| + ['c'],
|
| + 'c');
|
| +
|
| + testSuccessfulAlpnNegogiationConnection(['a', 'b', 'c'],
|
| + ['c', 'b', 'a'],
|
| + 'a');
|
| +
|
| + testSuccessfulAlpnNegogiationConnection(['c'],
|
| + ['a', 'b', 'c'],
|
| + 'c');
|
| +
|
| + testSuccessfulAlpnNegogiationConnection(['s1', 'b', 'e1'],
|
| + ['s2', 'b', 'e2'],
|
| + 'b');
|
| +
|
| + // Test no protocol negotiation support
|
| + testSuccessfulAlpnNegogiationConnection(null,
|
| + null,
|
| + null);
|
| +
|
| + testSuccessfulAlpnNegogiationConnection(['a', 'b', 'c'],
|
| + null,
|
| + null);
|
| +
|
| + testSuccessfulAlpnNegogiationConnection(null,
|
| + ['a', 'b', 'c'],
|
| + null);
|
| +
|
| + // Test non-overlapping protocols.
|
| + testFailedAlpnNegogiationConnection(['a'], ['b']);
|
| +}
|
|
|