Ejemplo n.º 1
0
        /// <summary>
        /// Cleanup fiddler and browser instances.
        /// </summary>
        internal static void Cleanup()
        {
            FiddlerProxy.Cleanup(Constants.FiddlerPort);
            ((BrowserManager)ObjectResolver.Resolve <IBrowserManager>()).Dispose();

            TestSetupHelpers.CleanupProcess(Constants.ChromeDriver);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Browser proxy injects mandatory headers implementation.
        /// </summary>
        /// <param name="browserType">
        /// Browser type.
        /// </param>
        private void BrowserProxyInjectsMandatoryHeadersImplementation(BrowserType browserType)
        {
            /*
             * WARNING: Terminating this test while the proxy is running can lead to adverse side effects
             *          such as loss of web connectivity. Please allow the call to FiddlerProxy.Cleanup
             *          to complete.
             */

            ObjectResolver.RegisterType <IProcessManager, ProcessManager>();

            var browserInstances = new Dictionary <BrowserType, int> {
                { browserType, 1 }
            };

            try
            {
                FiddlerProxy.Initialize(new[] { "TestKey:TestValue" }, Constants.FiddlerPort);

                using (var manager = new BrowserManager(browserInstances))
                {
                    var browser = manager.AcquireBrowser(browserType);

                    browser.NavigateTo($"{Constants.VulnerabilitiesAddress}dumpheaders.aspx");
                    browser.WaitForPageLoad(10);

                    // Then the expected request header should be present in the page
                    browser.PageSource.ShouldContain("TestKey : TestValue");
                }

                // turn off the proxy and make sure the header is not injected
                FiddlerProxy.Initialize(new string[0], 0);

                using (var manager = new BrowserManager(browserInstances))
                {
                    var browser = manager.AcquireBrowser(browserType);

                    browser.NavigateTo($"{Constants.VulnerabilitiesAddress}dumpheaders.aspx");
                    browser.WaitForPageLoad(10);

                    // Then the expected request header should be present in the page
                    browser.PageSource.ShouldNotContain("TestKey : TestValue");
                }
            }
            finally
            {
                FiddlerProxy.Cleanup(Constants.FiddlerPort);
                FiddlerProxy.Cleanup(0);
            }
        }
Ejemplo n.º 3
0
        public void TestFiddlerProxySessionFingerprint()
        {
            ObjectResolver.RegisterType <IProcessManager, ProcessManager>();
            const BrowserType BrowserType = BrowserType.Chrome;

            var browserInstances = new Dictionary <BrowserType, int> {
                { BrowserType, 1 }
            };

            try
            {
                FiddlerProxy.Initialize(new string[0], Constants.FiddlerPort);
                using (var manager = new BrowserManager(browserInstances))
                {
                    var browser = manager.AcquireBrowser(BrowserType);

                    // expected headers for this browser process
                    FiddlerProxy.RegisterInstanceHeaders(
                        browser.ProcessId,
                        "My User Agent 1.0",
                        "TestKey: Process" + browser.ProcessId);

                    browser.NavigateTo($"{Constants.VulnerabilitiesAddress}dumpheaders.aspx");
                    browser.WaitForPageLoad(10);

                    // Then the expected request header should be present in the page
                    browser.PageSource.ShouldContain("User-Agent : My User Agent 1.0");
                    browser.PageSource.ShouldContain("TestKey : Process" + browser.ProcessId);

                    var fiddlerResponseSessionKey = Library.Constants.FiddlerResponseSessionKey.FormatIc(
                        browser.ProcessId,
                        browser.Url);

                    // validate the proxy session fingerprint
                    var fiddlerSession = FiddlerProxy.ResponseSession[fiddlerResponseSessionKey];
                    fiddlerSession.bHasResponse.ShouldBeTrue();
                    fiddlerSession.ResponseBody.Length.ShouldBeGreaterThan(0);
                    fiddlerSession.oResponse.headers.Count().ShouldBeGreaterThan(0);
                }
            }
            finally
            {
                FiddlerProxy.Cleanup(Constants.FiddlerPort);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Fiddler reporting the wrong
        /// browser process Id when more than one instance of Chrome was present. Here we test explicitly
        /// for that circumstance across all browsers.
        /// </summary>
        /// <param name="browserType">
        /// Browser type.
        /// </param>
        private void BrowserProxyInjectsPerRequestHeadersMultipleImplementation(
            BrowserType browserType)
        {
            /*
             * WARNING: Terminating this test while the proxy is running can lead to adverse side effects
             *          such as loss of web connectivity. Please allow the call to FiddlerProxy.Cleanup
             *          to complete.
             */

            ObjectResolver.RegisterType <IProcessManager, ProcessManager>();

            var browserInstances = new Dictionary <BrowserType, int> {
                { browserType, 3 }
            };

            try
            {
                FiddlerProxy.Initialize(new string[0], Constants.FiddlerPort);
                using (var manager = new BrowserManager(browserInstances))
                {
                    for (int i = 0; i < 3; i++)
                    {
                        var browser = manager.AcquireBrowser(browserType);

                        // expected headers for this browser process
                        FiddlerProxy.RegisterInstanceHeaders(
                            browser.ProcessId,
                            "My User Agent 1.0",
                            "TestKey: Process" + browser.ProcessId);

                        browser.NavigateTo($"{Constants.VulnerabilitiesAddress}dumpheaders.aspx");
                        browser.WaitForPageLoad(10);

                        // Then the expected request header should be present in the page
                        browser.PageSource.ShouldContain("User-Agent : My User Agent 1.0");
                        browser.PageSource.ShouldContain("TestKey : Process" + browser.ProcessId);
                    }
                }
            }
            finally
            {
                FiddlerProxy.Cleanup(Constants.FiddlerPort);
            }
        }
Ejemplo n.º 5
0
 public static void ClassCleanup()
 {
     FiddlerProxy.Cleanup(Constants.FiddlerPort);
 }
Ejemplo n.º 6
0
        public static void ClassInit(TestContext testContext)
        {
            FiddlerProxy.Cleanup(Constants.FiddlerPort);

            CreateFirewallRules();
        }