| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import "dart:io"; | 6 import "dart:io"; |
| 7 | 7 |
| 8 String localFile(path) => Platform.script.resolve(path).toFilePath(); | 8 String localFile(path) => Platform.script.resolve(path).toFilePath(); |
| 9 List<int> readLocalFile(path) => (new File(localFile(path))).readAsBytesSync(); | |
| 10 | 9 |
| 11 bool printException(e) { print(e); return true; } | 10 bool printException(e) { print(e); return true; } |
| 12 bool argumentError(e) => e is ArgumentError; | 11 bool argumentError(e) => e is ArgumentError; |
| 13 bool argumentOrTypeError(e) => e is ArgumentError || e is TypeError; | 12 bool argumentOrTypeError(e) => e is ArgumentError || e is TypeError; |
| 14 bool fileSystemException(e) => e is FileSystemException; | 13 bool fileSystemException(e) => e is FileSystemException; |
| 15 bool tlsException(e) => e is TlsException; | 14 bool tlsException(e) => e is TlsException; |
| 16 | 15 |
| 17 void testUsePrivateKeyArguments() { | 16 void testUsePrivateKeyArguments() { |
| 18 var c = new SecurityContext(); | 17 var c = new SecurityContext(); |
| 19 c.useCertificateChainBytes(readLocalFile('certificates/server_chain.pem')); | 18 c.useCertificateChainSync(localFile('certificates/server_chain.pem')); |
| 20 Expect.throws(() => c.usePrivateKeyBytes( | 19 Expect.throws(() => c.usePrivateKeySync( |
| 21 readLocalFile('certificates/server_key.pem'), | 20 localFile('certificates/server_key.pem'), password: "dart" * 1000), |
| 22 password: "dart" * 1000), | |
| 23 argumentError); | 21 argumentError); |
| 24 Expect.throws(() => c.usePrivateKeyBytes( | 22 Expect.throws(() => c.usePrivateKeySync( |
| 25 readLocalFile('certificates/server_key.pem')), | 23 localFile('certificates/server_key.pem')), |
| 26 tlsException); | 24 tlsException); |
| 27 Expect.throws(() => c.usePrivateKeyBytes( | 25 Expect.throws(() => c.usePrivateKeySync( |
| 28 readLocalFile('certificates/server_key.pem'), password: "iHackSites"), | 26 localFile('certificates/server_key.pem'), password: "iHackSites"), |
| 29 tlsException); | 27 tlsException); |
| 30 Expect.throws(() => c.usePrivateKeyBytes( | 28 Expect.throws(() => c.usePrivateKeySync( |
| 31 readLocalFile('certificates/server_key_oops.pem'), | 29 localFile('certificates/server_key_oops.pem'), |
| 32 password: "dartdart"), | 30 password: "dartdart"), |
| 33 fileSystemException); | 31 fileSystemException); |
| 34 Expect.throws(() => c.usePrivateKeyBytes(1), argumentOrTypeError); | 32 Expect.throws(() => c.usePrivateKeySync(1), argumentOrTypeError); |
| 35 Expect.throws(() => c.usePrivateKeyBytes(null), argumentError); | 33 Expect.throws(() => c.usePrivateKeySync(null), argumentError); |
| 36 Expect.throws(() => c.usePrivateKeyBytes( | 34 Expect.throws(() => c.usePrivateKeySync( |
| 37 readLocalFile('certificates/server_key_oops.pem'), password: 3), | 35 localFile('certificates/server_key_oops.pem'), password: 3), |
| 38 fileSystemException); | 36 fileSystemException); |
| 39 c.usePrivateKeyBytes( | 37 c.usePrivateKeySync( |
| 40 readLocalFile('certificates/server_key.pem'), password: "dartdart"); | 38 localFile('certificates/server_key.pem'), password: "dartdart"); |
| 41 } | 39 } |
| 42 | 40 |
| 43 void main() { | 41 void main() { |
| 44 testUsePrivateKeyArguments(); | 42 testUsePrivateKeyArguments(); |
| 45 } | 43 } |
| OLD | NEW |