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 | 9 |
10 bool printException(e) { print(e); return true; } | 10 bool printException(e) { print(e); return true; } |
(...skipping 26 matching lines...) Expand all Loading... |
37 localFile('certificates/server_key.p12'), password: "iHackSites"), | 37 localFile('certificates/server_key.p12'), password: "iHackSites"), |
38 tlsException); | 38 tlsException); |
39 Expect.throws(() => c.useCertificateChain( | 39 Expect.throws(() => c.useCertificateChain( |
40 localFile('certificates/server_key.p12')), | 40 localFile('certificates/server_key.p12')), |
41 tlsException); | 41 tlsException); |
42 Expect.throws(() => c.useCertificateChain( | 42 Expect.throws(() => c.useCertificateChain( |
43 localFile('certificates/server_key.p12'), password: "iHackSites"), | 43 localFile('certificates/server_key.p12'), password: "iHackSites"), |
44 tlsException); | 44 tlsException); |
45 Expect.throws(() => c.setClientAuthorities( | 45 Expect.throws(() => c.setClientAuthorities( |
46 localFile('certificates/server_key.p12')), | 46 localFile('certificates/server_key.p12')), |
47 argumentError); | 47 tlsException); |
48 Expect.throws(() => c.setClientAuthorities( | 48 Expect.throws(() => c.setClientAuthorities( |
49 localFile('certificates/server_key.p12'), password: "iHackSites"), | 49 localFile('certificates/server_key.p12'), password: "iHackSites"), |
50 argumentError); | 50 tlsException); |
51 | 51 |
52 // File does not exist | 52 // File does not exist |
53 Expect.throws(() => c.usePrivateKey( | 53 Expect.throws(() => c.usePrivateKey( |
54 localFile('certificates/server_key_oops.pem'), | 54 localFile('certificates/server_key_oops.pem'), |
55 password: "dartdart"), | 55 password: "dartdart"), |
56 fileSystemException); | 56 fileSystemException); |
57 | 57 |
58 // Wrong type for file name or data | 58 // Wrong type for file name or data |
59 Expect.throws(() => c.usePrivateKey(1), argumentOrTypeError); | 59 Expect.throws(() => c.usePrivateKey(1), argumentOrTypeError); |
60 Expect.throws(() => c.usePrivateKey(null), argumentError); | 60 Expect.throws(() => c.usePrivateKey(null), argumentError); |
(...skipping 29 matching lines...) Expand all Loading... |
90 argumentOrTypeError); | 90 argumentOrTypeError); |
91 Expect.throws(() => c.setClientAuthoritiesBytes( | 91 Expect.throws(() => c.setClientAuthoritiesBytes( |
92 localFile('certificates/server_key.pem'), password: 3), | 92 localFile('certificates/server_key.pem'), password: 3), |
93 argumentOrTypeError); | 93 argumentOrTypeError); |
94 | 94 |
95 // Empty data. | 95 // Empty data. |
96 Expect.throws(() => c.usePrivateKeyBytes([], password: 'dartdart'), | 96 Expect.throws(() => c.usePrivateKeyBytes([], password: 'dartdart'), |
97 tlsException); | 97 tlsException); |
98 Expect.throws(() => c.setTrustedCertificatesBytes([]), tlsException); | 98 Expect.throws(() => c.setTrustedCertificatesBytes([]), tlsException); |
99 Expect.throws(() => c.useCertificateChainBytes([]), tlsException); | 99 Expect.throws(() => c.useCertificateChainBytes([]), tlsException); |
100 Expect.throws(() => c.setClientAuthoritiesBytes([]), argumentError); | 100 Expect.throws(() => c.setClientAuthoritiesBytes([]), tlsException); |
101 | 101 |
102 // Malformed PEM certs. | 102 // Malformed PEM certs. |
103 Expect.throws(() => c.usePrivateKey( | 103 Expect.throws(() => c.usePrivateKey( |
104 localFile('certificates/client1_key_malformed.pem'), | 104 localFile('certificates/client1_key_malformed.pem'), |
105 password: "dartdart"), | 105 password: "dartdart"), |
106 tlsException); | 106 tlsException); |
107 Expect.throws(() => c.setTrustedCertificates( | 107 Expect.throws(() => c.setTrustedCertificates( |
108 localFile('certificates/trusted_certs_malformed.pem')), | 108 localFile('certificates/trusted_certs_malformed.pem')), |
109 tlsException); | 109 tlsException); |
110 Expect.throws(() => c.useCertificateChain( | 110 Expect.throws(() => c.useCertificateChain( |
111 localFile('certificates/server_chain_malformed1.pem')), | 111 localFile('certificates/server_chain_malformed1.pem')), |
112 tlsException); | 112 tlsException); |
113 Expect.throws(() => c.useCertificateChain( | 113 Expect.throws(() => c.useCertificateChain( |
114 localFile('certificates/server_chain_malformed2.pem')), | 114 localFile('certificates/server_chain_malformed2.pem')), |
115 tlsException); | 115 tlsException); |
116 Expect.throws(() => c.setClientAuthorities( | 116 Expect.throws(() => c.setClientAuthorities( |
117 localFile('certificates/client_authority_malformed.pem')), | 117 localFile('certificates/client_authority_malformed.pem')), |
118 argumentError); | 118 tlsException); |
119 | 119 |
120 c.usePrivateKey( | 120 c.usePrivateKey( |
121 localFile('certificates/server_key.pem'), password: "dartdart"); | 121 localFile('certificates/server_key.pem'), password: "dartdart"); |
122 } | 122 } |
123 | 123 |
124 void main() { | 124 void main() { |
125 testUsePrivateKeyArguments(); | 125 testUsePrivateKeyArguments(); |
126 } | 126 } |
OLD | NEW |