Commit c062dee3752fee8e6ca1e656cff0de8615c9dfa7

Authored by Evandro Junior
1 parent 5ce42844

New tests

lib/noosfero/api/helpers.rb
@@ -217,7 +217,7 @@ @@ -217,7 +217,7 @@
217 raise ArgumentError, "Environment api_captcha_settings private_key not defined" if d[:private_key].nil? 217 raise ArgumentError, "Environment api_captcha_settings private_key not defined" if d[:private_key].nil?
218 raise ArgumentError, "Environment api_captcha_settings version not defined" unless d[:version] == 1 || d[:version] == 2 218 raise ArgumentError, "Environment api_captcha_settings version not defined" unless d[:version] == 1 || d[:version] == 2
219 raise ArgumentError, "Environment api_captcha_settings verify_uri not defined" if d[:verify_uri].nil? 219 raise ArgumentError, "Environment api_captcha_settings verify_uri not defined" if d[:verify_uri].nil?
220 - if d[:version] == 1 220 + if d[:version] == 1
221 return verify_recaptcha_v1(remote_ip, d[:private_key], d[:verify_uri], params[:recaptcha_challenge_field], params[:recaptcha_response_field]) 221 return verify_recaptcha_v1(remote_ip, d[:private_key], d[:verify_uri], params[:recaptcha_challenge_field], params[:recaptcha_response_field])
222 end 222 end
223 if d[:version] == 2 223 if d[:version] == 2
test/unit/api/helpers_test.rb
@@ -161,6 +161,20 @@ class APIHelpersTest < ActiveSupport::TestCase @@ -161,6 +161,20 @@ class APIHelpersTest < ActiveSupport::TestCase
161 assert_nil make_conditions_with_parameter[:type] 161 assert_nil make_conditions_with_parameter[:type]
162 end 162 end
163 163
  164 + should 'do not test captcha when there are no settings' do
  165 + environment = Environment.new
  166 + assert test_captcha("127.0.0.1", {}, environment)
  167 + end
  168 +
  169 + should 'do not test captcha when captcha is disabled on settings' do
  170 + environment = Environment.new
  171 + environment.api_captcha_settings = {
  172 + enabled: false,
  173 + }
  174 + assert test_captcha("127.0.0.1", {}, environment)
  175 + end
  176 +
  177 +
164 should 'fail display recaptcha v1' do 178 should 'fail display recaptcha v1' do
165 environment = Environment.new 179 environment = Environment.new
166 environment.api_captcha_settings = { 180 environment.api_captcha_settings = {