Skip to content

Commit

Permalink
Merge remote-tracking branch 'nemurimasu/ssl-config'
Browse files Browse the repository at this point in the history
Conflicts:
	README.rdoc
  • Loading branch information
Jason L Perry committed Feb 22, 2013
2 parents 4fe7e7c + de66a5b commit 8222d6c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.rdoc
Expand Up @@ -90,7 +90,7 @@ And, add +verify_recaptcha+ logic to each form action that you've protected.

Some of the options available:

<tt>:ssl</tt>:: Uses https for captcha widget, even if hosted on http (default +false+)
<tt>:ssl</tt>:: Uses secure http for captcha widget (default +false+, but can be changed by setting +config.use_ssl_by_default+)
<tt>:noscript</tt>:: Include <noscript> content (default +true+)
<tt>:display</tt>:: Takes a hash containing the +theme+ and +tabindex+ options per the API. (default +nil+), options: 'red', 'white', 'blackglass', 'clean', 'custom'
<tt>:ajax</tt>:: Render the dynamic AJAX captcha per the API. (default +false+)
Expand Down
1 change: 1 addition & 0 deletions lib/recaptcha.rb
Expand Up @@ -6,6 +6,7 @@ module Recaptcha
RECAPTCHA_API_SERVER_URL = '//www.google.com/recaptcha/api'
RECAPTCHA_API_SECURE_SERVER_URL = 'https://www.google.com/recaptcha/api'
RECAPTCHA_VERIFY_URL = 'http://www.google.com/recaptcha/api/verify'
USE_SSL_BY_DEFAULT = false

HANDLE_TIMEOUTS_GRACEFULLY = true
SKIP_VERIFY_ENV = ['test', 'cucumber']
Expand Down
7 changes: 5 additions & 2 deletions lib/recaptcha/configuration.rb
Expand Up @@ -35,20 +35,23 @@ class Configuration
:private_key,
:public_key,
:proxy,
:handle_timeouts_gracefully
:handle_timeouts_gracefully,
:use_ssl_by_default

def initialize #:nodoc:
@nonssl_api_server_url = RECAPTCHA_API_SERVER_URL
@ssl_api_server_url = RECAPTCHA_API_SECURE_SERVER_URL
@verify_url = RECAPTCHA_VERIFY_URL
@skip_verify_env = SKIP_VERIFY_ENV
@handle_timeouts_gracefully = HANDLE_TIMEOUTS_GRACEFULLY
@use_ssl_by_default = USE_SSL_BY_DEFAULT

@private_key = ENV['RECAPTCHA_PRIVATE_KEY']
@public_key = ENV['RECAPTCHA_PUBLIC_KEY']
end

def api_server_url(ssl = false) #:nodoc:
def api_server_url(ssl = nil) #:nodoc:
ssl = use_ssl_by_default if ssl.nil?
ssl ? ssl_api_server_url : nonssl_api_server_url
end
end
Expand Down
10 changes: 10 additions & 0 deletions test/recaptcha_test.rb
Expand Up @@ -22,6 +22,16 @@ def test_recaptcha_tags
assert_match /"\/\/www.google.com\/recaptcha\/api\/challenge/, recaptcha_tags
end

def test_ssl_by_default
Recaptcha.configuration.use_ssl_by_default = true
assert_match /https:\/\/www.google.com\/recaptcha\/api\/challenge/, recaptcha_tags
end

def test_ssl_by_default_without_ssl
Recaptcha.configuration.use_ssl_by_default = true
assert_match /http:\/\/www.google.com\/recaptcha\/api\/challenge/, recaptcha_tags(:ssl => false)
end

def test_recaptcha_tags_with_ssl
assert_match /https:\/\/www.google.com\/recaptcha\/api\/challenge/, recaptcha_tags(:ssl => true)
end
Expand Down

0 comments on commit 8222d6c

Please sign in to comment.