Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(538)

Unified Diff: tests/standalone/io/certificate_test_client.dart

Issue 18097007: Add SecureSocket.addCertificate. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add documentation link, and some constant trust strings. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/standalone/io/certificate_test.dart ('k') | tests/standalone/io/pkcert/myauthority.pem » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
+ });
+}
« no previous file with comments | « tests/standalone/io/certificate_test.dart ('k') | tests/standalone/io/pkcert/myauthority.pem » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698