| 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. | 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 Loading... |
| 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 } |
| OLD | NEW |