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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4 //
5 // This test tests TLS session resume, by making multiple client connections
6 // on the same port to the same server, with a delay of 200 ms between them.
7 // The unmodified secure_server_test creates all sessions simultaneously,
8 // which means that no handshake completes and caches its keys in the session
9 // cache in time for other connections to use it.
10
11 import 'dart:io';
12 import 'dart:convert';
13
14 import 'package:expect/expect.dart';
15 import 'package:async_helper/async_helper.dart';
16
17
18 void InitializeSSL() {
19 var testPkcertDatabase = Platform.script.resolve('pkcert').toFilePath();
20 SecureSocket.initialize(database: testPkcertDatabase,
21 password: 'dartdart');
22 }
23
24
25 // Tests that client/server with same protocol can securly establish a
26 // connection, negogiate the protocol and can send data to each other.
27 void testSuccessfulAlpnNegogiationConnection(List<String> clientProtocols,
28 List<String> serverProtocols,
29 String selectedProtocol) {
30 asyncStart();
31 SecureServerSocket.bind('localhost', 0, 'localhost_cert',
32 supportedProtocols: serverProtocols).then((SecureServerSocket server) {
33
34 asyncStart();
35 server.first.then((SecureSocket socket) {
36 Expect.equals(socket.selectedProtocol, selectedProtocol);
37 socket..write('server message')..close();
38 socket.transform(ASCII.decoder).join('').then((String s) {
39 Expect.equals(s, 'client message');
40 asyncEnd();
41 });
42 });
43
44 asyncStart();
45 SecureSocket.connect('localhost', server.port,
46 supportedProtocols: clientProtocols).then((socket) {
47 Expect.equals(socket.selectedProtocol, selectedProtocol);
48 socket..write('client message')..close();
49 socket.transform(ASCII.decoder).join('').then((String s) {
50 Expect.equals(s, 'server message');
51 server.close();
52 asyncEnd();
53 });
54 });
55
56 asyncEnd();
57 });
58 }
59
60 void testFailedAlpnNegogiationConnection(List<String> clientProtocols,
61 List<String> serverProtocols) {
62 asyncStart();
63 SecureServerSocket.bind('localhost', 0, 'localhost_cert',
64 supportedProtocols: serverProtocols).then((SecureServerSocket server) {
65
66 asyncStart();
67 server.first.catchError((error, stack) {
68 asyncEnd();
69 });
70
71 asyncStart();
72 SecureSocket.connect('localhost',
73 server.port,
74 supportedProtocols: clientProtocols)
75 .catchError((error, stack) {
76 asyncEnd();
77 });
78
79 asyncEnd();
80 });
81 }
82
83 main() {
84 InitializeSSL();
85
86 // Protocols are in order of decreasing priority. First matching protocol
87 // will be taken.
88
89 // Test successfull negotiation, including priority.
90 testSuccessfulAlpnNegogiationConnection(['a'],
91 ['a'],
92 'a');
93
94 testSuccessfulAlpnNegogiationConnection(['a', 'b', 'c'],
95 ['a', 'b', 'c'],
96 'a');
97
98 testSuccessfulAlpnNegogiationConnection(['a', 'b', 'c'],
99 ['c'],
100 'c');
101
102 testSuccessfulAlpnNegogiationConnection(['a', 'b', 'c'],
103 ['c', 'b', 'a'],
104 'a');
105
106 testSuccessfulAlpnNegogiationConnection(['c'],
107 ['a', 'b', 'c'],
108 'c');
109
110 testSuccessfulAlpnNegogiationConnection(['s1', 'b', 'e1'],
111 ['s2', 'b', 'e2'],
112 'b');
113
114 // Test no protocol negotiation support
115 testSuccessfulAlpnNegogiationConnection(null,
116 null,
117 null);
118
119 testSuccessfulAlpnNegogiationConnection(['a', 'b', 'c'],
120 null,
121 null);
122
123 testSuccessfulAlpnNegogiationConnection(null,
124 ['a', 'b', 'c'],
125 null);
126
127 // Test non-overlapping protocols.
128 testFailedAlpnNegogiationConnection(['a'], ['b']);
129 }
OLDNEW
« 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