diff --git a/recaptcha_test.go b/recaptcha_test.go index 03d07f5..472c01e 100644 --- a/recaptcha_test.go +++ b/recaptcha_test.go @@ -430,145 +430,3 @@ func (s *ReCaptchaSuite) TestV2VerifyWithV3IgnoreOptions(c *C) { err := captcha.VerifyWithOptions("mycode", VerifyOption{Action: "homepage", Threshold: 0.5}) c.Assert(err, IsNil) } - -/* -func (*mockSuccessClient) PostForm(url string, formValues url.Values) (resp *http.Response, err error) { - resp = &http.Response{ - Status: "200 OK", - StatusCode: 200, - } - resp.Body = ioutil.NopCloser(strings.NewReader(` - { - "success": true, - "challenge_ts": "2018-03-06T03:41:29+00:00", - "hostname": "test.com" - } - `)) - return -} - -func (*mockSuccessClientHostnameOption) PostForm(url string, formValues url.Values) (resp *http.Response, err error) { - resp = &http.Response{ - Status: "200 OK", - StatusCode: 200, - } - resp.Body = ioutil.NopCloser(strings.NewReader(` - { - "success": true, - "challenge_ts": "2018-03-06T03:41:29+00:00", - "hostname": "valid.com" - } - `)) - return -} - -func (*mockFailedClientHostnameOption) PostForm(url string, formValues url.Values) (resp *http.Response, err error) { - resp = &http.Response{ - Status: "200 OK", - StatusCode: 200, - } - resp.Body = ioutil.NopCloser(strings.NewReader(` - { - "success": true, - "challenge_ts": "2018-03-06T03:41:29+00:00", - "hostname": "invalid.com" - } - `)) - return -} - -func (*mockFailedClient) PostForm(url string, formValues url.Values) (resp *http.Response, err error) { - resp = &http.Response{ - Status: "200 OK", - StatusCode: 200, - } - resp.Body = ioutil.NopCloser(strings.NewReader(` - { - "success": false, - "challenge_ts": "2018-03-06T03:41:29+00:00", - "hostname": "test.com", - "error-codes": ["bad-request"] - } - `)) - return -} - -// bad json body - -func (s *ReCaptchaSuite) TestNewReCAPTCHA(c *C) { - captcha, err := NewReCAPTCHA("my secret", V2, 10) - c.Assert(err, IsNil) - c.Check(captcha.Secret, Equals, "my secret") - c.Check(captcha.Version, Equals, V2) - c.Check(captcha.Timeout, Equals, (uint)(10)) - c.Check(captcha.ReCAPTCHALink, Equals, reCAPTCHALink) - - captcha, err = NewReCAPTCHA("", V2, 10) - c.Assert(err, NotNil) -} - -func (s *ReCaptchaSuite) TestVerifyV2WithoutClientIP(c *C) { - captcha := ReCAPTCHA{ - client: &mockSuccessClient{}, - Version: V2, - } - - success, err := captcha.Verify("mycode") - c.Assert(err, IsNil) - c.Check(success, Equals, true) - - captcha.client = &mockFailedClient{} - success, err = captcha.Verify("mycode") - c.Assert(err, IsNil) - c.Check(success, Equals, false) -} - -func (s *ReCaptchaSuite) TestV3VerifyWithCHostnameOption(c *C) { - captcha := ReCAPTCHA{ - client: &mockSuccessClientHostnameOption{}, - Version: V3, - } - - success, err := captcha.VerifyWithOptions("mycode", VerifyOption{Hostname: "valid.com"}) - c.Assert(err, IsNil) - c.Check(success, Equals, true) - - captcha.client = &mockFailedClientHostnameOption{} - success, err = captcha.VerifyWithOptions("mycode", VerifyOption{Hostname: "valid.com"}) - c.Assert(err, NotNil) - c.Check(success, Equals, false) -} - -/* -func (s *ReCaptchaSuite) TestVerifyWithClientIP(c *C) { - captcha := ReCAPTCHA{ - client: &mockSuccessClient{}, - } - - success, err := captcha.Verify("mycode", "127.0.0.1") - c.Assert(err, IsNil) - c.Check(success, Equals, true) - - captcha.client = &mockFailedClient{} - success, err = captcha.Verify("mycode", "127.0.0.1") - c.Assert(err, IsNil) - c.Check(success, Equals, false) -} - -func (s *ReCaptchaSuite) TestConfirm(c *C) { - // check that an invalid json body errors - captcha := ReCAPTCHA{ - client: &mockInvalidClient{}, - } - body := reCHAPTCHARequest{Secret: "", Response: ""} - - success, err := captcha.confirm(body) - c.Assert(err, NotNil) - c.Check(success, Equals, false) - - captcha.client = &mockUnavailableClient{} - success, err = captcha.confirm(body) - c.Assert(err, NotNil) - c.Check(success, Equals, false) -} -*/