|
| 1 | +// Copyright (c) 2020, 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 | +// SharedOptions=-Ddart.library.io.allow_http=false |
| 6 | + |
| 7 | +import 'dart:async'; |
| 8 | +import 'dart:io'; |
| 9 | + |
| 10 | +import "package:async_helper/async_helper.dart"; |
| 11 | + |
| 12 | +import 'http_ban_http_normal_test.dart'; |
| 13 | +import 'http_bind_test.dart'; |
| 14 | + |
| 15 | +Future<void> testWithHostname() async { |
| 16 | + await testBanHttp(await getLocalHostIP(), (httpClient, httpUri) async { |
| 17 | + asyncExpectThrows( |
| 18 | + () async => await httpClient.getUrl(httpUri), (e) => e is StateError); |
| 19 | + asyncExpectThrows( |
| 20 | + () async => await runZoned(() => httpClient.getUrl(httpUri), |
| 21 | + zoneValues: {#dart.library.io.allow_http: 'foo'}), |
| 22 | + (e) => e is StateError); |
| 23 | + asyncExpectThrows( |
| 24 | + () async => await runZoned(() => httpClient.getUrl(httpUri), |
| 25 | + zoneValues: {#dart.library.io.allow_http: false}), |
| 26 | + (e) => e is StateError); |
| 27 | + await asyncTest(() => runZoned(() => httpClient.getUrl(httpUri), |
| 28 | + zoneValues: {#dart.library.io.allow_http: true})); |
| 29 | + }); |
| 30 | +} |
| 31 | + |
| 32 | +Future<void> testWithLoopback() async { |
| 33 | + await testBanHttp("127.0.0.1", (httpClient, uri) async { |
| 34 | + await asyncTest( |
| 35 | + () => httpClient.getUrl(Uri.parse('http://localhost:${uri.port}'))); |
| 36 | + await asyncTest( |
| 37 | + () => httpClient.getUrl(Uri.parse('http://127.0.0.1:${uri.port}'))); |
| 38 | + }); |
| 39 | +} |
| 40 | + |
| 41 | +Future<void> testWithIPv6() async { |
| 42 | + if (await supportsIPV6()) { |
| 43 | + await testBanHttp("::1", (httpClient, uri) async { |
| 44 | + await asyncTest(() => httpClient.getUrl(uri)); |
| 45 | + }); |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +Future<void> testWithHTTPS() async { |
| 50 | + await testBanHttp(await getLocalHostIP(), (httpClient, uri) async { |
| 51 | + asyncExpectThrows( |
| 52 | + () => httpClient.getUrl(Uri( |
| 53 | + scheme: 'https', |
| 54 | + host: uri.host, |
| 55 | + port: uri.port, |
| 56 | + )), |
| 57 | + (e) => e is SocketException || e is HandshakeException); |
| 58 | + }); |
| 59 | +} |
| 60 | + |
| 61 | +main() { |
| 62 | + asyncStart(); |
| 63 | + Future.wait(<Future>[ |
| 64 | + testWithHostname(), |
| 65 | + testWithLoopback(), |
| 66 | + testWithIPv6(), |
| 67 | + testWithHTTPS(), |
| 68 | + ]).then((_) => asyncEnd()); |
| 69 | +} |
0 commit comments