OLD | NEW |
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 // OtherResources=certificates/server_chain.pem | 9 // OtherResources=certificates/server_chain.pem |
10 // OtherResources=certificates/server_key.pem | 10 // OtherResources=certificates/server_key.pem |
11 // OtherResources=certificates/trusted_certs.pem | 11 // OtherResources=certificates/trusted_certs.pem |
12 // OtherResources=certificates/untrusted_server_chain.pem | 12 // OtherResources=certificates/untrusted_server_chain.pem |
13 // OtherResources=certificates/untrusted_server_key.pem | 13 // OtherResources=certificates/untrusted_server_key.pem |
14 | 14 |
15 import "dart:async"; | 15 import "dart:async"; |
16 import "dart:io"; | 16 import "dart:io"; |
17 | 17 |
18 import "package:async_helper/async_helper.dart"; | 18 import "package:async_helper/async_helper.dart"; |
19 import "package:expect/expect.dart"; | 19 import "package:expect/expect.dart"; |
20 | 20 |
21 InternetAddress HOST; | 21 InternetAddress HOST; |
22 String localFile(path) => Platform.script.resolve(path).toFilePath(); | 22 String localFile(path) => Platform.script.resolve(path).toFilePath(); |
23 | 23 |
24 SecurityContext serverContext = new SecurityContext() | 24 SecurityContext serverContext = new SecurityContext() |
25 ..useCertificateChain(localFile('certificates/server_chain.pem')) | 25 ..useCertificateChain(localFile('certificates/server_chain.pem')) |
26 ..usePrivateKey(localFile('certificates/server_key.pem'), | 26 ..usePrivateKey(localFile('certificates/server_key.pem'), |
27 password: 'dartdart'); | 27 password: 'dartdart'); |
28 | 28 |
29 SecurityContext clientContext = new SecurityContext() | 29 SecurityContext clientContext = new SecurityContext() |
30 ..setTrustedCertificates(localFile('certificates/trusted_certs.pem')); | 30 ..setTrustedCertificates(localFile('certificates/trusted_certs.pem')); |
31 | 31 |
32 void testSimpleBind() { | 32 void testSimpleBind() { |
33 print("asyncStart testSimpleBind"); | 33 print("asyncStart testSimpleBind"); |
34 asyncStart(); | 34 asyncStart(); |
35 RawSecureServerSocket.bind(HOST, 0, serverContext).then((s) { | 35 RawSecureServerSocket.bind(HOST, 0, serverContext).then((s) { |
36 Expect.isTrue(s.port > 0); | 36 Expect.isTrue(s.port > 0); |
37 s.close(); | 37 s.close(); |
(...skipping 24 matching lines...) Expand all Loading... |
62 }).catchError((error) { | 62 }).catchError((error) { |
63 Expect.isTrue(error is SocketException); | 63 Expect.isTrue(error is SocketException); |
64 print("asyncEnd testInvalidBind 2"); | 64 print("asyncEnd testInvalidBind 2"); |
65 asyncEnd(); | 65 asyncEnd(); |
66 }); | 66 }); |
67 | 67 |
68 // Bind to a port already in use. | 68 // Bind to a port already in use. |
69 asyncStart(); | 69 asyncStart(); |
70 print("asyncStart testInvalidBind 3"); | 70 print("asyncStart testInvalidBind 3"); |
71 RawSecureServerSocket.bind(HOST, 0, serverContext).then((s) { | 71 RawSecureServerSocket.bind(HOST, 0, serverContext).then((s) { |
72 RawSecureServerSocket.bind(HOST, | 72 RawSecureServerSocket.bind(HOST, s.port, serverContext).then((t) { |
73 s.port, | |
74 serverContext).then((t) { | |
75 s.close(); | 73 s.close(); |
76 t.close(); | 74 t.close(); |
77 Expect.fail("Multiple listens on same port"); | 75 Expect.fail("Multiple listens on same port"); |
78 }) | 76 }).catchError((error) { |
79 .catchError((error) { | |
80 Expect.isTrue(error is SocketException); | 77 Expect.isTrue(error is SocketException); |
81 s.close(); | 78 s.close(); |
82 print("asyncEnd testInvalidBind 3"); | 79 print("asyncEnd testInvalidBind 3"); |
83 asyncEnd(); | 80 asyncEnd(); |
84 }); | 81 }); |
85 }); | 82 }); |
86 } | 83 } |
87 | 84 |
88 void testSimpleConnect() { | 85 void testSimpleConnect() { |
89 print("asyncStart testSimpleConnect"); | 86 print("asyncStart testSimpleConnect"); |
90 asyncStart(); | 87 asyncStart(); |
91 RawSecureServerSocket.bind(HOST, 0, serverContext).then((server) { | 88 RawSecureServerSocket.bind(HOST, 0, serverContext).then((server) { |
92 var clientEndFuture = | 89 var clientEndFuture = |
93 RawSecureSocket.connect(HOST, server.port, context: clientContext); | 90 RawSecureSocket.connect(HOST, server.port, context: clientContext); |
94 server.listen((serverEnd) { | 91 server.listen((serverEnd) { |
95 clientEndFuture.then((clientEnd) { | 92 clientEndFuture.then((clientEnd) { |
96 // TODO(whesse): Shutdown(SEND) not supported on secure sockets. | 93 // TODO(whesse): Shutdown(SEND) not supported on secure sockets. |
97 clientEnd.shutdown(SocketDirection.SEND); | 94 clientEnd.shutdown(SocketDirection.SEND); |
98 serverEnd.shutdown(SocketDirection.SEND); | 95 serverEnd.shutdown(SocketDirection.SEND); |
99 server.close(); | 96 server.close(); |
100 print("asyncEnd testSimpleConnect"); | 97 print("asyncEnd testSimpleConnect"); |
101 asyncEnd(); | 98 asyncEnd(); |
102 }); | 99 }); |
103 }); | 100 }); |
104 }); | 101 }); |
105 } | 102 } |
106 | 103 |
107 int debugTestSimpleConnectFailCounter = 0; | 104 int debugTestSimpleConnectFailCounter = 0; |
108 void testSimpleConnectFail(SecurityContext context, bool cancelOnError) { | 105 void testSimpleConnectFail(SecurityContext context, bool cancelOnError) { |
109 var counter = debugTestSimpleConnectFailCounter++; | 106 var counter = debugTestSimpleConnectFailCounter++; |
110 print("asyncStart testSimpleConnectFail $counter"); | 107 print("asyncStart testSimpleConnectFail $counter"); |
111 asyncStart(); | 108 asyncStart(); |
112 RawSecureServerSocket.bind(HOST, 0, context).then((server) { | 109 RawSecureServerSocket.bind(HOST, 0, context).then((server) { |
113 var clientEndFuture = | 110 var clientEndFuture = RawSecureSocket |
114 RawSecureSocket.connect(HOST, server.port, context: clientContext) | 111 .connect(HOST, server.port, context: clientContext) |
115 .then((clientEnd) { | 112 .then((clientEnd) { |
116 Expect.fail("No client connection expected."); | 113 Expect.fail("No client connection expected."); |
117 }) | 114 }).catchError((error) { |
118 .catchError((error) { | 115 Expect.isTrue(error is SocketException || error is HandshakeException); |
119 Expect.isTrue(error is SocketException || | 116 }); |
120 error is HandshakeException); | |
121 }); | |
122 server.listen((serverEnd) { | 117 server.listen((serverEnd) { |
123 Expect.fail("No server connection expected."); | 118 Expect.fail("No server connection expected."); |
124 }, | 119 }, onError: (error) { |
125 onError: (error) { | 120 Expect.isTrue(error is SocketException || error is HandshakeException); |
126 Expect.isTrue(error is SocketException || | |
127 error is HandshakeException); | |
128 clientEndFuture.then((_) { | 121 clientEndFuture.then((_) { |
129 if (!cancelOnError) server.close(); | 122 if (!cancelOnError) server.close(); |
130 print("asyncEnd testSimpleConnectFail $counter"); | 123 print("asyncEnd testSimpleConnectFail $counter"); |
131 asyncEnd(); | 124 asyncEnd(); |
132 }); | 125 }); |
133 }, | 126 }, cancelOnError: cancelOnError); |
134 cancelOnError: cancelOnError); | |
135 }); | 127 }); |
136 } | 128 } |
137 | 129 |
138 void testServerListenAfterConnect() { | 130 void testServerListenAfterConnect() { |
139 print("asyncStart testServerListenAfterConnect"); | 131 print("asyncStart testServerListenAfterConnect"); |
140 asyncStart(); | 132 asyncStart(); |
141 RawSecureServerSocket.bind(HOST, 0, serverContext).then((server) { | 133 RawSecureServerSocket.bind(HOST, 0, serverContext).then((server) { |
142 Expect.isTrue(server.port > 0); | 134 Expect.isTrue(server.port > 0); |
143 var clientEndFuture = | 135 var clientEndFuture = |
144 RawSecureSocket.connect(HOST, server.port, context: clientContext); | 136 RawSecureSocket.connect(HOST, server.port, context: clientContext); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 // between client and server before the connection is secured. This argument | 171 // between client and server before the connection is secured. This argument |
180 // only makes sense when both listenSecure and connectSecure are false. | 172 // only makes sense when both listenSecure and connectSecure are false. |
181 // | 173 // |
182 // postponeSecure | 174 // postponeSecure |
183 // When this argument is false the securing of the server end will | 175 // When this argument is false the securing of the server end will |
184 // happen as soon as the last byte of the handshake before securing | 176 // happen as soon as the last byte of the handshake before securing |
185 // has been written. When this argument is true the securing of the | 177 // has been written. When this argument is true the securing of the |
186 // server will not happen until the first TLS handshake data has been | 178 // server will not happen until the first TLS handshake data has been |
187 // received from the client. This argument only takes effect when | 179 // received from the client. This argument only takes effect when |
188 // handshakeBeforeSecure is true. | 180 // handshakeBeforeSecure is true. |
189 void testSimpleReadWrite({bool listenSecure, | 181 void testSimpleReadWrite( |
190 bool connectSecure, | 182 {bool listenSecure, |
191 bool handshakeBeforeSecure, | 183 bool connectSecure, |
192 bool postponeSecure, | 184 bool handshakeBeforeSecure, |
193 bool dropReads}) { | 185 bool postponeSecure, |
| 186 bool dropReads}) { |
194 int clientReads = 0; | 187 int clientReads = 0; |
195 int serverReads = 0; | 188 int serverReads = 0; |
196 if (handshakeBeforeSecure == true && | 189 if (handshakeBeforeSecure == true && |
197 (listenSecure == true || connectSecure == true)) { | 190 (listenSecure == true || connectSecure == true)) { |
198 Expect.fail("Invalid arguments to testSimpleReadWrite"); | 191 Expect.fail("Invalid arguments to testSimpleReadWrite"); |
199 } | 192 } |
200 | 193 |
201 print("asyncStart testSimpleReadWrite($listenSecure, $connectSecure, " | 194 print("asyncStart testSimpleReadWrite($listenSecure, $connectSecure, " |
202 "$handshakeBeforeSecure, $postponeSecure, $dropReads"); | 195 "$handshakeBeforeSecure, $postponeSecure, $dropReads"); |
203 asyncStart(); | 196 asyncStart(); |
204 | 197 |
205 const messageSize = 1000; | 198 const messageSize = 1000; |
206 const handshakeMessageSize = 100; | 199 const handshakeMessageSize = 100; |
207 | 200 |
208 List<int> createTestData() { | 201 List<int> createTestData() { |
209 List<int> data = new List<int>(messageSize); | 202 List<int> data = new List<int>(messageSize); |
210 for (int i = 0; i < messageSize; i++) { | 203 for (int i = 0; i < messageSize; i++) { |
211 data[i] = i & 0xff; | 204 data[i] = i & 0xff; |
212 } | 205 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 client.writeEventsEnabled = true; | 264 client.writeEventsEnabled = true; |
272 } | 265 } |
273 break; | 266 break; |
274 case RawSocketEvent.WRITE: | 267 case RawSocketEvent.WRITE: |
275 Expect.isFalse(client.writeEventsEnabled); | 268 Expect.isFalse(client.writeEventsEnabled); |
276 Expect.equals(bytesRead, data.length); | 269 Expect.equals(bytesRead, data.length); |
277 for (int i = bytesWritten; i < data.length; ++i) { | 270 for (int i = bytesWritten; i < data.length; ++i) { |
278 Expect.isTrue(data[i] is int); | 271 Expect.isTrue(data[i] is int); |
279 Expect.isTrue(data[i] < 256 && data[i] >= 0); | 272 Expect.isTrue(data[i] < 256 && data[i] >= 0); |
280 } | 273 } |
281 bytesWritten += client.write( | 274 bytesWritten += |
282 data, bytesWritten, data.length - bytesWritten); | 275 client.write(data, bytesWritten, data.length - bytesWritten); |
283 if (bytesWritten < data.length) { | 276 if (bytesWritten < data.length) { |
284 client.writeEventsEnabled = true; | 277 client.writeEventsEnabled = true; |
285 } | 278 } |
286 if (bytesWritten == data.length) { | 279 if (bytesWritten == data.length) { |
287 client.shutdown(SocketDirection.SEND); | 280 client.shutdown(SocketDirection.SEND); |
288 } | 281 } |
289 break; | 282 break; |
290 case RawSocketEvent.READ_CLOSED: | 283 case RawSocketEvent.READ_CLOSED: |
291 completer.complete(null); | 284 completer.complete(null); |
292 break; | 285 break; |
293 default: throw "Unexpected event $event"; | 286 default: |
| 287 throw "Unexpected event $event"; |
294 } | 288 } |
295 }); | 289 }); |
296 return completer.future; | 290 return completer.future; |
297 } | 291 } |
298 | 292 |
299 Future<RawSocket> runClient(RawSocket socket) { | 293 Future<RawSocket> runClient(RawSocket socket) { |
300 var completer = new Completer(); | 294 var completer = new Completer(); |
301 int bytesRead = 0; | 295 int bytesRead = 0; |
302 int bytesWritten = 0; | 296 int bytesWritten = 0; |
303 List<int> dataSent = createTestData(); | 297 List<int> dataSent = createTestData(); |
(...skipping 22 matching lines...) Expand all Loading... |
326 bytesWritten += socket.write( | 320 bytesWritten += socket.write( |
327 dataSent, bytesWritten, dataSent.length - bytesWritten); | 321 dataSent, bytesWritten, dataSent.length - bytesWritten); |
328 if (bytesWritten < dataSent.length) { | 322 if (bytesWritten < dataSent.length) { |
329 socket.writeEventsEnabled = true; | 323 socket.writeEventsEnabled = true; |
330 } | 324 } |
331 break; | 325 break; |
332 case RawSocketEvent.READ_CLOSED: | 326 case RawSocketEvent.READ_CLOSED: |
333 verifyTestData(dataReceived); | 327 verifyTestData(dataReceived); |
334 completer.complete(socket); | 328 completer.complete(socket); |
335 break; | 329 break; |
336 default: throw "Unexpected event $event"; | 330 default: |
| 331 throw "Unexpected event $event"; |
337 } | 332 } |
338 }); | 333 }); |
339 return completer.future; | 334 return completer.future; |
340 } | 335 } |
341 | 336 |
342 Future runServerHandshake(RawSocket client) { | 337 Future runServerHandshake(RawSocket client) { |
343 var completer = new Completer(); | 338 var completer = new Completer(); |
344 int bytesRead = 0; | 339 int bytesRead = 0; |
345 int bytesWritten = 0; | 340 int bytesWritten = 0; |
346 List<int> data = new List<int>(handshakeMessageSize); | 341 List<int> data = new List<int>(handshakeMessageSize); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 client.writeEventsEnabled = true; | 377 client.writeEventsEnabled = true; |
383 } | 378 } |
384 break; | 379 break; |
385 case RawSocketEvent.WRITE: | 380 case RawSocketEvent.WRITE: |
386 Expect.isFalse(client.writeEventsEnabled); | 381 Expect.isFalse(client.writeEventsEnabled); |
387 Expect.equals(bytesRead, data.length); | 382 Expect.equals(bytesRead, data.length); |
388 for (int i = bytesWritten; i < data.length; ++i) { | 383 for (int i = bytesWritten; i < data.length; ++i) { |
389 Expect.isTrue(data[i] is int); | 384 Expect.isTrue(data[i] is int); |
390 Expect.isTrue(data[i] < 256 && data[i] >= 0); | 385 Expect.isTrue(data[i] < 256 && data[i] >= 0); |
391 } | 386 } |
392 bytesWritten += client.write( | 387 bytesWritten += |
393 data, bytesWritten, data.length - bytesWritten); | 388 client.write(data, bytesWritten, data.length - bytesWritten); |
394 if (bytesWritten < data.length) { | 389 if (bytesWritten < data.length) { |
395 client.writeEventsEnabled = true; | 390 client.writeEventsEnabled = true; |
396 } | 391 } |
397 if (bytesWritten == data.length) { | 392 if (bytesWritten == data.length) { |
398 if (!postponeSecure) { | 393 if (!postponeSecure) { |
399 completer.complete([subscription, null]); | 394 completer.complete([subscription, null]); |
400 } | 395 } |
401 } | 396 } |
402 break; | 397 break; |
403 case RawSocketEvent.READ_CLOSED: | 398 case RawSocketEvent.READ_CLOSED: |
404 Expect.fail("Unexpected close"); | 399 Expect.fail("Unexpected close"); |
405 break; | 400 break; |
406 default: throw "Unexpected event $event"; | 401 default: |
| 402 throw "Unexpected event $event"; |
407 } | 403 } |
408 }); | 404 }); |
409 return completer.future; | 405 return completer.future; |
410 } | 406 } |
411 | 407 |
412 Future<RawSocket> runClientHandshake(RawSocket socket) { | 408 Future<RawSocket> runClientHandshake(RawSocket socket) { |
413 var completer = new Completer(); | 409 var completer = new Completer(); |
414 int bytesRead = 0; | 410 int bytesRead = 0; |
415 int bytesWritten = 0; | 411 int bytesWritten = 0; |
416 List<int> dataSent = createHandshakeTestData(); | 412 List<int> dataSent = createHandshakeTestData(); |
(...skipping 26 matching lines...) Expand all Loading... |
443 Expect.isFalse(socket.writeEventsEnabled); | 439 Expect.isFalse(socket.writeEventsEnabled); |
444 bytesWritten += socket.write( | 440 bytesWritten += socket.write( |
445 dataSent, bytesWritten, dataSent.length - bytesWritten); | 441 dataSent, bytesWritten, dataSent.length - bytesWritten); |
446 if (bytesWritten < dataSent.length) { | 442 if (bytesWritten < dataSent.length) { |
447 socket.writeEventsEnabled = true; | 443 socket.writeEventsEnabled = true; |
448 } | 444 } |
449 break; | 445 break; |
450 case RawSocketEvent.READ_CLOSED: | 446 case RawSocketEvent.READ_CLOSED: |
451 Expect.fail("Unexpected close"); | 447 Expect.fail("Unexpected close"); |
452 break; | 448 break; |
453 default: throw "Unexpected event $event"; | 449 default: |
| 450 throw "Unexpected event $event"; |
454 } | 451 } |
455 }); | 452 }); |
456 return completer.future; | 453 return completer.future; |
457 } | 454 } |
458 | 455 |
459 Future<RawSecureSocket> connectClient(int port) { | 456 Future<RawSecureSocket> connectClient(int port) { |
460 if (connectSecure) { | 457 if (connectSecure) { |
461 return RawSecureSocket.connect(HOST, port, context: clientContext); | 458 return RawSecureSocket.connect(HOST, port, context: clientContext); |
462 } else if (!handshakeBeforeSecure) { | 459 } else if (!handshakeBeforeSecure) { |
463 return RawSocket.connect(HOST, port).then((socket) { | 460 return RawSocket.connect(HOST, port).then((socket) { |
464 return RawSecureSocket.secure(socket, context: clientContext); | 461 return RawSecureSocket.secure(socket, context: clientContext); |
465 }); | 462 }); |
466 } else { | 463 } else { |
467 return RawSocket.connect(HOST, port).then((socket) { | 464 return RawSocket.connect(HOST, port).then((socket) { |
468 return runClientHandshake(socket).then((subscription) { | 465 return runClientHandshake(socket).then((subscription) { |
469 return RawSecureSocket.secure(socket, | 466 return RawSecureSocket.secure(socket, |
470 context: clientContext, | 467 context: clientContext, subscription: subscription); |
471 subscription: subscription); | |
472 }); | 468 }); |
473 }); | 469 }); |
474 } | 470 } |
475 } | 471 } |
476 | 472 |
477 serverReady(server) { | 473 serverReady(server) { |
478 server.listen((client) { | 474 server.listen((client) { |
479 if (listenSecure) { | 475 if (listenSecure) { |
480 runServer(client).then((_) => server.close()); | 476 runServer(client).then((_) => server.close()); |
481 } else if (!handshakeBeforeSecure) { | 477 } else if (!handshakeBeforeSecure) { |
482 RawSecureSocket.secureServer(client, serverContext).then((client) { | 478 RawSecureSocket.secureServer(client, serverContext).then((client) { |
483 runServer(client).then((_) => server.close()); | 479 runServer(client).then((_) => server.close()); |
484 }); | 480 }); |
485 } else { | 481 } else { |
486 runServerHandshake(client).then((secure) { | 482 runServerHandshake(client).then((secure) { |
487 RawSecureSocket.secureServer( | 483 RawSecureSocket |
488 client, | 484 .secureServer(client, serverContext, |
489 serverContext, | 485 subscription: secure[0], bufferedData: secure[1]) |
490 subscription: secure[0], | 486 .then((client) { |
491 bufferedData: secure[1]).then((client) { | |
492 runServer(client).then((_) => server.close()); | 487 runServer(client).then((_) => server.close()); |
493 }); | 488 }); |
494 }); | 489 }); |
495 } | 490 } |
496 }); | 491 }); |
497 | 492 |
498 connectClient(server.port).then(runClient).then((socket) { | 493 connectClient(server.port).then(runClient).then((socket) { |
499 socket.close(); | 494 socket.close(); |
500 print("asyncEnd testSimpleReadWrite($listenSecure, $connectSecure, " | 495 print("asyncEnd testSimpleReadWrite($listenSecure, $connectSecure, " |
501 "$handshakeBeforeSecure, $postponeSecure, $dropReads"); | 496 "$handshakeBeforeSecure, $postponeSecure, $dropReads"); |
502 asyncEnd(); | 497 asyncEnd(); |
503 }); | 498 }); |
504 } | 499 } |
505 | 500 |
506 if (listenSecure) { | 501 if (listenSecure) { |
507 RawSecureServerSocket.bind( | 502 RawSecureServerSocket.bind(HOST, 0, serverContext).then(serverReady); |
508 HOST, 0, serverContext).then(serverReady); | |
509 } else { | 503 } else { |
510 RawServerSocket.bind(HOST, 0).then(serverReady); | 504 RawServerSocket.bind(HOST, 0).then(serverReady); |
511 } | 505 } |
512 } | 506 } |
513 | 507 |
514 testPausedSecuringSubscription(bool pausedServer, bool pausedClient) { | 508 testPausedSecuringSubscription(bool pausedServer, bool pausedClient) { |
515 print( | 509 print( |
516 "asyncStart testPausedSecuringSubscription $pausedServer $pausedClient"); | 510 "asyncStart testPausedSecuringSubscription $pausedServer $pausedClient"); |
517 asyncStart(); | 511 asyncStart(); |
518 var clientComplete = new Completer(); | 512 var clientComplete = new Completer(); |
519 RawServerSocket.bind(HOST, 0).then((server) { | 513 RawServerSocket.bind(HOST, 0).then((server) { |
520 server.listen((client) { | 514 server.listen((client) { |
521 var subscription; | 515 var subscription; |
522 subscription = client.listen((_) { | 516 subscription = client.listen((_) { |
523 if (pausedServer) { | 517 if (pausedServer) { |
524 subscription.pause(); | 518 subscription.pause(); |
525 } | 519 } |
526 void done() { | 520 void done() { |
527 server.close(); | 521 server.close(); |
528 clientComplete.future.then((_) { | 522 clientComplete.future.then((_) { |
529 client.close(); | 523 client.close(); |
530 print("asyncEnd testPausedSecuringSubscription " | 524 print("asyncEnd testPausedSecuringSubscription " |
531 "$pausedServer $pausedClient"); | 525 "$pausedServer $pausedClient"); |
532 asyncEnd(); | 526 asyncEnd(); |
533 }); | 527 }); |
534 } | 528 } |
| 529 |
535 try { | 530 try { |
536 RawSecureSocket.secureServer( | 531 RawSecureSocket |
537 client, serverContext, subscription: subscription) | 532 .secureServer(client, serverContext, subscription: subscription) |
538 .catchError((_) {}) | 533 .catchError((_) {}) |
539 .whenComplete(() { | 534 .whenComplete(() { |
540 if (pausedServer) { | 535 if (pausedServer) { |
541 Expect.fail("secureServer succeeded with paused subscription"); | 536 Expect.fail("secureServer succeeded with paused subscription"); |
542 } | 537 } |
543 done(); | 538 done(); |
544 }); | 539 }); |
545 } catch (e) { | 540 } catch (e) { |
546 if (!pausedServer) { | 541 if (!pausedServer) { |
547 Expect.fail("secureServer failed with non-paused subscriptions"); | 542 Expect.fail("secureServer failed with non-paused subscriptions"); |
548 } | 543 } |
549 if (pausedServer) { | 544 if (pausedServer) { |
550 Expect.isTrue(e is ArgumentError); | 545 Expect.isTrue(e is ArgumentError); |
551 } | 546 } |
552 done(); | 547 done(); |
553 } | 548 } |
554 }); | 549 }); |
555 }); | 550 }); |
556 | 551 |
557 RawSocket.connect(HOST, server.port).then((socket) { | 552 RawSocket.connect(HOST, server.port).then((socket) { |
558 var subscription; | 553 var subscription; |
559 subscription = socket.listen((_) { | 554 subscription = socket.listen((_) { |
560 if (pausedClient) { | 555 if (pausedClient) { |
561 subscription.pause(); | 556 subscription.pause(); |
562 } | 557 } |
563 try { | 558 try { |
564 RawSecureSocket.secure( | 559 RawSecureSocket |
565 socket, subscription: subscription) | 560 .secure(socket, subscription: subscription) |
566 .catchError((_) {}) | 561 .catchError((_) {}) |
567 .whenComplete(() { | 562 .whenComplete(() { |
568 if (pausedClient) { | 563 if (pausedClient) { |
569 Expect.fail("secure succeeded with paused subscription"); | 564 Expect.fail("secure succeeded with paused subscription"); |
570 } | 565 } |
571 socket.close(); | 566 socket.close(); |
572 clientComplete.complete(null); | 567 clientComplete.complete(null); |
573 }); | 568 }); |
574 } catch (e) { | 569 } catch (e) { |
575 if (!pausedClient) { | 570 if (!pausedClient) { |
576 Expect.fail("secure failed with non-paused subscriptions ($e)"); | 571 Expect.fail("secure failed with non-paused subscriptions ($e)"); |
577 } | 572 } |
578 if (pausedClient) { | 573 if (pausedClient) { |
579 Expect.isTrue(e is ArgumentError); | 574 Expect.isTrue(e is ArgumentError); |
580 } | 575 } |
581 clientComplete.complete(null); | 576 clientComplete.complete(null); |
582 } | 577 } |
583 }); | 578 }); |
(...skipping 12 matching lines...) Expand all Loading... |
596 }); | 591 }); |
597 } | 592 } |
598 | 593 |
599 runTests() { | 594 runTests() { |
600 testSimpleBind(); | 595 testSimpleBind(); |
601 testInvalidBind(); | 596 testInvalidBind(); |
602 testSimpleConnect(); | 597 testSimpleConnect(); |
603 SecurityContext context = new SecurityContext(); | 598 SecurityContext context = new SecurityContext(); |
604 testSimpleConnectFail(context, false); | 599 testSimpleConnectFail(context, false); |
605 testSimpleConnectFail(context, true); | 600 testSimpleConnectFail(context, true); |
606 var chain = | 601 var chain = Platform.script |
607 Platform.script.resolve('certificates/untrusted_server_chain.pem') | 602 .resolve('certificates/untrusted_server_chain.pem') |
608 .toFilePath(); | 603 .toFilePath(); |
609 context.useCertificateChain(chain); | 604 context.useCertificateChain(chain); |
610 testSimpleConnectFail(context, false); | 605 testSimpleConnectFail(context, false); |
611 testSimpleConnectFail(context, true); | 606 testSimpleConnectFail(context, true); |
612 var key = | 607 var key = Platform.script |
613 Platform.script.resolve('certificates/untrusted_server_key.pem') | 608 .resolve('certificates/untrusted_server_key.pem') |
614 .toFilePath(); | 609 .toFilePath(); |
615 context.usePrivateKey(key, password: 'dartdart'); | 610 context.usePrivateKey(key, password: 'dartdart'); |
616 testSimpleConnectFail(context, false); | 611 testSimpleConnectFail(context, false); |
617 testSimpleConnectFail(context, true); | 612 testSimpleConnectFail(context, true); |
618 testServerListenAfterConnect(); | 613 testServerListenAfterConnect(); |
619 | 614 |
620 testSimpleReadWrite(listenSecure: true, | 615 testSimpleReadWrite( |
621 connectSecure: true, | 616 listenSecure: true, |
622 handshakeBeforeSecure: false, | 617 connectSecure: true, |
623 postponeSecure: false, | 618 handshakeBeforeSecure: false, |
624 dropReads: false); | 619 postponeSecure: false, |
625 testSimpleReadWrite(listenSecure: true, | 620 dropReads: false); |
626 connectSecure: false, | 621 testSimpleReadWrite( |
627 handshakeBeforeSecure: false, | 622 listenSecure: true, |
628 postponeSecure: false, | 623 connectSecure: false, |
629 dropReads: false); | 624 handshakeBeforeSecure: false, |
| 625 postponeSecure: false, |
| 626 dropReads: false); |
630 | 627 |
631 testSimpleReadWrite(listenSecure: false, | 628 testSimpleReadWrite( |
632 connectSecure: true, | 629 listenSecure: false, |
633 handshakeBeforeSecure: false, | 630 connectSecure: true, |
634 postponeSecure: false, | 631 handshakeBeforeSecure: false, |
635 dropReads: false); | 632 postponeSecure: false, |
| 633 dropReads: false); |
636 | 634 |
637 testSimpleReadWrite(listenSecure: false, | 635 testSimpleReadWrite( |
638 connectSecure: false, | 636 listenSecure: false, |
639 handshakeBeforeSecure: false, | 637 connectSecure: false, |
640 postponeSecure: false, | 638 handshakeBeforeSecure: false, |
641 dropReads: false); | 639 postponeSecure: false, |
642 testSimpleReadWrite(listenSecure: false, | 640 dropReads: false); |
643 connectSecure: false, | 641 testSimpleReadWrite( |
644 handshakeBeforeSecure: true, | 642 listenSecure: false, |
645 postponeSecure: true, | 643 connectSecure: false, |
646 dropReads: false); | 644 handshakeBeforeSecure: true, |
647 testSimpleReadWrite(listenSecure: false, | 645 postponeSecure: true, |
648 connectSecure: false, | 646 dropReads: false); |
649 handshakeBeforeSecure: true, | 647 testSimpleReadWrite( |
650 postponeSecure: false, | 648 listenSecure: false, |
651 dropReads: false); | 649 connectSecure: false, |
652 testSimpleReadWrite(listenSecure: true, | 650 handshakeBeforeSecure: true, |
653 connectSecure: true, | 651 postponeSecure: false, |
654 handshakeBeforeSecure: false, | 652 dropReads: false); |
655 postponeSecure: false, | 653 testSimpleReadWrite( |
656 dropReads: true); | 654 listenSecure: true, |
657 testSimpleReadWrite(listenSecure: false, | 655 connectSecure: true, |
658 connectSecure: false, | 656 handshakeBeforeSecure: false, |
659 handshakeBeforeSecure: true, | 657 postponeSecure: false, |
660 postponeSecure: true, | 658 dropReads: true); |
661 dropReads: true); | 659 testSimpleReadWrite( |
| 660 listenSecure: false, |
| 661 connectSecure: false, |
| 662 handshakeBeforeSecure: true, |
| 663 postponeSecure: true, |
| 664 dropReads: true); |
662 testPausedSecuringSubscription(false, false); | 665 testPausedSecuringSubscription(false, false); |
663 testPausedSecuringSubscription(true, false); | 666 testPausedSecuringSubscription(true, false); |
664 testPausedSecuringSubscription(false, true); | 667 testPausedSecuringSubscription(false, true); |
665 testPausedSecuringSubscription(true, true); | 668 testPausedSecuringSubscription(true, true); |
666 } | 669 } |
OLD | NEW |