OLD | NEW |
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 in HttpClient. | 5 // This test verifies that the bad certificate callback works in HttpClient. |
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 server.close(); | 50 server.close(); |
51 } | 51 } |
52 | 52 |
53 | 53 |
54 Future runClient(int port, | 54 Future runClient(int port, |
55 SecurityContext context, | 55 SecurityContext context, |
56 callbackReturns, | 56 callbackReturns, |
57 result) async { | 57 result) async { |
58 HttpClient client = new HttpClient(context: context); | 58 HttpClient client = new HttpClient(context: context); |
59 client.badCertificateCallback = (X509Certificate certificate, host, port) { | 59 client.badCertificateCallback = (X509Certificate certificate, host, port) { |
60 Expect.equals('/CN=rootauthority', certificate.subject); | 60 Expect.isTrue(certificate.subject.contains('rootauthority')); |
61 Expect.equals('/CN=rootauthority', certificate.issuer); | 61 Expect.isTrue(certificate.issuer.contains('rootauthority')); |
62 // Throw exception if one is requested. | 62 // Throw exception if one is requested. |
63 if (callbackReturns == 'exception') throw new CustomException(); | 63 if (callbackReturns == 'exception') throw new CustomException(); |
64 return callbackReturns; | 64 return callbackReturns; |
65 }; | 65 }; |
66 | 66 |
67 try { | 67 try { |
68 var request = await client.getUrl(Uri.parse('https://$HOST_NAME:$port/')); | 68 var request = await client.getUrl(Uri.parse('https://$HOST_NAME:$port/')); |
69 Expect.equals('pass', result); | 69 Expect.equals('pass', result); |
70 await request.close(); | 70 await request.close(); |
71 } catch (error) { | 71 } catch (error) { |
72 Expect.notEquals(result, 'pass'); | 72 Expect.notEquals(result, 'pass'); |
73 if (result == 'fail') { | 73 if (result == 'fail') { |
74 Expect.isTrue(error is HandshakeException); | 74 Expect.isTrue(error is HandshakeException); |
75 } else if (result == 'throw') { | 75 } else if (result == 'throw') { |
76 Expect.isTrue(error is CustomException); | 76 Expect.isTrue(error is CustomException); |
77 } else { | 77 } else { |
78 Expect.fail('Unknown expectation $result'); | 78 Expect.fail('Unknown expectation $result'); |
79 } | 79 } |
80 } | 80 } |
81 } | 81 } |
OLD | NEW |