Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(430)

Unified Diff: dart/tests/standalone/io/secure_socket_alpn_test.dart

Issue 625953002: Support for the ALPN extension of the TLS protocol for Client and Server (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add test for ALPN negotiation Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« dart/sdk/lib/io/secure_socket.dart ('K') | « dart/sdk/lib/io/secure_socket.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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']);
+}
« dart/sdk/lib/io/secure_socket.dart ('K') | « dart/sdk/lib/io/secure_socket.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698