private string CloudFlareChallengeSolverSolve(string challengePageContent, Uri uri)
        {
            var    solution     = ChallengeSolver.Solve(challengePageContent, uri.Host);
            string clearanceUri = uri.Scheme + Uri.SchemeDelimiter + uri.Host + ":" + uri.Port + solution.ClearanceQuery;

            return(clearanceUri);
        }
        private static void ShowResults()
        {
            ChallengeSolver challengeSolver = new ChallengeSolver();

            Console.WriteLine($"First challenge result: {challengeSolver.Solve(1, 2020)}");
            Console.WriteLine($"Second challenge result: {challengeSolver.Solve(2, 2020)}");
        }
        public void SolveReturnsClearancePage()
        {
            var pageContent = JavaScriptData + FormData;

            var solution = ChallengeSolver.Solve(pageContent, Host);

            Assert.AreEqual(ClearancePage, solution.ClearancePage);
        }
        public void SolveReturnsPass()
        {
            var pageContent = JavaScriptData + FormData;

            var solution = ChallengeSolver.Solve(pageContent, Host);

            Assert.AreEqual(Pass, solution.Pass);
        }
        public void SolveReturnsVerificationCode()
        {
            var pageContent = JavaScriptData + FormData;

            var solution = ChallengeSolver.Solve(pageContent, Host);

            Assert.AreEqual(VerificationCode, solution.VerificationCode);
        }
        public void SolveReturnsValidAnswer()
        {
            var pageContent = JavaScriptData + FormData;

            var solution = ChallengeSolver.Solve(pageContent, Host);

            Assert.AreEqual(ValidAnswer, solution.Answer);
        }
        public void SolveReturnsPass()
        {
            var pageContent = IntegerChallengeScript + Form;

            var solution = ChallengeSolver.Solve(pageContent, Host);

            Assert.AreEqual(Pass, solution.Pass);
        }
Exemple #8
0
        public void SolverReturnsNullIfNoMatchFound()
        {
            var invalid = ChallengeSolver.SolveChallenge(new List <int> {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            });

            invalid.Should().Be(null, "The numbers are sequential, so no match should be found");
        }
Exemple #9
0
        public void SolveReturnsValidFloatAnswer()
        {
            var pageContent = FloatChallengeScript + Form;

            var solution = ChallengeSolver.Solve(pageContent, Host);

            Assert.AreEqual(ValidFloatAnswer, solution.Answer);
        }
Exemple #10
0
        public void SolverAbleToMatchAtRightBoundary()
        {
            // Check that the algorithm works for the right-most possible match (Index 7)
            var boundaryRight = ChallengeSolver.SolveChallenge(new List <int> {
                1, 1, 1, 1, 1, 1, 1, 0, 7
            });

            boundaryRight.Should().Be(7, "7 = 7 = 1+1+1+1+1+1+1");
        }
Exemple #11
0
        public void SolverAbleToMatchAtLeftBoundary()
        {
            // Check that the algorithm works for the left-most possible match (Index 1)
            var boundaryLeft = ChallengeSolver.SolveChallenge(new List <int> {
                7, 0, 1, 1, 1, 1, 1, 1, 1
            });

            boundaryLeft.Should().Be(1, "7 = 7 = 1+1+1+1+1+1+1");
        }
        public void SolveReturnsValidClearanceQuery()
        {
            var pageContent = JavaScriptData + FormData;

            var solution = ChallengeSolver.Solve(pageContent, Host);

            Assert.AreEqual(
                $"{ClearancePage}?jschl_vc={VerificationCode}&pass={Pass}&jschl_answer={ValidAnswer}",
                solution.ClearanceQuery);
        }
        public void SolveReturnsValidClearanceQuery()
        {
            var pageContent = IntegerChallengeScript + Form;

            var solution = ChallengeSolver.Solve(pageContent, Host);

            Assert.AreEqual(
                $"{ClearancePage}?s={Uri.EscapeDataString(S)}&jschl_vc={VerificationCode}&pass={Pass}&jschl_answer={ValidIntegerAnswer}",
                solution.ClearanceQuery);
        }
        public void SolveReturnsValidIntegerAnswer()
        {
            var pageContent = IntegerChallengeScript + Form;

            var solution = ChallengeSolver.Solve(pageContent, Host);

            Assert.AreEqual(ValidIntegerAnswer, solution.Answer);


            var solutionCustomPort = ChallengeSolver.Solve(pageContent, Host, CustomPort);

            Assert.AreEqual(_validIntegerAnswerCustomPort, solutionCustomPort.Answer);
        }
Exemple #15
0
        public void SolveChallenge()
        {
            _driver.Url = "http:/localhost:3000";

            // Click the RENDER THE CHALLENGE button
            _driver.FindElement(By.CssSelector("button[data-test-id=\"render-challenge\"]")).Click();

            // Wait for the challenge to exist
            _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
            _driver.FindElement(By.Id("home"));
            _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(0);

            // Solve each Row
            for (var row = 1; row < 4; row++)
            {
                // Build the array from the column
                var arr = new List <int>();
                for (var column = 0; column < 9; column++)
                {
                    arr.Add(Convert.ToInt32(_driver.FindElement(By.CssSelector($"td[data-test-id=\"array-item-{row}-{column}\"]")).Text));
                }
                // Solve the puzzle
                var answer = ChallengeSolver.SolveChallenge(arr);

                // Verify that we got a positive result
                answer.Should().NotBeNull("The center value should be found");

                // Fill in the answer
                _driver.FindElement(By.CssSelector($"input[data-test-id=\"submit-{row}\"]")).SendKeys(answer.ToString());
            }

            // Sign the test
            _driver.FindElement(By.CssSelector("input[data-test-id=\"submit-4\"]")).SendKeys("Clive Galway");

            // Submit
            // Use XPath to find a span with the text "Submit Answers", and click it
            _driver.FindElement(By.XPath("//span[contains(text(), 'Submit Answers')]")).Click();
            // This could probably be improved by selecting the first found button ancestor of this node
        }
        /// <summary>
        /// Solve the CloudFlare challenge
        /// </summary>
        /// <param name="response">Response from the site</param>
        /// <param name="html">HTML text of response</param>
        /// <returns></returns>
        private async Task SolverCloudFlare(HttpWebResponse response, string html)
        {
            var scheme       = response.ResponseUri.Scheme;
            var host         = response.ResponseUri.Host;
            var port         = response.ResponseUri.Port;
            var solution     = ChallengeSolver.Solve(html, host);
            var clearanceUri = $"{scheme}://{host}:{port}{solution.ClearanceQuery}";

            // Save the cookies from response
            SetTheCookie(response.Headers["Set-Cookie"]);

            await Task.Delay(5000);

            // Make the request to specific URL which should be solved
            var request = CreateRequest(clearanceUri);

            request.CookieContainer = null;

            // This one should return the ClearanceCookieName. Use them for new request
            using (HttpWebResponse clearanceResponse = (HttpWebResponse)request.GetResponse())
            {
                SetTheCookie(clearanceResponse.Headers["Set-Cookie"]);
            }
        }