Index: tests/standalone/io/certificate_test_client.dart |
diff --git a/tests/standalone/io/certificate_test_client.dart b/tests/standalone/io/certificate_test_client.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f7f2fb238e0a37139cdf0d9f182541edb6b2b9ea |
--- /dev/null |
+++ b/tests/standalone/io/certificate_test_client.dart |
@@ -0,0 +1,41 @@ |
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+// |
+// Client that tests that a certificate authority certificate loaded |
+// at runtime can be used to verify a certificate chain. The server it |
+// connects to uses localhost_cert, signed by myauthority_cert, to connect |
+// securely. |
+ |
+import 'dart:io'; |
+ |
+void main() { |
+ int port = int.parse(new Options().arguments[0]); |
+ String certificate = new Options().arguments[1]; |
+ SecureSocket.initialize(); |
+ var mycert = new File(certificate).readAsBytesSync(); |
+ bool threw = false; |
+ try { |
+ SecureSocket.addCertificate("I am not a cert".codeUnits, |
+ SecureSocket.TRUST_ISSUE_SERVER_CERTIFICATES); |
+ } on CertificateException catch (e) { |
+ threw = true; |
+ } |
+ if (!threw) throw new AssertException("Expected bad certificate to throw"); |
+ |
+ threw = false; |
+ try { |
+ SecureSocket.addCertificate(mycert, "Trust me, I'm a string"); |
+ } on CertificateException catch (e) { |
+ threw = true; |
+ } |
+ if (!threw) throw new AssertException("Expected bad trust string to throw"); |
+ |
+ SecureSocket.addCertificate(mycert, |
+ SecureSocket.TRUST_ISSUE_SERVER_CERTIFICATES); |
+ SecureSocket.connect('localhost', port).then((SecureSocket socket) { |
+ socket.writeln("hello world"); |
+ socket.listen((data) { }); |
+ socket.close(); |
+ }); |
+} |