Ejemplo n.º 1
0
        public async Task WhenUsingProxyAutoConfigWithoutCredentials_ThenRequestsAreSentToProxy()
        {
            using (var proxy = new InProcessHttpProxy())
            {
                proxy.AddStaticFile(
                    "/proxy.pac",
                    "function FindProxyForURL(url, host) " +
                    "{ return \"PROXY localhost:" + proxy.Port + "; DIRECT\";}");

                var adapter = new HttpProxyAdapter();
                adapter.ActivateProxyAutoConfigSettings(
                    new Uri($"http://localhost:{proxy.Port}/proxy.pac"),
                    null);

                var proxiedUrl = WebRequest.DefaultWebProxy.GetProxy(SampleHttpsUrl);

                Assert.AreEqual(
                    new Uri($"http://localhost:{proxy.Port}/"),
                    proxiedUrl,
                    "This might fail on systems that have a proxy PAC configured by GPO");

                await SendWebRequest(SampleHttpsUrl);

                Assert.AreEqual(1, proxy.ConnectionTargets.Distinct().Count());
                CollectionAssert.Contains(proxy.ConnectionTargets, SampleHttpsUrl.Host);
            }
        }
Ejemplo n.º 2
0
        public async Task WhenUsingCustomProxySettingsWithoutCredentials_ThenRequestsAreSentToProxy()
        {
            using (var proxy = new InProcessHttpProxy())
            {
                var adapter = new HttpProxyAdapter();
                adapter.ActivateCustomProxySettings(
                    new Uri($"http://localhost:{proxy.Port}"),
                    ProxyBypassList,
                    null);

                await SendWebRequest(SampleHttpsUrl);

                Assert.AreEqual(1, proxy.ConnectionTargets.Distinct().Count());
                CollectionAssert.Contains(proxy.ConnectionTargets, SampleHttpsUrl.Host);
            }
        }