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

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

Issue 14036017: Revert "Add new InternetAddress class with a static lookup function (including IPv6 results)." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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 "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 import "dart:async"; 6 import "dart:async";
7 import "dart:io"; 7 import "dart:io";
8 import "dart:isolate"; 8 import "dart:isolate";
9 9
10 const SERVER_ADDRESS = "127.0.0.1";
10 const HOST_NAME = "localhost"; 11 const HOST_NAME = "localhost";
11 const CERTIFICATE = "localhost_cert"; 12 const CERTIFICATE = "localhost_cert";
12 13
13 void testClientCertificate() { 14 void testClientCertificate() {
14 ReceivePort port = new ReceivePort(); 15 ReceivePort port = new ReceivePort();
15 SecureServerSocket.bind(HOST_NAME, 16 SecureServerSocket.bind(SERVER_ADDRESS,
16 0, 17 0,
17 5, 18 5,
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 port.close();
37 }); 38 });
38 }); 39 });
39 }); 40 });
40 } 41 }
41 42
42 void testRequiredClientCertificate() { 43 void testRequiredClientCertificate() {
43 ReceivePort port = new ReceivePort(); 44 ReceivePort port = new ReceivePort();
44 SecureServerSocket.bind(HOST_NAME, 45 SecureServerSocket.bind(SERVER_ADDRESS,
45 0, 46 0,
46 5, 47 5,
47 CERTIFICATE, 48 CERTIFICATE,
48 requireClientCertificate: true).then((server) { 49 requireClientCertificate: true).then((server) {
49 var clientEndFuture = SecureSocket.connect(HOST_NAME, 50 var clientEndFuture = SecureSocket.connect(HOST_NAME,
50 server.port, 51 server.port,
51 sendClientCertificate: true); 52 sendClientCertificate: true);
52 server.listen((serverEnd) { 53 server.listen((serverEnd) {
53 X509Certificate certificate = serverEnd.peerCertificate; 54 X509Certificate certificate = serverEnd.peerCertificate;
54 Expect.isNotNull(certificate); 55 Expect.isNotNull(certificate);
55 Expect.equals("CN=localhost", certificate.subject); 56 Expect.equals("CN=localhost", certificate.subject);
56 Expect.equals("CN=myauthority", certificate.issuer); 57 Expect.equals("CN=myauthority", certificate.issuer);
57 clientEndFuture.then((clientEnd) { 58 clientEndFuture.then((clientEnd) {
58 X509Certificate certificate = clientEnd.peerCertificate; 59 X509Certificate certificate = clientEnd.peerCertificate;
59 Expect.isNotNull(certificate); 60 Expect.isNotNull(certificate);
60 Expect.equals("CN=localhost", certificate.subject); 61 Expect.equals("CN=localhost", certificate.subject);
61 Expect.equals("CN=myauthority", certificate.issuer); 62 Expect.equals("CN=myauthority", certificate.issuer);
62 clientEnd.close(); 63 clientEnd.close();
63 serverEnd.close(); 64 serverEnd.close();
64 server.close(); 65 server.close();
65 port.close(); 66 port.close();
66 }); 67 });
67 }); 68 });
68 }); 69 });
69 } 70 }
70 71
71 void testNoClientCertificate() { 72 void testNoClientCertificate() {
72 ReceivePort port = new ReceivePort(); 73 ReceivePort port = new ReceivePort();
73 SecureServerSocket.bind(HOST_NAME, 74 SecureServerSocket.bind(SERVER_ADDRESS,
74 0, 75 0,
75 5, 76 5,
76 CERTIFICATE, 77 CERTIFICATE,
77 requestClientCertificate: true).then((server) { 78 requestClientCertificate: true).then((server) {
78 var clientEndFuture = SecureSocket.connect(HOST_NAME, 79 var clientEndFuture = SecureSocket.connect(HOST_NAME,
79 server.port); 80 server.port);
80 server.listen((serverEnd) { 81 server.listen((serverEnd) {
81 X509Certificate certificate = serverEnd.peerCertificate; 82 X509Certificate certificate = serverEnd.peerCertificate;
82 Expect.isNull(certificate); 83 Expect.isNull(certificate);
83 clientEndFuture.then((clientEnd) { 84 clientEndFuture.then((clientEnd) {
84 clientEnd.close(); 85 clientEnd.close();
85 serverEnd.close(); 86 serverEnd.close();
86 server.close(); 87 server.close();
87 port.close(); 88 port.close();
88 }); 89 });
89 }); 90 });
90 }); 91 });
91 } 92 }
92 93
93 void testNoRequiredClientCertificate() { 94 void testNoRequiredClientCertificate() {
94 ReceivePort port = new ReceivePort(); 95 ReceivePort port = new ReceivePort();
95 bool clientError = false; 96 bool clientError = false;
96 SecureServerSocket.bind(HOST_NAME, 97 SecureServerSocket.bind(SERVER_ADDRESS,
97 0, 98 0,
98 5, 99 5,
99 CERTIFICATE, 100 CERTIFICATE,
100 requireClientCertificate: true).then((server) { 101 requireClientCertificate: true).then((server) {
101 Future clientDone = SecureSocket.connect(HOST_NAME, server.port) 102 Future clientDone = SecureSocket.connect(HOST_NAME, server.port)
102 .catchError((e) { clientError = true; }); 103 .catchError((e) { clientError = true; });
103 server.listen((serverEnd) { 104 server.listen((serverEnd) {
104 Expect.fail("Got a unverifiable connection"); 105 Expect.fail("Got a unverifiable connection");
105 }, 106 },
106 onError: (e) { 107 onError: (e) {
(...skipping 11 matching lines...) Expand all
118 Path certificateDatabase = scriptDir.append('pkcert'); 119 Path certificateDatabase = scriptDir.append('pkcert');
119 SecureSocket.initialize(database: certificateDatabase.toNativePath(), 120 SecureSocket.initialize(database: certificateDatabase.toNativePath(),
120 password: 'dartdart', 121 password: 'dartdart',
121 useBuiltinRoots: false); 122 useBuiltinRoots: false);
122 123
123 testClientCertificate(); 124 testClientCertificate();
124 testRequiredClientCertificate(); 125 testRequiredClientCertificate();
125 testNoClientCertificate(); 126 testNoClientCertificate();
126 testNoRequiredClientCertificate(); 127 testNoRequiredClientCertificate();
127 } 128 }
OLDNEW
« no previous file with comments | « tests/standalone/io/secure_multiple_client_server_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