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

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

Issue 1665433002: Adds SecurityContext.setTrustedCertificatesBytes (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Adds MemBIOScope Created 4 years, 10 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 SecureServerSocket SERVER; 17 SecureServerSocket SERVER;
18 18
19 String localFile(path) => Platform.script.resolve(path).toFilePath(); 19 String localFile(path) => Platform.script.resolve(path).toFilePath();
20 List<int> readLocalFile(path) => (new File(localFile(path))).readAsBytesSync(); 20 List<int> readLocalFile(path) => (new File(localFile(path))).readAsBytesSync();
21 21
22 SecurityContext serverContext = new SecurityContext() 22 SecurityContext serverContext = new SecurityContext()
23 ..useCertificateChainBytes(readLocalFile('certificates/server_chain.pem')) 23 ..useCertificateChainBytes(readLocalFile('certificates/server_chain.pem'))
24 ..usePrivateKeyBytes(readLocalFile('certificates/server_key.pem'), 24 ..usePrivateKeyBytes(readLocalFile('certificates/server_key.pem'),
25 password: 'dartdart'); 25 password: 'dartdart');
26 26
27 SecurityContext clientContext = new SecurityContext() 27 SecurityContext clientContext = new SecurityContext()
28 ..setTrustedCertificates(file: localFile('certificates/trusted_certs.pem')); 28 ..setTrustedCertificatesBytes(
29 readLocalFile('certificates/trusted_certs.pem'));
29 30
30 Future startServer() { 31 Future startServer() {
31 return SecureServerSocket.bind(HOST, 0, serverContext).then((server) { 32 return SecureServerSocket.bind(HOST, 0, serverContext).then((server) {
32 SERVER = server; 33 SERVER = server;
33 SERVER.listen((SecureSocket client) { 34 SERVER.listen((SecureSocket client) {
34 client.fold(<int>[], (message, data) => message..addAll(data)) 35 client.fold(<int>[], (message, data) => message..addAll(data))
35 .then((message) { 36 .then((message) {
36 String received = new String.fromCharCodes(message); 37 String received = new String.fromCharCodes(message);
37 Expect.isTrue(received.contains("Hello from client ")); 38 Expect.isTrue(received.contains("Hello from client "));
38 String name = received.substring(received.indexOf("client ") + 7); 39 String name = received.substring(received.indexOf("client ") + 7);
(...skipping 18 matching lines...) Expand all
57 58
58 void main() { 59 void main() {
59 asyncStart(); 60 asyncStart();
60 InternetAddress.lookup("localhost").then((hosts) => HOST = hosts.first) 61 InternetAddress.lookup("localhost").then((hosts) => HOST = hosts.first)
61 .then((_) => startServer()) 62 .then((_) => startServer())
62 .then((_) => ['ale', 'bar', 'che', 'den', 'els'].map(testClient)) 63 .then((_) => ['ale', 'bar', 'che', 'den', 'els'].map(testClient))
63 .then((futures) => Future.wait(futures)) 64 .then((futures) => Future.wait(futures))
64 .then((_) => SERVER.close()) 65 .then((_) => SERVER.close())
65 .then((_) => asyncEnd()); 66 .then((_) => asyncEnd());
66 } 67 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698