0af5298845
The parameter defaults to false. This enables creating a SecurityContext that includes the trusted root certificates that can be modified per-connection. fixes #24693 Change-Id: I22e5736838755ce4055f77b1b17aeb5176329240 Reviewed-on: https://dart-review.googlesource.com/20580 Reviewed-by: William Hesse <whesse@google.com> Commit-Queue: Zach Anderson <zra@google.com>
43 lines
1.5 KiB
Dart
43 lines
1.5 KiB
Dart
// Copyright (c) 2012, 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 "dart:async";
|
|
|
|
import "package:async_helper/async_helper.dart";
|
|
import "package:expect/expect.dart";
|
|
|
|
Future testGoogleUrl(SecurityContext context, String outcome) async {
|
|
var client = new HttpClient(context: context);
|
|
// We need to use an external server that is backed by a
|
|
// built-in root certificate authority.
|
|
try {
|
|
// First, check if the lookup works.
|
|
await InternetAddress.lookup('www.google.com');
|
|
var request = await client.getUrl(Uri.parse('https://www.google.com'));
|
|
request.followRedirects = false;
|
|
var response = await request.close();
|
|
Expect.equals('pass', outcome, 'Unexpected successful connection');
|
|
try {
|
|
await response.drain();
|
|
} catch (e) {}
|
|
} on HandshakeException {
|
|
Expect.equals('fail', outcome, 'Unexpected failed connection');
|
|
} on SocketException {
|
|
// Lookup failed or connection failed. Don't report a failure.
|
|
} finally {
|
|
client.close();
|
|
}
|
|
}
|
|
|
|
main() async {
|
|
asyncStart();
|
|
await testGoogleUrl(null, "pass");
|
|
await testGoogleUrl(SecurityContext.defaultContext, "pass");
|
|
await testGoogleUrl(new SecurityContext(withTrustedRoots: true), "pass");
|
|
await testGoogleUrl(new SecurityContext(withTrustedRoots: false), "fail");
|
|
await testGoogleUrl(new SecurityContext(), "fail");
|
|
asyncEnd();
|
|
}
|