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

Side by Side Diff: tests/standalone/io/raw_secure_server_socket_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 // 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 "package:expect/expect.dart"; 10 import "package:expect/expect.dart";
11 import "dart:async"; 11 import "dart:async";
12 import "dart:io"; 12 import "dart:io";
13 import "dart:isolate"; 13 import "dart:isolate";
14 14
15 const SERVER_ADDRESS = "127.0.0.1";
15 const HOST_NAME = "localhost"; 16 const HOST_NAME = "localhost";
16 const CERTIFICATE = "localhost_cert"; 17 const CERTIFICATE = "localhost_cert";
17 18
18 void testSimpleBind() { 19 void testSimpleBind() {
19 ReceivePort port = new ReceivePort(); 20 ReceivePort port = new ReceivePort();
20 RawSecureServerSocket.bind(HOST_NAME, 0, 5, CERTIFICATE).then((s) { 21 RawSecureServerSocket.bind(SERVER_ADDRESS, 0, 5, CERTIFICATE).then((s) {
21 Expect.isTrue(s.port > 0); 22 Expect.isTrue(s.port > 0);
22 s.close(); 23 s.close();
23 port.close(); 24 port.close();
24 }); 25 });
25 } 26 }
26 27
27 void testInvalidBind() { 28 void testInvalidBind() {
28 int count = 0; 29 int count = 0;
29 ReceivePort port = new ReceivePort(); 30 ReceivePort port = new ReceivePort();
30 port.receive((_, __) { count++; if (count == 3) port.close(); }); 31 port.receive((_, __) { count++; if (count == 3) port.close(); });
(...skipping 11 matching lines...) Expand all
42 Expect.fail("Failure expected"); 43 Expect.fail("Failure expected");
43 }).catchError((error) { 44 }).catchError((error) {
44 Expect.isTrue(error is SocketIOException); 45 Expect.isTrue(error is SocketIOException);
45 port.toSendPort().send(1); 46 port.toSendPort().send(1);
46 }); 47 });
47 48
48 // Bind to a port already in use. 49 // Bind to a port already in use.
49 // Either an error or a successful bind is allowed. 50 // Either an error or a successful bind is allowed.
50 // Windows platforms allow multiple binding to the same socket, with 51 // Windows platforms allow multiple binding to the same socket, with
51 // unpredictable results. 52 // unpredictable results.
52 RawSecureServerSocket.bind(HOST_NAME, 0, 5, CERTIFICATE).then((s) { 53 RawSecureServerSocket.bind(SERVER_ADDRESS, 0, 5, CERTIFICATE).then((s) {
53 RawSecureServerSocket.bind(HOST_NAME, 54 RawSecureServerSocket.bind(SERVER_ADDRESS,
54 s.port, 55 s.port,
55 5, 56 5,
56 CERTIFICATE).then((t) { 57 CERTIFICATE).then((t) {
57 Expect.equals('windows', Platform.operatingSystem); 58 Expect.equals('windows', Platform.operatingSystem);
58 Expect.equals(s.port, t.port); 59 Expect.equals(s.port, t.port);
59 s.close(); 60 s.close();
60 t.close(); 61 t.close();
61 port.toSendPort().send(1); 62 port.toSendPort().send(1);
62 }) 63 })
63 .catchError((error) { 64 .catchError((error) {
64 Expect.notEquals('windows', Platform.operatingSystem); 65 Expect.notEquals('windows', Platform.operatingSystem);
65 Expect.isTrue(error is SocketIOException); 66 Expect.isTrue(error is SocketIOException);
66 s.close(); 67 s.close();
67 port.toSendPort().send(1); 68 port.toSendPort().send(1);
68 }); 69 });
69 }); 70 });
70 } 71 }
71 72
72 void testSimpleConnect(String certificate) { 73 void testSimpleConnect(String certificate) {
73 ReceivePort port = new ReceivePort(); 74 ReceivePort port = new ReceivePort();
74 RawSecureServerSocket.bind(HOST_NAME, 0, 5, certificate).then((server) { 75 RawSecureServerSocket.bind(SERVER_ADDRESS, 0, 5, certificate).then((server) {
75 var clientEndFuture = RawSecureSocket.connect(HOST_NAME, server.port); 76 var clientEndFuture = RawSecureSocket.connect(HOST_NAME, server.port);
76 server.listen((serverEnd) { 77 server.listen((serverEnd) {
77 clientEndFuture.then((clientEnd) { 78 clientEndFuture.then((clientEnd) {
78 clientEnd.shutdown(SocketDirection.SEND); 79 clientEnd.shutdown(SocketDirection.SEND);
79 serverEnd.shutdown(SocketDirection.SEND); 80 serverEnd.shutdown(SocketDirection.SEND);
80 server.close(); 81 server.close();
81 port.close(); 82 port.close();
82 }); 83 });
83 }); 84 });
84 }); 85 });
85 } 86 }
86 87
87 void testSimpleConnectFail(String certificate) { 88 void testSimpleConnectFail(String certificate) {
88 ReceivePort port = new ReceivePort(); 89 ReceivePort port = new ReceivePort();
89 RawSecureServerSocket.bind(HOST_NAME, 0, 5, certificate).then((server) { 90 RawSecureServerSocket.bind(SERVER_ADDRESS, 0, 5, certificate).then((server) {
90 var clientEndFuture = RawSecureSocket.connect(HOST_NAME, server.port) 91 var clientEndFuture = RawSecureSocket.connect(HOST_NAME, server.port)
91 .then((clientEnd) { 92 .then((clientEnd) {
92 Expect.fail("No client connection expected."); 93 Expect.fail("No client connection expected.");
93 }) 94 })
94 .catchError((error) { 95 .catchError((error) {
95 Expect.isTrue(error is SocketIOException); 96 Expect.isTrue(error is SocketIOException);
96 }); 97 });
97 server.listen((serverEnd) { 98 server.listen((serverEnd) {
98 Expect.fail("No server connection expected."); 99 Expect.fail("No server connection expected.");
99 }, 100 },
100 onError: (error) { 101 onError: (error) {
101 Expect.isTrue(error is SocketIOException); 102 Expect.isTrue(error is SocketIOException);
102 clientEndFuture.then((_) => port.close()); 103 clientEndFuture.then((_) => port.close());
103 }); 104 });
104 }); 105 });
105 } 106 }
106 107
107 void testServerListenAfterConnect() { 108 void testServerListenAfterConnect() {
108 ReceivePort port = new ReceivePort(); 109 ReceivePort port = new ReceivePort();
109 RawSecureServerSocket.bind(HOST_NAME, 0, 5, CERTIFICATE).then((server) { 110 RawSecureServerSocket.bind(SERVER_ADDRESS, 0, 5, CERTIFICATE).then((server) {
110 Expect.isTrue(server.port > 0); 111 Expect.isTrue(server.port > 0);
111 var clientEndFuture = RawSecureSocket.connect(HOST_NAME, server.port); 112 var clientEndFuture = RawSecureSocket.connect(HOST_NAME, server.port);
112 new Timer(const Duration(milliseconds: 500), () { 113 new Timer(const Duration(milliseconds: 500), () {
113 server.listen((serverEnd) { 114 server.listen((serverEnd) {
114 clientEndFuture.then((clientEnd) { 115 clientEndFuture.then((clientEnd) {
115 clientEnd.shutdown(SocketDirection.SEND); 116 clientEnd.shutdown(SocketDirection.SEND);
116 serverEnd.shutdown(SocketDirection.SEND); 117 serverEnd.shutdown(SocketDirection.SEND);
117 server.close(); 118 server.close();
118 port.close(); 119 port.close();
119 }); 120 });
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 }); 425 });
425 426
426 connectClient(server.port).then(runClient).then((socket) { 427 connectClient(server.port).then(runClient).then((socket) {
427 socket.close(); 428 socket.close();
428 port.close(); 429 port.close();
429 }); 430 });
430 } 431 }
431 432
432 if (listenSecure) { 433 if (listenSecure) {
433 RawSecureServerSocket.bind( 434 RawSecureServerSocket.bind(
434 HOST_NAME, 0, 5, CERTIFICATE).then(serverReady); 435 SERVER_ADDRESS, 0, 5, CERTIFICATE).then(serverReady);
435 } else { 436 } else {
436 RawServerSocket.bind(HOST_NAME, 0, 5).then(serverReady); 437 RawServerSocket.bind(SERVER_ADDRESS, 0, 5).then(serverReady);
437 } 438 }
438 } 439 }
439 440
440 main() { 441 main() {
441 Path scriptDir = new Path(new Options().script).directoryPath; 442 Path scriptDir = new Path(new Options().script).directoryPath;
442 Path certificateDatabase = scriptDir.append('pkcert'); 443 Path certificateDatabase = scriptDir.append('pkcert');
443 SecureSocket.initialize(database: certificateDatabase.toNativePath(), 444 SecureSocket.initialize(database: certificateDatabase.toNativePath(),
444 password: 'dartdart', 445 password: 'dartdart',
445 useBuiltinRoots: false); 446 useBuiltinRoots: false);
446 testSimpleBind(); 447 testSimpleBind();
447 testInvalidBind(); 448 testInvalidBind();
448 testSimpleConnect(CERTIFICATE); 449 testSimpleConnect(CERTIFICATE);
449 testSimpleConnect("CN=localhost"); 450 testSimpleConnect("CN=localhost");
450 testSimpleConnectFail("not_a_nickname"); 451 testSimpleConnectFail("not_a_nickname");
451 testSimpleConnectFail("CN=notARealDistinguishedName"); 452 testSimpleConnectFail("CN=notARealDistinguishedName");
452 testServerListenAfterConnect(); 453 testServerListenAfterConnect();
453 testSimpleReadWrite(true, true, false); 454 testSimpleReadWrite(true, true, false);
454 testSimpleReadWrite(true, false, false); 455 testSimpleReadWrite(true, false, false);
455 testSimpleReadWrite(false, true, false); 456 testSimpleReadWrite(false, true, false);
456 testSimpleReadWrite(false, false, false); 457 testSimpleReadWrite(false, false, false);
457 testSimpleReadWrite(false, false, true, true); 458 testSimpleReadWrite(false, false, true, true);
458 testSimpleReadWrite(false, false, true, false); 459 testSimpleReadWrite(false, false, true, false);
459 } 460 }
OLDNEW
« no previous file with comments | « tests/standalone/io/raw_secure_server_closing_test.dart ('k') | tests/standalone/io/raw_secure_socket_pause_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698