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

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

Issue 1319703002: Breaking Change: merge BoringSSL branch into master (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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
Index: tests/standalone/io/secure_server_socket_test.dart
diff --git a/tests/standalone/io/secure_server_socket_test.dart b/tests/standalone/io/secure_server_socket_test.dart
index a6a10878507a09b7865f2611951555c64ef781d1..6ef7f27e82d0bd027aba6738da22bf8f16112851 100644
--- a/tests/standalone/io/secure_server_socket_test.dart
+++ b/tests/standalone/io/secure_server_socket_test.dart
@@ -14,11 +14,20 @@ import "package:async_helper/async_helper.dart";
import "package:expect/expect.dart";
InternetAddress HOST;
-const CERTIFICATE = "localhost_cert";
+
+String localFile(path) => Platform.script.resolve(path).toFilePath();
+
+SecurityContext serverContext = new SecurityContext()
+ ..useCertificateChain(localFile('certificates/server_chain.pem'))
+ ..usePrivateKey(localFile('certificates/server_key.pem'),
+ password: 'dartdart');
+
+SecurityContext clientContext = new SecurityContext()
+ ..setTrustedCertificates(file: localFile('certificates/trusted_certs.pem'));
void testSimpleBind() {
asyncStart();
- SecureServerSocket.bind(HOST, 0, CERTIFICATE).then((s) {
+ SecureServerSocket.bind(HOST, 0, serverContext).then((s) {
Expect.isTrue(s.port > 0);
s.close();
asyncEnd();
@@ -30,7 +39,7 @@ void testInvalidBind() {
// Bind to a unknown DNS name.
asyncStart();
- SecureServerSocket.bind("ko.faar.__hest__", 0, CERTIFICATE).then((_) {
+ SecureServerSocket.bind("ko.faar.__hest__", 0, serverContext).then((_) {
Expect.fail("Failure expected");
}).catchError((error) {
Expect.isTrue(error is SocketException);
@@ -39,7 +48,7 @@ void testInvalidBind() {
// Bind to an unavaliable IP-address.
asyncStart();
- SecureServerSocket.bind("8.8.8.8", 0, CERTIFICATE).then((_) {
+ SecureServerSocket.bind("8.8.8.8", 0, serverContext).then((_) {
Expect.fail("Failure expected");
}).catchError((error) {
Expect.isTrue(error is SocketException);
@@ -48,10 +57,10 @@ void testInvalidBind() {
// Bind to a port already in use.
asyncStart();
- SecureServerSocket.bind(HOST, 0, CERTIFICATE).then((s) {
+ SecureServerSocket.bind(HOST, 0, serverContext).then((s) {
SecureServerSocket.bind(HOST,
s.port,
- CERTIFICATE).then((t) {
+ serverContext).then((t) {
Expect.fail("Multiple listens on same port");
}).catchError((error) {
Expect.isTrue(error is SocketException);
@@ -61,12 +70,18 @@ void testInvalidBind() {
});
}
-void testSimpleConnect(String certificate) {
+void testSimpleConnect() {
asyncStart();
- SecureServerSocket.bind(HOST, 0, certificate).then((server) {
- var clientEndFuture = SecureSocket.connect(HOST, server.port);
+ SecureServerSocket.bind(HOST, 0, serverContext).then((server) {
+ var clientEndFuture =
+ SecureSocket.connect(HOST, server.port, context: clientContext);
server.listen((serverEnd) {
clientEndFuture.then((clientEnd) {
+ var x5 = clientEnd.peerCertificate;
+ print(x5.subject);
+ print(x5.issuer);
+ print(x5.startValidity);
+ print(x5.endValidity);
clientEnd.close();
serverEnd.close();
server.close();
@@ -76,22 +91,32 @@ void testSimpleConnect(String certificate) {
});
}
-void testSimpleConnectFail(String certificate, bool cancelOnError) {
+void testSimpleConnectFail(SecurityContext serverContext,
+ SecurityContext clientContext,
+ bool cancelOnError) {
+ print('$serverContext $clientContext $cancelOnError');
asyncStart();
- SecureServerSocket.bind(HOST, 0, certificate).then((server) {
- var clientEndFuture = SecureSocket.connect(HOST, server.port)
+ SecureServerSocket.bind(HOST, 0, serverContext).then((server) {
+ var clientEndFuture =
+ SecureSocket.connect(HOST, server.port, context: clientContext)
.then((clientEnd) {
Expect.fail("No client connection expected.");
})
.catchError((error) {
- Expect.isTrue(error is HandshakeException ||
+ // TODO(whesse): When null context is supported, disallow
+ // the ArgumentError type here.
+ Expect.isTrue(error is ArgumentError ||
+ error is HandshakeException ||
error is SocketException);
});
server.listen((serverEnd) {
Expect.fail("No server connection expected.");
},
onError: (error) {
- Expect.isTrue(error is CertificateException);
+ // TODO(whesse): When null context is supported, disallow
+ // the ArgumentError type here.
+ Expect.isTrue(error is ArgumentError ||
+ error is HandshakeException);
clientEndFuture.then((_) {
if (!cancelOnError) server.close();
asyncEnd();
@@ -103,9 +128,10 @@ void testSimpleConnectFail(String certificate, bool cancelOnError) {
void testServerListenAfterConnect() {
asyncStart();
- SecureServerSocket.bind(HOST, 0, CERTIFICATE).then((server) {
+ SecureServerSocket.bind(HOST, 0, serverContext).then((server) {
Expect.isTrue(server.port > 0);
- var clientEndFuture = SecureSocket.connect(HOST, server.port);
+ var clientEndFuture =
+ SecureSocket.connect(HOST, server.port, context: clientContext);
new Timer(const Duration(milliseconds: 500), () {
server.listen((serverEnd) {
clientEndFuture.then((clientEnd) {
@@ -144,7 +170,7 @@ void testSimpleReadWrite() {
}
}
- SecureServerSocket.bind(HOST, 0, CERTIFICATE).then((server) {
+ SecureServerSocket.bind(HOST, 0, serverContext).then((server) {
server.listen((client) {
int bytesRead = 0;
int bytesWritten = 0;
@@ -166,7 +192,8 @@ void testSimpleReadWrite() {
});
});
- SecureSocket.connect(HOST, server.port).then((socket) {
+ SecureSocket.connect(HOST, server.port, context: clientContext)
+ .then((socket) {
int bytesRead = 0;
int bytesWritten = 0;
List<int> dataSent = createTestData();
@@ -189,10 +216,6 @@ void testSimpleReadWrite() {
main() {
asyncStart();
- String certificateDatabase = Platform.script.resolve('pkcert').toFilePath();
- SecureSocket.initialize(database: certificateDatabase,
- password: 'dartdart',
- useBuiltinRoots: false);
InternetAddress.lookup("localhost").then((hosts) {
HOST = hosts.first;
runTests();
@@ -203,12 +226,16 @@ main() {
runTests() {
testSimpleBind();
testInvalidBind();
- testSimpleConnect(CERTIFICATE);
- testSimpleConnect("CN=localhost");
- testSimpleConnectFail("not_a_nickname", false);
- testSimpleConnectFail("CN=notARealDistinguishedName", false);
- testSimpleConnectFail("not_a_nickname", true);
- testSimpleConnectFail("CN=notARealDistinguishedName", true);
+ testSimpleConnect();
+ for (var server in [serverContext, null]) {
+ for (var client in [clientContext, null]) {
+ for (bool cancelOnError in [true, false]) {
+ if (server == null || client == null) {
+ testSimpleConnectFail(server, client, cancelOnError);
+ }
+ }
+ }
+ }
testServerListenAfterConnect();
testSimpleReadWrite();
}
« no previous file with comments | « tests/standalone/io/secure_server_closing_test.dart ('k') | tests/standalone/io/secure_session_resume_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698