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

Unified Diff: tests/standalone/io/https_client_certificate_test.dart

Issue 12316036: Merge IO v2 branch to bleeding edge (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased to r18818 Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/standalone/io/http_stream_close_test.dart ('k') | tests/standalone/io/https_client_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/https_client_certificate_test.dart
diff --git a/tests/standalone/io/https_client_certificate_test.dart b/tests/standalone/io/https_client_certificate_test.dart
index 67162a5aca6d4557484a2179f386ea079f7e6166..1d9b0e4180c6d867d85c887a716b59e2500cd44c 100644
--- a/tests/standalone/io/https_client_certificate_test.dart
+++ b/tests/standalone/io/https_client_certificate_test.dart
@@ -1,4 +1,4 @@
-// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2013, 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.
@@ -10,71 +10,34 @@ import "dart:isolate";
const SERVER_ADDRESS = "127.0.0.1";
const HOST_NAME = "localhost";
-int numClientCertificatesReceived = 0;
-Function test(Map options) {
- Future runTest([var unused]) {
- var completer = new Completer();
- HttpsServer server = new HttpsServer();
- Expect.throws(() => server.port);
-
- server.defaultRequestHandler =
- (HttpRequest request, HttpResponse response) {
- if (request.path == '/true') {
- // Client certificate sent
- numClientCertificatesReceived++;
- Expect.isNotNull(request.certificate);
- Expect.equals('CN=localhost', request.certificate.subject);
- } else {
- Expect.equals('/false', request.path);
- Expect.isNull(request.certificate);
- }
-
- request.inputStream.onClosed = () {
- response.outputStream.close();
- };
- };
-
- server.listen(SERVER_ADDRESS,
- 0,
- backlog: 5,
- certificate_name: 'CN=$HOST_NAME',
- requestClientCertificate: true);
+Function test() {
+ var keepAlive = new ReceivePort();
+ HttpServer.bindSecure(SERVER_ADDRESS,
+ 0,
+ backlog: 5,
+ certificateName: 'localhost_cert',
+ requestClientCertificate: true).then((server) {
+ server.listen((HttpRequest request) {
+ Expect.isNotNull(request.certificate);
+ Expect.equals('CN=localhost', request.certificate.subject);
+ request.response.addString("Hello");
+ request.response.close();
+ });
HttpClient client = new HttpClient();
- Future testConnect(bool sendCertificate) {
- client.sendClientCertificate = sendCertificate;
- client.clientCertificate = options['certificateName'];
- var completer = new Completer();
- HttpClientConnection conn =
- client.getUrl(Uri.parse(
- "https://$HOST_NAME:${server.port}/$sendCertificate"));
- conn.onRequest = (HttpClientRequest request) {
- request.outputStream.close();
- };
- conn.onResponse = (HttpClientResponse response) {
- Expect.isNotNull(response.certificate);
- Expect.equals('CN=myauthority', response.certificate.issuer);
- response.inputStream.onClosed = () {
- completer.complete(false); // Chained call will not send cert.
- };
- };
- conn.onError = (Exception e) {
- Expect.fail("Unexpected error in Https Client: $e");
- };
- return completer.future;
- }
-
- testConnect(true).then(testConnect).then((_) {
- client.shutdown();
- server.close();
- Expect.throws(() => server.port);
- // Run second test with a certificate name.
- completer.complete(null);
- });
- return completer.future;
- }
- return runTest;
+ client.getUrl(Uri.parse("https://$HOST_NAME:${server.port}/"))
+ .then((request) => request.close())
+ .then((response) =>
+ response.reduce(<int>[], (message, data) => message..addAll(data)))
+ .then((message) {
+ String received = new String.fromCharCodes(message);
+ Expect.equals(received, "Hello");
+ client.close();
+ server.close();
+ keepAlive.close();
+ });
+ });
}
void InitializeSSL() {
@@ -85,13 +48,6 @@ void InitializeSSL() {
}
void main() {
- var keepAlive = new ReceivePort();
InitializeSSL();
- // Test two connections in sequence.
- test({'certificateName': null})()
- .then((_) => test({'certificateName': 'localhost_cert'})())
- .then((_) {
- Expect.equals(2, numClientCertificatesReceived);
- keepAlive.close();
- });
+ test();
}
« no previous file with comments | « tests/standalone/io/http_stream_close_test.dart ('k') | tests/standalone/io/https_client_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698