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(); |
9 | 10 |
10 bool printException(e) { print(e); return true; } | 11 bool printException(e) { print(e); return true; } |
11 bool argumentError(e) => e is ArgumentError; | 12 bool argumentError(e) => e is ArgumentError; |
12 bool argumentOrTypeError(e) => e is ArgumentError || e is TypeError; | 13 bool argumentOrTypeError(e) => e is ArgumentError || e is TypeError; |
| 14 bool fileSystemException(e) => e is FileSystemException; |
13 bool tlsException(e) => e is TlsException; | 15 bool tlsException(e) => e is TlsException; |
14 | 16 |
15 void testUsePrivateKeyArguments() { | 17 void testUsePrivateKeyArguments() { |
16 var c = new SecurityContext(); | 18 var c = new SecurityContext(); |
17 c.useCertificateChain(localFile('certificates/server_chain.pem')); | 19 c.useCertificateChain(localFile('certificates/server_chain.pem')); |
18 Expect.throws(() => c.usePrivateKey( | 20 Expect.throws(() => c.usePrivateKeyAsBytes( |
19 localFile('certificates/server_key.pem'), password: "dart" * 1000), | 21 readLocalFile('certificates/server_key.pem'), |
| 22 password: "dart" * 1000), |
20 argumentError); | 23 argumentError); |
21 Expect.throws(() => c.usePrivateKey( | 24 Expect.throws(() => c.usePrivateKeyAsBytes( |
22 localFile('certificates/server_key.pem')), | 25 readLocalFile('certificates/server_key.pem')), |
23 tlsException); | 26 tlsException); |
24 Expect.throws(() => c.usePrivateKey( | 27 Expect.throws(() => c.usePrivateKeyAsBytes( |
25 localFile('certificates/server_key.pem'), password: "iHackSites"), | 28 readLocalFile('certificates/server_key.pem'), password: "iHackSites"), |
26 tlsException); | 29 tlsException); |
27 Expect.throws(() => c.usePrivateKey( | 30 Expect.throws(() => c.usePrivateKeyAsBytes( |
28 localFile('certificates/server_key_oops.pem'), password: "dartdart"), | 31 readLocalFile('certificates/server_key_oops.pem'), |
29 tlsException); | 32 password: "dartdart"), |
30 Expect.throws(() => c.usePrivateKey(1), argumentOrTypeError); | 33 fileSystemException); |
31 Expect.throws(() => c.usePrivateKey(null), argumentError); | 34 Expect.throws(() => c.usePrivateKeyAsBytes(1), argumentOrTypeError); |
32 Expect.throws(() => c.usePrivateKey( | 35 Expect.throws(() => c.usePrivateKeyAsBytes(null), argumentError); |
33 localFile('certificates/server_key_oops.pem'), password: 3), | 36 Expect.throws(() => c.usePrivateKeyAsBytes( |
34 argumentOrTypeError); | 37 readLocalFile('certificates/server_key_oops.pem'), password: 3), |
35 c.usePrivateKey( | 38 fileSystemException); |
36 localFile('certificates/server_key.pem'), password: "dartdart"); | 39 c.usePrivateKeyAsBytes( |
37 } | 40 readLocalFile('certificates/server_key.pem'), password: "dartdart"); |
| 41 } |
38 | 42 |
39 void main() { | 43 void main() { |
40 testUsePrivateKeyArguments(); | 44 testUsePrivateKeyArguments(); |
41 } | 45 } |
OLD | NEW |