Exemplo n.º 1
0
        private async Task VerifyCaptcha(CancellationToken cancellationToken)
        {
            var captchaService = new ReCaptchaService();

            var clientToken = this.GetClientToken();
            var ipAddress   = this.GetClientIPAddress();

            var result = await captchaService.Verify3Async(clientToken, ipAddress, CaptchaSettings.SecretKey, cancellationToken);

            if (result == null)
            {
                SetStatus("ERROR: Verification result is null.", Color.Red);
                return;
            }

            if (!result.IsSuccess ||
                result.Action != PageAction ||
                result.Score < 0.5)
            {
                SetStatus("ERROR: Something went wrong. I think you're a bot!", Color.Red);
                return;
            }

            var now = DateTime.Now;

            SetStatus("Cool. Validation passed. Time is: " + now + ". Your message is: " + this.message.Text, Color.Lime);
        }
        public async Task can_make_process_bad_request()
        {
            var service = new ReCaptchaService();

            service.EnableFiddlerDebugProxy("http://localhost.:8888");

            var response = await service.Verify3Async("ffff", "127.0.0.1", "bbbb");

            response.IsSuccess.Should().BeFalse();
        }
Exemplo n.º 3
0
        public async Task can_parse_errors()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.Expect(HttpMethod.Post, Constants.VerifyUrl)
            .Respond("application/json", ErrorJson)
            .WithExactFormData("response=aaa&remoteip=bbb&secret=ccc");

            var captcha = new ReCaptchaService(client: mockHttp.ToHttpClient());

            var response = await captcha.Verify3Async("aaa", "bbb", "ccc");

            response.IsSuccess.Should().BeFalse();
            response.ErrorCodes.Should().BeEquivalentTo("invalid-input-response", "invalid-input-secret");
        }
Exemplo n.º 4
0
        public async Task can_parse_good_response()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.Expect(HttpMethod.Post, Constants.VerifyUrl)
            .Respond("application/json", GoodJson)
            .WithExactFormData("response=aaa&remoteip=bbb&secret=ccc");

            var captcha = new ReCaptchaService(client: mockHttp.ToHttpClient());

            var response = await captcha.Verify3Async("aaa", "bbb", "ccc");

            response.IsSuccess.Should().BeTrue();
            response.ErrorCodes.Should().BeNull();
            response.ChallengeTs.Should().Be("2019-04-30T02:37:21Z");
            response.HostName.Should().Be("www.bitarmory.com");
            response.Score.Should().Be(0.9f);
            response.Action.Should().Be("purchase");
        }