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