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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « sdk/lib/io/http.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
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.
4
5 import "dart:io";
6 import "package:expect/expect.dart";
7
8 RawServerSocket server;
9 RawSocket client;
10
11 serverListen(RawSocket serverSide) {
12 serveData(RawSocketEvent event) {
13 serverSide.shutdown(SocketDirection.SEND);
14 }
15
16 serverSide.listen(serveData);
17 }
18
19 IPv4ToIPv6FailureTest() async {
20 server = await RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V6, 0);
21 server.listen(serverListen);
22 bool testFailure = false;
23 try {
24 client =
25 await RawSocket.connect(InternetAddress.LOOPBACK_IP_V4, server.port);
26 await client.close();
27 testFailure = true;
28 } on SocketException catch (e) {
29 // We shouldn't be able to connect to the IPv6 loopback adapter using the
30 // IPv4 loopback address.
31 } catch (e) {
32 testFailure = true;
33 } finally {
34 Expect.equals(testFailure, false);
35 await server.close();
36 }
37 }
38
39 IPv6ToIPv4FailureTest() async {
40 server = await RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0);
41 server.listen(serverListen);
42 bool testFailure = false;
43 try {
44 client =
45 await RawSocket.connect(InternetAddress.LOOPBACK_IP_V6, server.port);
46 await client.close();
47 testFailure = true;
48 } on SocketException catch (e) {
49 // We shouldn't be able to connect to the IPv4 loopback adapter using the
50 // IPv6 loopback address.
51 } catch (e) {
52 testFailure = true;
53 } finally {
54 Expect.equals(testFailure, false);
55 await server.close();
56 }
57 }
58
59 loopbackSuccessTest(InternetAddress address) async {
60 server = await RawServerSocket.bind(address, 0);
61 server.listen(serverListen);
62 bool testFailure = false;
63 try {
64 client = await RawSocket.connect(address, server.port);
65 await client.close();
66 } catch (e) {
67 testFailure = true;
68 } finally {
69 Expect.equals(testFailure, false);
70 await server.close();
71 }
72 }
73
74 main() async {
75 await IPv4ToIPv6FailureTest();
76 await IPv6ToIPv4FailureTest();
77 await loopbackSuccessTest(InternetAddress.LOOPBACK_IP_V4);
78 await loopbackSuccessTest(InternetAddress.LOOPBACK_IP_V6);
79 }
OLDNEW
« 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