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 | 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 String localFile(path) => Platform.script.resolve(path).toFilePath(); | 17 String localFile(path) => Platform.script.resolve(path).toFilePath(); |
18 List<int> readLocalFile(path) => (new File(localFile(path))).readAsBytesSync(); | |
19 | 18 |
20 SecurityContext serverContext = new SecurityContext() | 19 SecurityContext serverContext = new SecurityContext() |
21 ..useCertificateChainBytes(readLocalFile('certificates/server_chain.pem')) | 20 ..useCertificateChainSync(localFile('certificates/server_chain.pem')) |
22 ..usePrivateKeyBytes(readLocalFile('certificates/server_key.pem'), | 21 ..usePrivateKeySync(localFile('certificates/server_key.pem'), |
23 password: 'dartdart'); | 22 password: 'dartdart'); |
24 | 23 |
25 SecurityContext clientContext = new SecurityContext() | 24 SecurityContext clientContext = new SecurityContext() |
26 ..setTrustedCertificates(file: localFile('certificates/trusted_certs.pem')); | 25 ..setTrustedCertificatesSync(localFile('certificates/trusted_certs.pem')); |
27 | 26 |
28 void testSimpleBind() { | 27 void testSimpleBind() { |
29 asyncStart(); | 28 asyncStart(); |
30 RawSecureServerSocket.bind(HOST, 0, serverContext).then((s) { | 29 RawSecureServerSocket.bind(HOST, 0, serverContext).then((s) { |
31 Expect.isTrue(s.port > 0); | 30 Expect.isTrue(s.port > 0); |
32 s.close(); | 31 s.close(); |
33 asyncEnd(); | 32 asyncEnd(); |
34 }); | 33 }); |
35 } | 34 } |
36 | 35 |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 runTests() { | 567 runTests() { |
569 testSimpleBind(); | 568 testSimpleBind(); |
570 testInvalidBind(); | 569 testInvalidBind(); |
571 testSimpleConnect(); | 570 testSimpleConnect(); |
572 SecurityContext context = new SecurityContext(); | 571 SecurityContext context = new SecurityContext(); |
573 testSimpleConnectFail(context, false); | 572 testSimpleConnectFail(context, false); |
574 testSimpleConnectFail(context, true); | 573 testSimpleConnectFail(context, true); |
575 var chain = | 574 var chain = |
576 Platform.script.resolve('certificates/untrusted_server_chain.pem') | 575 Platform.script.resolve('certificates/untrusted_server_chain.pem') |
577 .toFilePath(); | 576 .toFilePath(); |
578 context.useCertificateChain(chain); | 577 context.useCertificateChainSync(chain); |
579 testSimpleConnectFail(context, false); | 578 testSimpleConnectFail(context, false); |
580 testSimpleConnectFail(context, true); | 579 testSimpleConnectFail(context, true); |
581 var key = | 580 var key = |
582 Platform.script.resolve('certificates/untrusted_server_key.pem') | 581 Platform.script.resolve('certificates/untrusted_server_key.pem') |
583 .toFilePath(); | 582 .toFilePath(); |
584 context.usePrivateKey(key, password: 'dartdart'); | 583 context.usePrivateKeySync(key, password: 'dartdart'); |
585 testSimpleConnectFail(context, false); | 584 testSimpleConnectFail(context, false); |
586 testSimpleConnectFail(context, true); | 585 testSimpleConnectFail(context, true); |
587 testServerListenAfterConnect(); | 586 testServerListenAfterConnect(); |
588 | 587 |
589 testSimpleReadWrite(listenSecure: true, | 588 testSimpleReadWrite(listenSecure: true, |
590 connectSecure: true, | 589 connectSecure: true, |
591 handshakeBeforeSecure: false, | 590 handshakeBeforeSecure: false, |
592 postponeSecure: false, | 591 postponeSecure: false, |
593 dropReads: false); | 592 dropReads: false); |
594 testSimpleReadWrite(listenSecure: true, | 593 testSimpleReadWrite(listenSecure: true, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 testSimpleReadWrite(listenSecure: false, | 625 testSimpleReadWrite(listenSecure: false, |
627 connectSecure: false, | 626 connectSecure: false, |
628 handshakeBeforeSecure: true, | 627 handshakeBeforeSecure: true, |
629 postponeSecure: true, | 628 postponeSecure: true, |
630 dropReads: true); | 629 dropReads: true); |
631 testPausedSecuringSubscription(false, false); | 630 testPausedSecuringSubscription(false, false); |
632 testPausedSecuringSubscription(true, false); | 631 testPausedSecuringSubscription(true, false); |
633 testPausedSecuringSubscription(false, true); | 632 testPausedSecuringSubscription(false, true); |
634 testPausedSecuringSubscription(true, true); | 633 testPausedSecuringSubscription(true, true); |
635 } | 634 } |
OLD | NEW |