blob: ae51a37b14208979309f1187cdf978287c6f4cae [file] [log] [blame]
// Copyright (c) 2020, 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.
// This test file disallows VM from accepting insecure connections to all
// domains and tests that HTTP connections to non-localhost targets fail.
// HTTPS connections and localhost connections should still succeed.
import "dart:async";
import "dart:io";
import "package:async_helper/async_helper.dart";
Future<void> testWithHostname() async {
final httpClient = new HttpClient();
final uri = Uri(scheme: 'http', host: 'domain.invalid', port: 12345);
() async => await httpClient.getUrl(uri),
(e) =>
e is StateError &&
e.message.contains("Insecure HTTP is not allowed by platform"));
main() {
testWithHostname().then((_) => asyncEnd());