Skip to content
This repository
Browse code

Merge remote-tracking branch 'nemurimasu/ssl-config'

Conflicts:
	README.rdoc
  • Loading branch information...
commit 8222d6c444e5b08a53009f9d9050f6682e04563a 2 parents 4fe7e7c + de66a5b
Jason L Perry authored
2  README.rdoc
Source Rendered
@@ -90,7 +90,7 @@ And, add +verify_recaptcha+ logic to each form action that you've protected.
90 90
91 91 Some of the options available:
92 92
93   -<tt>:ssl</tt>:: Uses https for captcha widget, even if hosted on http (default +false+)
  93 +<tt>:ssl</tt>:: Uses secure http for captcha widget (default +false+, but can be changed by setting +config.use_ssl_by_default+)
94 94 <tt>:noscript</tt>:: Include <noscript> content (default +true+)
95 95 <tt>:display</tt>:: Takes a hash containing the +theme+ and +tabindex+ options per the API. (default +nil+), options: 'red', 'white', 'blackglass', 'clean', 'custom'
96 96 <tt>:ajax</tt>:: Render the dynamic AJAX captcha per the API. (default +false+)
1  lib/recaptcha.rb
@@ -6,6 +6,7 @@ module Recaptcha
6 6 RECAPTCHA_API_SERVER_URL = '//www.google.com/recaptcha/api'
7 7 RECAPTCHA_API_SECURE_SERVER_URL = 'https://www.google.com/recaptcha/api'
8 8 RECAPTCHA_VERIFY_URL = 'http://www.google.com/recaptcha/api/verify'
  9 + USE_SSL_BY_DEFAULT = false
9 10
10 11 HANDLE_TIMEOUTS_GRACEFULLY = true
11 12 SKIP_VERIFY_ENV = ['test', 'cucumber']
7 lib/recaptcha/configuration.rb
@@ -35,7 +35,8 @@ class Configuration
35 35 :private_key,
36 36 :public_key,
37 37 :proxy,
38   - :handle_timeouts_gracefully
  38 + :handle_timeouts_gracefully,
  39 + :use_ssl_by_default
39 40
40 41 def initialize #:nodoc:
41 42 @nonssl_api_server_url = RECAPTCHA_API_SERVER_URL
@@ -43,12 +44,14 @@ def initialize #:nodoc:
43 44 @verify_url = RECAPTCHA_VERIFY_URL
44 45 @skip_verify_env = SKIP_VERIFY_ENV
45 46 @handle_timeouts_gracefully = HANDLE_TIMEOUTS_GRACEFULLY
  47 + @use_ssl_by_default = USE_SSL_BY_DEFAULT
46 48
47 49 @private_key = ENV['RECAPTCHA_PRIVATE_KEY']
48 50 @public_key = ENV['RECAPTCHA_PUBLIC_KEY']
49 51 end
50 52
51   - def api_server_url(ssl = false) #:nodoc:
  53 + def api_server_url(ssl = nil) #:nodoc:
  54 + ssl = use_ssl_by_default if ssl.nil?
52 55 ssl ? ssl_api_server_url : nonssl_api_server_url
53 56 end
54 57 end
10 test/recaptcha_test.rb
@@ -22,6 +22,16 @@ def test_recaptcha_tags
22 22 assert_match /"\/\/www.google.com\/recaptcha\/api\/challenge/, recaptcha_tags
23 23 end
24 24
  25 + def test_ssl_by_default
  26 + Recaptcha.configuration.use_ssl_by_default = true
  27 + assert_match /https:\/\/www.google.com\/recaptcha\/api\/challenge/, recaptcha_tags
  28 + end
  29 +
  30 + def test_ssl_by_default_without_ssl
  31 + Recaptcha.configuration.use_ssl_by_default = true
  32 + assert_match /http:\/\/www.google.com\/recaptcha\/api\/challenge/, recaptcha_tags(:ssl => false)
  33 + end
  34 +
25 35 def test_recaptcha_tags_with_ssl
26 36 assert_match /https:\/\/www.google.com\/recaptcha\/api\/challenge/, recaptcha_tags(:ssl => true)
27 37 end

0 comments on commit 8222d6c

Please sign in to comment.
Something went wrong with that request. Please try again.