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

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

Issue 23886004: Update dart:io tests to use asyncStart/asyncEnd (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 7 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 | Annotate | Revision Log
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 import "dart:async";
6 import "dart:io";
7
8 import "package:async_helper/async_helper.dart";
5 import "package:expect/expect.dart"; 9 import "package:expect/expect.dart";
6 import "package:path/path.dart"; 10 import "package:path/path.dart";
7 import "dart:async";
8 import "dart:io";
9 import "dart:isolate";
10 11
11 const HOST_NAME = "localhost"; 12 const HOST_NAME = "localhost";
12 const CERTIFICATE = "localhost_cert"; 13 const CERTIFICATE = "localhost_cert";
13 14
14 void testClientCertificate() { 15 void testClientCertificate() {
15 ReceivePort port = new ReceivePort(); 16 asyncStart();
16 SecureServerSocket.bind(HOST_NAME, 17 SecureServerSocket.bind(HOST_NAME,
17 0, 18 0,
18 CERTIFICATE, 19 CERTIFICATE,
19 requestClientCertificate: true).then((server) { 20 requestClientCertificate: true).then((server) {
20 var clientEndFuture = SecureSocket.connect(HOST_NAME, 21 var clientEndFuture = SecureSocket.connect(HOST_NAME,
21 server.port, 22 server.port,
22 sendClientCertificate: true); 23 sendClientCertificate: true);
23 server.listen((serverEnd) { 24 server.listen((serverEnd) {
24 X509Certificate certificate = serverEnd.peerCertificate; 25 X509Certificate certificate = serverEnd.peerCertificate;
25 Expect.isNotNull(certificate); 26 Expect.isNotNull(certificate);
26 Expect.equals("CN=localhost", certificate.subject); 27 Expect.equals("CN=localhost", certificate.subject);
27 Expect.equals("CN=myauthority", certificate.issuer); 28 Expect.equals("CN=myauthority", certificate.issuer);
28 clientEndFuture.then((clientEnd) { 29 clientEndFuture.then((clientEnd) {
29 X509Certificate certificate = clientEnd.peerCertificate; 30 X509Certificate certificate = clientEnd.peerCertificate;
30 Expect.isNotNull(certificate); 31 Expect.isNotNull(certificate);
31 Expect.equals("CN=localhost", certificate.subject); 32 Expect.equals("CN=localhost", certificate.subject);
32 Expect.equals("CN=myauthority", certificate.issuer); 33 Expect.equals("CN=myauthority", certificate.issuer);
33 clientEnd.close(); 34 clientEnd.close();
34 serverEnd.close(); 35 serverEnd.close();
35 server.close(); 36 server.close();
36 port.close(); 37 asyncEnd();
37 }); 38 });
38 }); 39 });
39 }); 40 });
40 } 41 }
41 42
42 void testRequiredClientCertificate() { 43 void testRequiredClientCertificate() {
43 ReceivePort port = new ReceivePort(); 44 asyncStart();
44 SecureServerSocket.bind(HOST_NAME, 45 SecureServerSocket.bind(HOST_NAME,
45 0, 46 0,
46 CERTIFICATE, 47 CERTIFICATE,
47 requireClientCertificate: true).then((server) { 48 requireClientCertificate: true).then((server) {
48 var clientEndFuture = SecureSocket.connect(HOST_NAME, 49 var clientEndFuture = SecureSocket.connect(HOST_NAME,
49 server.port, 50 server.port,
50 sendClientCertificate: true); 51 sendClientCertificate: true);
51 server.listen((serverEnd) { 52 server.listen((serverEnd) {
52 X509Certificate certificate = serverEnd.peerCertificate; 53 X509Certificate certificate = serverEnd.peerCertificate;
53 Expect.isNotNull(certificate); 54 Expect.isNotNull(certificate);
54 Expect.equals("CN=localhost", certificate.subject); 55 Expect.equals("CN=localhost", certificate.subject);
55 Expect.equals("CN=myauthority", certificate.issuer); 56 Expect.equals("CN=myauthority", certificate.issuer);
56 clientEndFuture.then((clientEnd) { 57 clientEndFuture.then((clientEnd) {
57 X509Certificate certificate = clientEnd.peerCertificate; 58 X509Certificate certificate = clientEnd.peerCertificate;
58 Expect.isNotNull(certificate); 59 Expect.isNotNull(certificate);
59 Expect.equals("CN=localhost", certificate.subject); 60 Expect.equals("CN=localhost", certificate.subject);
60 Expect.equals("CN=myauthority", certificate.issuer); 61 Expect.equals("CN=myauthority", certificate.issuer);
61 clientEnd.close(); 62 clientEnd.close();
62 serverEnd.close(); 63 serverEnd.close();
63 server.close(); 64 server.close();
64 port.close(); 65 asyncEnd();
65 }); 66 });
66 }); 67 });
67 }); 68 });
68 } 69 }
69 70
70 void testNoClientCertificate() { 71 void testNoClientCertificate() {
71 ReceivePort port = new ReceivePort(); 72 asyncStart();
72 SecureServerSocket.bind(HOST_NAME, 73 SecureServerSocket.bind(HOST_NAME,
73 0, 74 0,
74 CERTIFICATE, 75 CERTIFICATE,
75 requestClientCertificate: true).then((server) { 76 requestClientCertificate: true).then((server) {
76 var clientEndFuture = SecureSocket.connect(HOST_NAME, 77 var clientEndFuture = SecureSocket.connect(HOST_NAME,
77 server.port); 78 server.port);
78 server.listen((serverEnd) { 79 server.listen((serverEnd) {
79 X509Certificate certificate = serverEnd.peerCertificate; 80 X509Certificate certificate = serverEnd.peerCertificate;
80 Expect.isNull(certificate); 81 Expect.isNull(certificate);
81 clientEndFuture.then((clientEnd) { 82 clientEndFuture.then((clientEnd) {
82 clientEnd.close(); 83 clientEnd.close();
83 serverEnd.close(); 84 serverEnd.close();
84 server.close(); 85 server.close();
85 port.close(); 86 asyncEnd();
86 }); 87 });
87 }); 88 });
88 }); 89 });
89 } 90 }
90 91
91 void testNoRequiredClientCertificate() { 92 void testNoRequiredClientCertificate() {
92 ReceivePort port = new ReceivePort(); 93 asyncStart();
93 bool clientError = false; 94 bool clientError = false;
94 SecureServerSocket.bind(HOST_NAME, 95 SecureServerSocket.bind(HOST_NAME,
95 0, 96 0,
96 CERTIFICATE, 97 CERTIFICATE,
97 requireClientCertificate: true).then((server) { 98 requireClientCertificate: true).then((server) {
98 Future clientDone = SecureSocket.connect(HOST_NAME, server.port) 99 Future clientDone = SecureSocket.connect(HOST_NAME, server.port)
99 .catchError((e) { clientError = true; }); 100 .catchError((e) { clientError = true; });
100 server.listen((serverEnd) { 101 server.listen((serverEnd) {
101 Expect.fail("Got a unverifiable connection"); 102 Expect.fail("Got a unverifiable connection");
102 }, 103 },
103 onError: (e) { 104 onError: (e) {
104 clientDone.then((_) { 105 clientDone.then((_) {
105 Expect.isTrue(clientError); 106 Expect.isTrue(clientError);
106 server.close(); 107 server.close();
107 port.close(); 108 asyncEnd();
108 }); 109 });
109 }); 110 });
110 }); 111 });
111 } 112 }
112 113
113 void main() { 114 void main() {
114 String certificateDatabase = join(dirname(Platform.script), 'pkcert'); 115 String certificateDatabase = join(dirname(Platform.script), 'pkcert');
115 SecureSocket.initialize(database: certificateDatabase, 116 SecureSocket.initialize(database: certificateDatabase,
116 password: 'dartdart', 117 password: 'dartdart',
117 useBuiltinRoots: false); 118 useBuiltinRoots: false);
118 119
119 testClientCertificate(); 120 testClientCertificate();
120 testRequiredClientCertificate(); 121 testRequiredClientCertificate();
121 testNoClientCertificate(); 122 testNoClientCertificate();
122 testNoRequiredClientCertificate(); 123 testNoRequiredClientCertificate();
123 } 124 }
OLDNEW
« no previous file with comments | « tests/standalone/io/secure_builtin_roots_test.dart ('k') | tests/standalone/io/secure_server_closing_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698