OLD | NEW |
(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 } |
OLD | NEW |