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

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

Issue 1889273002: fix analyzer failures (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 import "package:convert/convert.dart";
5 import "package:crypto/crypto.dart"; 6 import "package:crypto/crypto.dart";
6 import "package:expect/expect.dart"; 7 import "package:expect/expect.dart";
7 import "package:path/path.dart";
8 import "dart:async"; 8 import "dart:async";
9 import "dart:io"; 9 import "dart:io";
10 import 'dart:convert'; 10 import 'dart:convert';
11 11
12 String localFile(path) => Platform.script.resolve(path).toFilePath(); 12 String localFile(path) => Platform.script.resolve(path).toFilePath();
13 13
14 SecurityContext serverContext = new SecurityContext() 14 SecurityContext serverContext = new SecurityContext()
15 ..useCertificateChain(localFile('certificates/server_chain.pem')) 15 ..useCertificateChain(localFile('certificates/server_chain.pem'))
16 ..usePrivateKey(localFile('certificates/server_key.pem'), 16 ..usePrivateKey(localFile('certificates/server_key.pem'),
17 password: 'dartdart'); 17 password: 'dartdart');
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 var nonce = "12345678"; // No need for random nonce in test. 102 var nonce = "12345678"; // No need for random nonce in test.
103 103
104 ProxyServer({this.ipV6: false}) : client = new HttpClient(); 104 ProxyServer({this.ipV6: false}) : client = new HttpClient();
105 105
106 void useBasicAuthentication(String username, String password) { 106 void useBasicAuthentication(String username, String password) {
107 this.username = username; 107 this.username = username;
108 this.password = password; 108 this.password = password;
109 authScheme = "Basic"; 109 authScheme = "Basic";
110 } 110 }
111 111
112 void useDigestAuthentication(String username, String password) {
113 this.username = username;
114 this.password = password;
115 authScheme = "Digest";
116
117 // Calculate ha1.
118 var hasher = new MD5();
119 hasher.add("${username}:${realm}:${password}".codeUnits);
120 ha1 = CryptoUtils.bytesToHex(hasher.close());
121 }
122
123 basicAuthenticationRequired(request) { 112 basicAuthenticationRequired(request) {
124 request.fold(null, (x, y) {}).then((_) { 113 request.fold(null, (x, y) {}).then((_) {
125 var response = request.response; 114 var response = request.response;
126 response.headers.set(HttpHeaders.PROXY_AUTHENTICATE, 115 response.headers.set(HttpHeaders.PROXY_AUTHENTICATE,
127 "Basic, realm=$realm"); 116 "Basic, realm=$realm");
128 response.statusCode = HttpStatus.PROXY_AUTHENTICATION_REQUIRED; 117 response.statusCode = HttpStatus.PROXY_AUTHENTICATION_REQUIRED;
129 response.close(); 118 response.close();
130 }); 119 });
131 } 120 }
132 121
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 Expect.isNotNull(cnonce); 188 Expect.isNotNull(cnonce);
200 Expect.isNotNull(nc); 189 Expect.isNotNull(nc);
201 Expect.isFalse(ncs.contains(nc)); 190 Expect.isFalse(ncs.contains(nc));
202 ncs.add(nc); 191 ncs.add(nc);
203 } else { 192 } else {
204 Expect.isNull(cnonce); 193 Expect.isNull(cnonce);
205 Expect.isNull(nc); 194 Expect.isNull(nc);
206 } 195 }
207 Expect.isNotNull(header.parameters["response"]); 196 Expect.isNotNull(header.parameters["response"]);
208 197
209 var hasher = new MD5(); 198 var digest = md5.convert("${request.method}:${uri}".codeUnits);
210 hasher.add("${request.method}:${uri}".codeUnits); 199 var ha2 = hex.encode(digest.bytes);
211 var ha2 = CryptoUtils.bytesToHex(hasher.close());
212 200
213 var x;
214 hasher = new MD5();
215 if (qop == null || qop == "" || qop == "none") { 201 if (qop == null || qop == "" || qop == "none") {
216 hasher.add("$ha1:${nonce}:$ha2".codeUnits); 202 digest = md5.convert("$ha1:${nonce}:$ha2".codeUnits);
217 } else { 203 } else {
218 hasher.add( 204 digest = md5.convert(
219 "$ha1:${nonce}:${nc}:${cnonce}:${qop}:$ha2".codeUnits); 205 "$ha1:${nonce}:${nc}:${cnonce}:${qop}:$ha2".codeUnits);
220 } 206 }
221 Expect.equals(CryptoUtils.bytesToHex(hasher.close()), 207 Expect.equals(hex.encode(digest.bytes),
222 header.parameters["response"]); 208 header.parameters["response"]);
223 209
224 // Add a bogus Proxy-Authentication-Info for testing. 210 // Add a bogus Proxy-Authentication-Info for testing.
225 var info = 'rspauth="77180d1ab3d6c9de084766977790f482", ' 211 var info = 'rspauth="77180d1ab3d6c9de084766977790f482", '
226 'cnonce="8f971178", ' 212 'cnonce="8f971178", '
227 'nc=000002c74, ' 213 'nc=000002c74, '
228 'qop=auth'; 214 'qop=auth';
229 request.response.headers.set("Proxy-Authentication-Info", info); 215 request.response.headers.set("Proxy-Authentication-Info", info);
230 } 216 }
231 } 217 }
232 } 218 }
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 }); 455 });
470 }); 456 });
471 } 457 }
472 458
473 main() { 459 main() {
474 testInvalidProxy(); 460 testInvalidProxy();
475 testDirectProxy(); 461 testDirectProxy();
476 testProxy(); 462 testProxy();
477 testProxyChain(); 463 testProxyChain();
478 } 464 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698