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

Side by Side Diff: tests/standalone/io/secure_server_client_certificate_test.dart

Issue 2771453003: Format all tests. (Closed)
Patch Set: Format files Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 // OtherResources=certificates/server_chain.pem 5 // OtherResources=certificates/server_chain.pem
6 // OtherResources=certificates/server_key.pem 6 // OtherResources=certificates/server_key.pem
7 // OtherResources=certificates/trusted_certs.pem 7 // OtherResources=certificates/trusted_certs.pem
8 // OtherResources=certificates/client_authority.pem 8 // OtherResources=certificates/client_authority.pem
9 // OtherResources=certificates/client1.pem 9 // OtherResources=certificates/client1.pem
10 // OtherResources=certificates/client1_key.pem 10 // OtherResources=certificates/client1_key.pem
11 // OtherResources=certificates/server_chain.p12 11 // OtherResources=certificates/server_chain.p12
12 // OtherResources=certificates/server_key.p12 12 // OtherResources=certificates/server_key.p12
13 // OtherResources=certificates/trusted_certs.p12 13 // OtherResources=certificates/trusted_certs.p12
14 // OtherResources=certificates/client_authority.p12 14 // OtherResources=certificates/client_authority.p12
15 // OtherResources=certificates/client1.p12 15 // OtherResources=certificates/client1.p12
16 // OtherResources=certificates/client1_key.p12 16 // OtherResources=certificates/client1_key.p12
17 17
18 import "dart:async"; 18 import "dart:async";
19 import "dart:io"; 19 import "dart:io";
20 20
21 import "package:async_helper/async_helper.dart"; 21 import "package:async_helper/async_helper.dart";
22 import "package:expect/expect.dart"; 22 import "package:expect/expect.dart";
23 23
24 InternetAddress HOST; 24 InternetAddress HOST;
25 25
26 String localFile(path) => Platform.script.resolve(path).toFilePath(); 26 String localFile(path) => Platform.script.resolve(path).toFilePath();
27 27
28 SecurityContext serverContext(String certType, String password) => 28 SecurityContext serverContext(String certType, String password) =>
29 new SecurityContext() 29 new SecurityContext()
30 ..useCertificateChain(localFile( 30 ..useCertificateChain(localFile('certificates/server_chain.$certType'),
31 'certificates/server_chain.$certType'), password: password) 31 password: password)
32 ..usePrivateKey(localFile( 32 ..usePrivateKey(localFile('certificates/server_key.$certType'),
33 'certificates/server_key.$certType'), password: password) 33 password: password)
34 ..setTrustedCertificates(localFile( 34 ..setTrustedCertificates(
35 'certificates/client_authority.$certType'), password: password) 35 localFile('certificates/client_authority.$certType'),
36 ..setClientAuthorities(localFile( 36 password: password)
37 'certificates/client_authority.$certType'), password: password); 37 ..setClientAuthorities(
38 localFile('certificates/client_authority.$certType'),
39 password: password);
38 40
39 SecurityContext clientCertContext(String certType, String password) => 41 SecurityContext clientCertContext(String certType, String password) =>
40 new SecurityContext() 42 new SecurityContext()
41 ..setTrustedCertificates(localFile( 43 ..setTrustedCertificates(
42 'certificates/trusted_certs.$certType'), password: password) 44 localFile('certificates/trusted_certs.$certType'),
43 ..useCertificateChain(localFile( 45 password: password)
44 'certificates/client1.$certType'), password: password) 46 ..useCertificateChain(localFile('certificates/client1.$certType'),
45 ..usePrivateKey(localFile( 47 password: password)
46 'certificates/client1_key.$certType'), password: password); 48 ..usePrivateKey(localFile('certificates/client1_key.$certType'),
49 password: password);
47 50
48 SecurityContext clientNoCertContext(String certType, String password) => 51 SecurityContext clientNoCertContext(String certType, String password) =>
49 new SecurityContext() 52 new SecurityContext()
50 ..setTrustedCertificates(localFile( 53 ..setTrustedCertificates(
51 'certificates/trusted_certs.$certType'), password: password); 54 localFile('certificates/trusted_certs.$certType'),
55 password: password);
52 56
53 Future testClientCertificate( 57 Future testClientCertificate(
54 {bool required, bool sendCert, String certType, String password}) async { 58 {bool required, bool sendCert, String certType, String password}) async {
55 var server = await SecureServerSocket.bind(HOST, 0, 59 var server = await SecureServerSocket.bind(
56 serverContext(certType, password), 60 HOST, 0, serverContext(certType, password),
57 requestClientCertificate: true, 61 requestClientCertificate: true, requireClientCertificate: required);
58 requireClientCertificate: required); 62 var clientContext = sendCert
59 var clientContext = sendCert ? 63 ? clientCertContext(certType, password)
60 clientCertContext(certType, password) : 64 : clientNoCertContext(certType, password);
61 clientNoCertContext(certType, password);
62 var clientEndFuture = 65 var clientEndFuture =
63 SecureSocket.connect(HOST, server.port, context: clientContext); 66 SecureSocket.connect(HOST, server.port, context: clientContext);
64 if (required && !sendCert) { 67 if (required && !sendCert) {
65 try { 68 try {
66 await server.first; 69 await server.first;
67 } catch (e) { 70 } catch (e) {
68 try { 71 try {
69 await clientEndFuture; 72 await clientEndFuture;
70 } catch (e) { 73 } catch (e) {
71 return; 74 return;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 await testClientCertificate( 110 await testClientCertificate(
108 required: false, sendCert: true, certType: 'p12', password: 'dartdart'); 111 required: false, sendCert: true, certType: 'p12', password: 'dartdart');
109 await testClientCertificate( 112 await testClientCertificate(
110 required: true, sendCert: true, certType: 'p12', password: 'dartdart'); 113 required: true, sendCert: true, certType: 'p12', password: 'dartdart');
111 await testClientCertificate( 114 await testClientCertificate(
112 required: false, sendCert: false, certType: 'p12', password: 'dartdart'); 115 required: false, sendCert: false, certType: 'p12', password: 'dartdart');
113 await testClientCertificate( 116 await testClientCertificate(
114 required: true, sendCert: false, certType: 'p12', password: 'dartdart'); 117 required: true, sendCert: false, certType: 'p12', password: 'dartdart');
115 asyncEnd(); 118 asyncEnd();
116 } 119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698