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

Side by Side Diff: tests/standalone/io/secure_client_server_test.dart

Issue 1319703002: Breaking Change: merge BoringSSL branch into master (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 // 4 //
5 // VMOptions= 5 // VMOptions=
6 // VMOptions=--short_socket_read 6 // VMOptions=--short_socket_read
7 // VMOptions=--short_socket_write 7 // VMOptions=--short_socket_write
8 // VMOptions=--short_socket_read --short_socket_write 8 // VMOptions=--short_socket_read --short_socket_write
9 9
10 import "dart:async"; 10 import "dart:async";
11 import "dart:io"; 11 import "dart:io";
12 12
13 import "package:async_helper/async_helper.dart"; 13 import "package:async_helper/async_helper.dart";
14 import "package:expect/expect.dart"; 14 import "package:expect/expect.dart";
15 15
16 InternetAddress HOST; 16 InternetAddress HOST;
17 const CERTIFICATE = "localhost_cert"; 17
18 String localFile(path) => Platform.script.resolve(path).toFilePath();
19
20 SecurityContext serverContext = new SecurityContext()
21 ..useCertificateChain(localFile('certificates/server_chain.pem'))
22 ..usePrivateKey(localFile('certificates/server_key.pem'),
23 password: 'dartdart');
24
25 SecurityContext clientContext = new SecurityContext()
26 ..setTrustedCertificates(file: localFile('certificates/trusted_certs.pem'));
27
28
18 Future<SecureServerSocket> startEchoServer() { 29 Future<SecureServerSocket> startEchoServer() {
19 return SecureServerSocket.bind(HOST, 30 return SecureServerSocket.bind(HOST,
20 0, 31 0,
21 CERTIFICATE).then((server) { 32 serverContext).then((server) {
22 server.listen((SecureSocket client) { 33 server.listen((SecureSocket client) {
23 client.fold(<int>[], (message, data) => message..addAll(data)) 34 client.fold(<int>[], (message, data) => message..addAll(data))
24 .then((message) { 35 .then((message) {
25 client.add(message); 36 client.add(message);
26 client.close(); 37 client.close();
27 }); 38 });
28 }); 39 });
29 return server; 40 return server;
30 }); 41 });
31 } 42 }
32 43
33 Future testClient(server) { 44 Future testClient(server) {
34 return SecureSocket.connect(HOST, server.port).then((socket) { 45 return SecureSocket.connect(HOST, server.port, context: clientContext)
46 .then((socket) {
35 socket.write("Hello server."); 47 socket.write("Hello server.");
36 socket.close(); 48 socket.close();
37 return socket.fold(<int>[], (message, data) => message..addAll(data)) 49 return socket.fold(<int>[], (message, data) => message..addAll(data))
38 .then((message) { 50 .then((message) {
39 Expect.listEquals("Hello server.".codeUnits, message); 51 Expect.listEquals("Hello server.".codeUnits, message);
40 return server; 52 return server;
41 }); 53 });
42 }); 54 });
43 } 55 }
44 56
45 void main() { 57 void main() {
46 asyncStart(); 58 asyncStart();
47 String certificateDatabase = Platform.script.resolve('pkcert').toFilePath();
48 SecureSocket.initialize(database: certificateDatabase,
49 password: 'dartdart');
50 InternetAddress.lookup("localhost").then((hosts) => HOST = hosts.first ) 59 InternetAddress.lookup("localhost").then((hosts) => HOST = hosts.first )
51 .then((_) => startEchoServer()) 60 .then((_) => startEchoServer())
52 .then(testClient) 61 .then(testClient)
53 .then((server) => server.close()) 62 .then((server) => server.close())
54 .then((_) => asyncEnd()); 63 .then((_) => asyncEnd());
55 } 64 }
OLDNEW
« no previous file with comments | « tests/standalone/io/secure_client_raw_server_test.dart ('k') | tests/standalone/io/secure_multiple_client_server_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698