Chromium Code Reviews| Index: tests/standalone/io/http_loopback_test.dart |
| diff --git a/tests/standalone/io/http_loopback_test.dart b/tests/standalone/io/http_loopback_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..eaa38ef0c96e0733da7c27879980882c44ed8210 |
| --- /dev/null |
| +++ b/tests/standalone/io/http_loopback_test.dart |
| @@ -0,0 +1,81 @@ |
| +// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +import "dart:io"; |
| +import "dart:async"; |
| +import "package:expect/expect.dart"; |
| + |
| +RawServerSocket server; |
| +RawSocket client; |
| + |
| +void serverListen(RawSocket serverSide) async { |
|
zra
2017/06/08 21:45:21
The analyzer will complain about this because asyn
bkonyi
2017/06/08 22:49:37
I've gone ahead and removed the void token from th
|
| + void serveData(RawSocketEvent event) async { |
|
zra
2017/06/08 21:45:21
ditto
bkonyi
2017/06/08 22:49:37
Done.
|
| + serverSide.shutdown(SocketDirection.SEND); |
| + await server.close(); |
|
zra
2017/06/08 21:45:21
server is already closed below in the finally bloc
bkonyi
2017/06/08 22:49:38
You're right, I just forgot to remove this. Done.
|
| + } |
| + |
| + serverSide.listen(serveData); |
| +} |
| + |
| +IPv4ToIPv6FailureTest() async { |
| + server = await RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V6, 0); |
| + server.listen(serverListen); |
| + bool testFailure = false; |
| + try { |
| + client = |
| + await RawSocket.connect(InternetAddress.LOOPBACK_IP_V4, server.port); |
| + await client.close(); |
| + testFailure = true; |
| + } on SocketException catch (e) { |
| + // We shouldn't be able to connect to the IPv6 loopback adapter using the |
| + // IPv4 loopback address. |
| + } catch (e) { |
| + testFailure = true; |
| + } finally { |
| + Expect.equals(testFailure, false); |
| + await server.close(); |
| + } |
| +} |
| + |
| +IPv6ToIPv4FailureTest() async { |
| + server = await RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0); |
| + server.listen(serverListen); |
| + bool testFailure = false; |
| + try { |
| + client = |
| + await RawSocket.connect(InternetAddress.LOOPBACK_IP_V6, server.port); |
| + await client.close(); |
| + testFailure = true; |
| + } on SocketException catch (e) { |
| + // We shouldn't be able to connect to the IPv4 loopback adapter using the |
| + // IPv6 loopback address. |
| + } catch (e) { |
| + testFailure = true; |
| + } finally { |
| + Expect.equals(testFailure, false); |
| + await server.close(); |
| + } |
| +} |
| + |
| +loopbackSuccessTest(InternetAddress address) async { |
| + server = await RawServerSocket.bind(address, 0); |
| + server.listen(serverListen); |
| + bool testFailure = false; |
| + try { |
| + client = await RawSocket.connect(address, server.port); |
| + await client.close(); |
| + } catch (e) { |
| + testFailure = true; |
| + } finally { |
| + Expect.equals(testFailure, false); |
| + await server.close(); |
| + } |
| +} |
| + |
| +void main() async { |
| + await IPv4ToIPv6FailureTest(); |
| + await IPv6ToIPv4FailureTest(); |
| + await loopbackSuccessTest(InternetAddress.LOOPBACK_IP_V4); |
| + await loopbackSuccessTest(InternetAddress.LOOPBACK_IP_V6); |
| +} |