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 "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
(...skipping 24 matching lines...) Expand all Loading... |
35 } | 35 } |
36 | 36 |
37 void testInvalidBind() { | 37 void testInvalidBind() { |
38 int count = 0; | 38 int count = 0; |
39 ReceivePort port = new ReceivePort(); | 39 ReceivePort port = new ReceivePort(); |
40 port.receive((_, __) { count++; if (count == 3) port.close(); }); | 40 port.receive((_, __) { count++; if (count == 3) port.close(); }); |
41 | 41 |
42 // Bind to a unknown DNS name. | 42 // Bind to a unknown DNS name. |
43 SecureServerSocket.bind("ko.faar.__hest__", 0, 5, CERTIFICATE).then((_) { | 43 SecureServerSocket.bind("ko.faar.__hest__", 0, 5, CERTIFICATE).then((_) { |
44 Expect.fail("Failure expected"); | 44 Expect.fail("Failure expected"); |
45 }).catchError((e) { | 45 }).catchError((error) { |
46 Expect.isTrue(e.error is SocketIOException); | 46 Expect.isTrue(error is SocketIOException); |
47 port.toSendPort().send(1); | 47 port.toSendPort().send(1); |
48 }); | 48 }); |
49 | 49 |
50 // Bind to an unavaliable IP-address. | 50 // Bind to an unavaliable IP-address. |
51 SecureServerSocket.bind("8.8.8.8", 0, 5, CERTIFICATE).then((_) { | 51 SecureServerSocket.bind("8.8.8.8", 0, 5, CERTIFICATE).then((_) { |
52 Expect.fail("Failure expected"); | 52 Expect.fail("Failure expected"); |
53 }).catchError((e) { | 53 }).catchError((error) { |
54 Expect.isTrue(e.error is SocketIOException); | 54 Expect.isTrue(error is SocketIOException); |
55 port.toSendPort().send(1); | 55 port.toSendPort().send(1); |
56 }); | 56 }); |
57 | 57 |
58 // Bind to a port already in use. | 58 // Bind to a port already in use. |
59 // Either an error or a successful bind is allowed. | 59 // Either an error or a successful bind is allowed. |
60 // Windows platforms allow multiple binding to the same socket, with | 60 // Windows platforms allow multiple binding to the same socket, with |
61 // unpredictable results. | 61 // unpredictable results. |
62 SecureServerSocket.bind(SERVER_ADDRESS, 0, 5, CERTIFICATE).then((s) { | 62 SecureServerSocket.bind(SERVER_ADDRESS, 0, 5, CERTIFICATE).then((s) { |
63 SecureServerSocket.bind(SERVER_ADDRESS, | 63 SecureServerSocket.bind(SERVER_ADDRESS, |
64 s.port, | 64 s.port, |
65 5, | 65 5, |
66 CERTIFICATE).then((t) { | 66 CERTIFICATE).then((t) { |
67 Expect.equals('windows', Platform.operatingSystem); | 67 Expect.equals('windows', Platform.operatingSystem); |
68 Expect.equals(s.port, t.port); | 68 Expect.equals(s.port, t.port); |
69 s.close(); | 69 s.close(); |
70 t.close(); | 70 t.close(); |
71 port.toSendPort().send(1); | 71 port.toSendPort().send(1); |
72 }).catchError((e) { | 72 }).catchError((error) { |
73 Expect.notEquals('windows', Platform.operatingSystem); | 73 Expect.notEquals('windows', Platform.operatingSystem); |
74 Expect.isTrue(e.error is SocketIOException); | 74 Expect.isTrue(error is SocketIOException); |
75 s.close(); | 75 s.close(); |
76 port.toSendPort().send(1); | 76 port.toSendPort().send(1); |
77 }); | 77 }); |
78 }); | 78 }); |
79 } | 79 } |
80 | 80 |
81 void testSimpleConnect(String certificate) { | 81 void testSimpleConnect(String certificate) { |
82 ReceivePort port = new ReceivePort(); | 82 ReceivePort port = new ReceivePort(); |
83 SecureServerSocket.bind(SERVER_ADDRESS, 0, 5, certificate).then((server) { | 83 SecureServerSocket.bind(SERVER_ADDRESS, 0, 5, certificate).then((server) { |
84 var clientEndFuture = SecureSocket.connect(HOST_NAME, server.port); | 84 var clientEndFuture = SecureSocket.connect(HOST_NAME, server.port); |
85 server.listen((serverEnd) { | 85 server.listen((serverEnd) { |
86 clientEndFuture.then((clientEnd) { | 86 clientEndFuture.then((clientEnd) { |
87 clientEnd.close(); | 87 clientEnd.close(); |
88 serverEnd.close(); | 88 serverEnd.close(); |
89 server.close(); | 89 server.close(); |
90 port.close(); | 90 port.close(); |
91 }); | 91 }); |
92 }); | 92 }); |
93 }); | 93 }); |
94 } | 94 } |
95 | 95 |
96 void testSimpleConnectFail(String certificate) { | 96 void testSimpleConnectFail(String certificate) { |
97 ReceivePort port = new ReceivePort(); | 97 ReceivePort port = new ReceivePort(); |
98 SecureServerSocket.bind(SERVER_ADDRESS, 0, 5, certificate).then((server) { | 98 SecureServerSocket.bind(SERVER_ADDRESS, 0, 5, certificate).then((server) { |
99 var clientEndFuture = SecureSocket.connect(HOST_NAME, server.port) | 99 var clientEndFuture = SecureSocket.connect(HOST_NAME, server.port) |
100 .then((clientEnd) { | 100 .then((clientEnd) { |
101 Expect.fail("No client connection expected."); | 101 Expect.fail("No client connection expected."); |
102 }) | 102 }) |
103 .catchError((e) { | 103 .catchError((error) { |
104 Expect.isTrue(e is AsyncError); | 104 Expect.isTrue(error is SocketIOException); |
105 Expect.isTrue(e.error is SocketIOException); | |
106 }); | 105 }); |
107 server.listen((serverEnd) { | 106 server.listen((serverEnd) { |
108 Expect.fail("No server connection expected."); | 107 Expect.fail("No server connection expected."); |
109 }, | 108 }, |
110 onError: (e) { | 109 onError: (error) { |
111 Expect.isTrue(e is AsyncError); | 110 Expect.isTrue(error is SocketIOException); |
112 Expect.isTrue(e.error is SocketIOException); | |
113 clientEndFuture.then((_) => port.close()); | 111 clientEndFuture.then((_) => port.close()); |
114 }); | 112 }); |
115 }); | 113 }); |
116 } | 114 } |
117 | 115 |
118 void testServerListenAfterConnect() { | 116 void testServerListenAfterConnect() { |
119 ReceivePort port = new ReceivePort(); | 117 ReceivePort port = new ReceivePort(); |
120 SecureServerSocket.bind(SERVER_ADDRESS, 0, 5, CERTIFICATE).then((server) { | 118 SecureServerSocket.bind(SERVER_ADDRESS, 0, 5, CERTIFICATE).then((server) { |
121 Expect.isTrue(server.port > 0); | 119 Expect.isTrue(server.port > 0); |
122 var clientEndFuture = SecureSocket.connect(HOST_NAME, server.port); | 120 var clientEndFuture = SecureSocket.connect(HOST_NAME, server.port); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 testArguments(); | 208 testArguments(); |
211 testSimpleBind(); | 209 testSimpleBind(); |
212 testInvalidBind(); | 210 testInvalidBind(); |
213 testSimpleConnect(CERTIFICATE); | 211 testSimpleConnect(CERTIFICATE); |
214 testSimpleConnect("CN=localhost"); | 212 testSimpleConnect("CN=localhost"); |
215 testSimpleConnectFail("not_a_nickname"); | 213 testSimpleConnectFail("not_a_nickname"); |
216 testSimpleConnectFail("CN=notARealDistinguishedName"); | 214 testSimpleConnectFail("CN=notARealDistinguishedName"); |
217 testServerListenAfterConnect(); | 215 testServerListenAfterConnect(); |
218 testSimpleReadWrite(); | 216 testSimpleReadWrite(); |
219 } | 217 } |
OLD | NEW |