OLD | NEW |
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:crypto/crypto.dart"; | 5 import "package:crypto/crypto.dart"; |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 import "package:path/path.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'; |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 ProxyServer proxyServer = new ProxyServer(ipV6: ipV6); | 283 ProxyServer proxyServer = new ProxyServer(ipV6: ipV6); |
284 return proxyServer.start(); | 284 return proxyServer.start(); |
285 } | 285 } |
286 | 286 |
287 | 287 |
288 int testProxyIPV6DoneCount = 0; | 288 int testProxyIPV6DoneCount = 0; |
289 void testProxyIPV6() { | 289 void testProxyIPV6() { |
290 setupProxyServer(ipV6: true).then((proxyServer) { | 290 setupProxyServer(ipV6: true).then((proxyServer) { |
291 setupServer(1, directRequestPaths: ["/4"]).then((server) { | 291 setupServer(1, directRequestPaths: ["/4"]).then((server) { |
292 setupServer(1, directRequestPaths: ["/4"], secure: true).then((secureServer) { | 292 setupServer(1, directRequestPaths: ["/4"], secure: true).then((secureServer) { |
293 HttpClient client = new HttpClient(); | 293 HttpClient client = new HttpClient(context: clientContext); |
294 | 294 |
295 List<String> proxy = ["PROXY [::1]:${proxyServer.port}"]; | 295 List<String> proxy = ["PROXY [::1]:${proxyServer.port}"]; |
296 client.findProxy = (Uri uri) { | 296 client.findProxy = (Uri uri) { |
297 // Pick the proxy configuration based on the request path. | 297 // Pick the proxy configuration based on the request path. |
298 int index = int.parse(uri.path.substring(1)); | 298 int index = int.parse(uri.path.substring(1)); |
299 return proxy[index]; | 299 return proxy[index]; |
300 }; | 300 }; |
301 | 301 |
302 for (int i = 0; i < proxy.length; i++) { | 302 for (int i = 0; i < proxy.length; i++) { |
303 test(bool secure) { | 303 test(bool secure) { |
(...skipping 29 matching lines...) Expand all Loading... |
333 }); | 333 }); |
334 }); | 334 }); |
335 } | 335 } |
336 | 336 |
337 | 337 |
338 int testProxyFromEnviromentDoneCount = 0; | 338 int testProxyFromEnviromentDoneCount = 0; |
339 void testProxyFromEnviroment() { | 339 void testProxyFromEnviroment() { |
340 setupProxyServer().then((proxyServer) { | 340 setupProxyServer().then((proxyServer) { |
341 setupServer(1).then((server) { | 341 setupServer(1).then((server) { |
342 setupServer(1, secure: true).then((secureServer) { | 342 setupServer(1, secure: true).then((secureServer) { |
343 HttpClient client = new HttpClient(); | 343 HttpClient client = new HttpClient(context: clientContext); |
344 | 344 |
345 client.findProxy = (Uri uri) { | 345 client.findProxy = (Uri uri) { |
346 return HttpClient.findProxyFromEnvironment( | 346 return HttpClient.findProxyFromEnvironment( |
347 uri, | 347 uri, |
348 environment: {"http_proxy": "localhost:${proxyServer.port}", | 348 environment: {"http_proxy": "localhost:${proxyServer.port}", |
349 "https_proxy": "localhost:${proxyServer.port}"}); | 349 "https_proxy": "localhost:${proxyServer.port}"}); |
350 }; | 350 }; |
351 | 351 |
352 const int loopCount = 5; | 352 const int loopCount = 5; |
353 for (int i = 0; i < loopCount; i++) { | 353 for (int i = 0; i < loopCount; i++) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 | 387 |
388 | 388 |
389 int testProxyAuthenticateCount = 0; | 389 int testProxyAuthenticateCount = 0; |
390 Future testProxyAuthenticate(bool useDigestAuthentication) { | 390 Future testProxyAuthenticate(bool useDigestAuthentication) { |
391 testProxyAuthenticateCount = 0; | 391 testProxyAuthenticateCount = 0; |
392 var completer = new Completer(); | 392 var completer = new Completer(); |
393 | 393 |
394 setupProxyServer().then((proxyServer) { | 394 setupProxyServer().then((proxyServer) { |
395 setupServer(1).then((server) { | 395 setupServer(1).then((server) { |
396 setupServer(1, secure: true).then((secureServer) { | 396 setupServer(1, secure: true).then((secureServer) { |
397 HttpClient client = new HttpClient(); | 397 HttpClient client = new HttpClient(context: clientContext); |
398 | 398 |
399 Completer step1 = new Completer(); | 399 Completer step1 = new Completer(); |
400 Completer step2 = new Completer(); | 400 Completer step2 = new Completer(); |
401 | 401 |
402 if (useDigestAuthentication) { | 402 if (useDigestAuthentication) { |
403 proxyServer.useDigestAuthentication("dart", "password"); | 403 proxyServer.useDigestAuthentication("dart", "password"); |
404 } else { | 404 } else { |
405 proxyServer.useBasicAuthentication("dart", "password"); | 405 proxyServer.useBasicAuthentication("dart", "password"); |
406 } | 406 } |
407 | 407 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 }); | 536 }); |
537 }); | 537 }); |
538 }); | 538 }); |
539 | 539 |
540 return completer.future; | 540 return completer.future; |
541 } | 541 } |
542 | 542 |
543 int testRealProxyDoneCount = 0; | 543 int testRealProxyDoneCount = 0; |
544 void testRealProxy() { | 544 void testRealProxy() { |
545 setupServer(1).then((server) { | 545 setupServer(1).then((server) { |
546 HttpClient client = new HttpClient(); | 546 HttpClient client = new HttpClient(context: clientContext); |
547 client.addProxyCredentials( | 547 client.addProxyCredentials( |
548 "localhost", | 548 "localhost", |
549 8080, | 549 8080, |
550 "test", | 550 "test", |
551 new HttpClientBasicCredentials("dart", "password")); | 551 new HttpClientBasicCredentials("dart", "password")); |
552 | 552 |
553 List<String> proxy = | 553 List<String> proxy = |
554 ["PROXY localhost:8080", | 554 ["PROXY localhost:8080", |
555 "PROXY localhost:8080; PROXY hede.hule.hest:8080", | 555 "PROXY localhost:8080; PROXY hede.hule.hest:8080", |
556 "PROXY hede.hule.hest:8080; PROXY localhost:8080", | 556 "PROXY hede.hule.hest:8080; PROXY localhost:8080", |
(...skipping 22 matching lines...) Expand all Loading... |
579 } | 579 } |
580 }); | 580 }); |
581 }); | 581 }); |
582 } | 582 } |
583 }); | 583 }); |
584 } | 584 } |
585 | 585 |
586 int testRealProxyAuthDoneCount = 0; | 586 int testRealProxyAuthDoneCount = 0; |
587 void testRealProxyAuth() { | 587 void testRealProxyAuth() { |
588 setupServer(1).then((server) { | 588 setupServer(1).then((server) { |
589 HttpClient client = new HttpClient(); | 589 HttpClient client = new HttpClient(context: clientContext); |
590 | 590 |
591 List<String> proxy = | 591 List<String> proxy = |
592 ["PROXY dart:password@localhost:8080", | 592 ["PROXY dart:password@localhost:8080", |
593 "PROXY dart:password@localhost:8080; PROXY hede.hule.hest:8080", | 593 "PROXY dart:password@localhost:8080; PROXY hede.hule.hest:8080", |
594 "PROXY hede.hule.hest:8080; PROXY dart:password@localhost:8080", | 594 "PROXY hede.hule.hest:8080; PROXY dart:password@localhost:8080", |
595 "PROXY dart:password@localhost:8080; DIRECT"]; | 595 "PROXY dart:password@localhost:8080; DIRECT"]; |
596 | 596 |
597 client.findProxy = (Uri uri) { | 597 client.findProxy = (Uri uri) { |
598 // Pick the proxy configuration based on the request path. | 598 // Pick the proxy configuration based on the request path. |
599 int index = int.parse(uri.path.substring(1)); | 599 int index = int.parse(uri.path.substring(1)); |
(...skipping 27 matching lines...) Expand all Loading... |
627 // The two invocations use the same global variable for state - | 627 // The two invocations use the same global variable for state - |
628 // run one after the other. | 628 // run one after the other. |
629 testProxyAuthenticate(false) | 629 testProxyAuthenticate(false) |
630 .then((_) => testProxyAuthenticate(true)); | 630 .then((_) => testProxyAuthenticate(true)); |
631 | 631 |
632 // This test is not normally run. It can be used for locally testing | 632 // This test is not normally run. It can be used for locally testing |
633 // with a real proxy server (e.g. Apache). | 633 // with a real proxy server (e.g. Apache). |
634 // testRealProxy(); | 634 // testRealProxy(); |
635 // testRealProxyAuth(); | 635 // testRealProxyAuth(); |
636 } | 636 } |
OLD | NEW |