Beispiel #1
0
        public void ValidateResponseReturnsFalseOnError()
        {
            HttpContextBase context = GetContext();

            Assert.False(ReCaptcha.HandleValidateResponse(context, "false\nincorrect-captcha-sol"));
            Assert.Equal("incorrect-captcha-sol", ReCaptcha.GetLastError(context));
        }
Beispiel #2
0
        public void ValidateResponseReturnsFalseOnEmptyReCaptchaResponse()
        {
            HttpContextBase context = GetContext();

            Assert.False(ReCaptcha.HandleValidateResponse(context, ""));
            Assert.Equal(String.Empty, ReCaptcha.GetLastError(context));
        }
Beispiel #3
0
        public void ValidateResponseReturnsTrueOnSuccess()
        {
            HttpContextBase context = GetContext();

            Assert.True(ReCaptcha.HandleValidateResponse(context, "true\nsuccess"));
            Assert.Equal(String.Empty, ReCaptcha.GetLastError(context));
        }
Beispiel #4
0
        public void RenderUsesLastError()
        {
            HttpContextBase context = GetContext();

            ReCaptcha.HandleValidateResponse(context, "false\nincorrect-captcha-sol");
            var html = ReCaptcha.GetHtml(context, "PUBLIC_KEY");

            AssertEqualsIgnoreLineBreaks(
                @"<script src=""http://api.recaptcha.net/challenge?k=PUBLIC_KEY&amp;error=incorrect-captcha-sol"" type=""text/javascript""></script>" +
                @"<noscript>" +
                @"<iframe frameborder=""0"" height=""300"" src=""http://api.recaptcha.net/noscript?k=PUBLIC_KEY"" width=""500""></iframe><br></br>" +
                @"<textarea cols=""40"" name=""recaptcha_challenge_field"" rows=""3""></textarea>" +
                @"<input name=""recaptcha_response_field"" type=""hidden"" value=""manual_challenge""></input>" +
                @"</noscript>",
                html);
        }
Beispiel #5
0
        public void RenderUsesLastError()
        {
            HttpContextBase context = GetContext();

            ReCaptcha.HandleValidateResponse(context, "false\nincorrect-captcha-sol");
            var html = ReCaptcha.GetHtml(context, "PUBLIC_KEY");

            UnitTestHelper.AssertEqualsIgnoreWhitespace(
                @"<script src=""http://www.google.com/recaptcha/api/challenge?k=PUBLIC_KEY&amp;error=incorrect-captcha-sol"" type=""text/javascript""></script>" +
                @"<noscript>" +
                @"<iframe frameborder=""0"" height=""300px"" src=""http://www.google.com/recaptcha/api/noscript?k=PUBLIC_KEY"" width=""500px""></iframe><br/><br/>" +
                @"<textarea cols=""40"" name=""recaptcha_challenge_field"" rows=""3""></textarea>" +
                @"<input name=""recaptcha_response_field"" type=""hidden"" value=""manual_challenge""/>" +
                @"</noscript>",
                html.ToString());
            XhtmlAssert.Validate1_0(html, addRoot: true);
        }