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

Side by Side Diff: tests/standalone/io/secure_bad_certificate_test.dart

Issue 1721283002: Implements secure sockets on Mac OS with SecureTransport API (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comments Created 4 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // This test verifies that the bad certificate callback works. 5 // This test verifies that the bad certificate callback works.
6 6
7 import "dart:async"; 7 import "dart:async";
8 import "dart:io"; 8 import "dart:io";
9 9
10 import "package:expect/expect.dart"; 10 import "package:expect/expect.dart";
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 await runClient(server.port, defaultContext, 'exception', 'throw'); 48 await runClient(server.port, defaultContext, 'exception', 'throw');
49 server.close(); 49 server.close();
50 } 50 }
51 51
52 52
53 Future runClient(int port, 53 Future runClient(int port,
54 SecurityContext context, 54 SecurityContext context,
55 callbackReturns, 55 callbackReturns,
56 result) async { 56 result) async {
57 badCertificateCallback(X509Certificate certificate) { 57 badCertificateCallback(X509Certificate certificate) {
58 Expect.equals('/CN=rootauthority', certificate.subject); 58 Expect.isTrue(certificate.subject.contains('rootauthority'));
59 Expect.equals('/CN=rootauthority', certificate.issuer); 59 Expect.isTrue(certificate.issuer.contains('rootauthority'));
60 // Throw exception if one is requested. 60 // Throw exception if one is requested.
61 if (callbackReturns == 'exception') throw new CustomException(); 61 if (callbackReturns == 'exception') throw new CustomException();
62 return callbackReturns; 62 return callbackReturns;
63 } 63 }
64 64
65 try { 65 try {
66 var socket = await SecureSocket.connect( 66 var socket = await SecureSocket.connect(
67 HOST_NAME, 67 HOST_NAME,
68 port, 68 port,
69 context: context, 69 context: context,
70 onBadCertificate: badCertificateCallback); 70 onBadCertificate: badCertificateCallback);
71 Expect.equals('pass', result); // Is rethrown below 71 Expect.equals('pass', result); // Is rethrown below
72 await socket.close(); 72 await socket.close();
73 } catch (error) { 73 } catch (error) {
74 if (error is ExpectException) rethrow; 74 if (error is ExpectException) rethrow;
75 Expect.notEquals(result, 'pass'); 75 Expect.notEquals(result, 'pass');
76 if (result == 'fail') { 76 if (result == 'fail') {
77 Expect.isTrue(error is HandshakeException || error is ArgumentError); 77 Expect.isTrue(error is HandshakeException || error is ArgumentError);
78 } else if (result == 'throw') { 78 } else if (result == 'throw') {
79 Expect.isTrue(error is CustomException); 79 Expect.isTrue(error is CustomException);
80 } else { 80 } else {
81 Expect.fail('Unknown expectation $result'); 81 Expect.fail('Unknown expectation $result');
82 } 82 }
83 } 83 }
84 } 84 }
OLDNEW
« no previous file with comments | « tests/standalone/io/https_bad_certificate_test.dart ('k') | tests/standalone/io/secure_builtin_roots_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698