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

Unified Diff: tests/standalone/io/http_loopback_test.dart

Issue 2931623003: Updated HttpServer documentation to specify that only IPv6 connections can be made when specifying … (Closed)
Patch Set: Removed extra asyncs Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/io/http.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..d240996a564af7384dbdc5020263732badd17149
--- /dev/null
+++ b/tests/standalone/io/http_loopback_test.dart
@@ -0,0 +1,79 @@
+// 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 "package:expect/expect.dart";
+
+RawServerSocket server;
+RawSocket client;
+
+serverListen(RawSocket serverSide) {
+ serveData(RawSocketEvent event) {
+ serverSide.shutdown(SocketDirection.SEND);
+ }
+
+ 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();
+ }
+}
+
+main() async {
+ await IPv4ToIPv6FailureTest();
+ await IPv6ToIPv4FailureTest();
+ await loopbackSuccessTest(InternetAddress.LOOPBACK_IP_V4);
+ await loopbackSuccessTest(InternetAddress.LOOPBACK_IP_V6);
+}
« no previous file with comments | « sdk/lib/io/http.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698