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

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

Issue 11414009: Secure server sockets for dart:io. Add TlsServerSocket class, providing SSL server sockets. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 1 month 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/pkcert/key4.db ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/tls_server_test.dart
diff --git a/tests/standalone/io/tls_server_test.dart b/tests/standalone/io/tls_server_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..372b114cb3f85c5e7826adcbd80b59ee172d21c2
--- /dev/null
+++ b/tests/standalone/io/tls_server_test.dart
@@ -0,0 +1,109 @@
+// Copyright (c) 2012, 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.
+
+import "dart:io";
+
+const SERVER_ADDRESS = "127.0.0.1";
+const HOST_NAME = "localhost";
+
+class TlsTestServer {
+ void onConnection(Socket connection) {
+ connection.onConnect = () {
+ numConnections++;
+ };
+ connection.onData = () {
+ var data = connection.read();
Søren Gjesse 2012/11/20 21:03:34 This read is not guaranteed to return a specific a
+ var received = new String.fromCharCodes(data);
+ Expect.isTrue(received.contains("Hello from client "));
+ string name = received.substring(received.indexOf("client ") + 7);
+ var reply_bytes = "Welcome, client $name".charCodes;
+ connection.writeList(reply_bytes, 0, reply_bytes.length);
Søren Gjesse 2012/11/20 21:03:34 Likewise the writeList is not guaranteed to write
+ };
+ }
+
+ void errorHandlerServer(Exception e) {
+ Expect.fail("Server socket error $e");
+ }
+
+ int start() {
+ server = new TlsServerSocket(SERVER_ADDRESS, 0, 10, "CN=$HOST_NAME");
+ Expect.isNotNull(server);
+ server.onConnection = onConnection;
+ server.onError = errorHandlerServer;
+ return server.port;
+ }
+
+ void stop() {
+ server.close();
+ }
+
+ int numConnections = 0;
+ TlsServerSocket server;
+}
+
+class TlsTestClient {
+ TlsTestClient(int this.port, String this.name) {
+ socket = new TlsSocket(HOST_NAME, port);
+ socket.onConnect = this.onConnect;
+ socket.onData = this.onData;
+ reply = "";
+ }
+
+ void onConnect() {
+ numRequests++;
+ var request_bytes =
+ "Hello from client $name".charCodes;
+ socket.writeList(request_bytes, 0, request_bytes.length);
Søren Gjesse 2012/11/20 21:03:34 Ditto.
+ }
+
+ void onData() {
+ var data = socket.read();
Søren Gjesse 2012/11/20 21:03:34 Ditto.
+ var received = new String.fromCharCodes(data);
+ reply = reply.concat(received);
+ if (reply.contains("Welcome") && reply.contains(name)) {
+ done();
+ }
+ }
+
+ void done() {
+ Expect.equals("Welcome, client $name", reply);
+ socket.close(true);
+ numReplies++;
+ if (numReplies == CLIENT_NAMES.length) {
+ Expect.equals(numRequests, numReplies);
+ EndTest();
+ }
+ }
+
+ static int numRequests = 0;
+ static int numReplies = 0;
+
+ int port;
+ String name;
+ TlsSocket socket;
+ String reply;
+}
+
+Function EndTest;
+
+const CLIENT_NAMES = const ['able', 'baker', 'camera', 'donut', 'echo'];
+
+void main() {
+ Path scriptDir = new Path.fromNative(new Options().script).directoryPath;
+ Path certificateDatabase = scriptDir.append('pkcert');
+ TlsSocket.setCertificateDatabase(certificateDatabase.toNativePath(),
+ 'dartdart');
+
+ var server = new TlsTestServer();
+ int port = server.start();
+
+ EndTest = () {
+ Expect.equals(CLIENT_NAMES.length, server.numConnections);
+ server.stop();
+ };
+
+ for (var x in CLIENT_NAMES) {
+ new TlsTestClient(port, x);
+ }
+}
« no previous file with comments | « tests/standalone/io/pkcert/key4.db ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698