recaptcha 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +42 -19
- data/Rakefile +2 -0
- data/VERSION +1 -1
- data/lib/recaptcha.rb +21 -4
- data/lib/recaptcha/client_helper.rb +7 -7
- data/lib/recaptcha/configuration.rb +52 -0
- data/lib/recaptcha/verify.rb +7 -6
- data/recaptcha.gemspec +28 -22
- data/test/recaptcha_test.rb +8 -6
- data/test/verify_recaptcha_test.rb +17 -18
- metadata +44 -9
data/README.rdoc
CHANGED
@@ -7,19 +7,25 @@ Info:: http://ambethia.com/recaptcha
|
|
7
7
|
Git:: http://github.com/ambethia/recaptcha/tree/master
|
8
8
|
Bugs:: http://github.com/ambethia/recaptcha/issues
|
9
9
|
|
10
|
-
This plugin adds helpers for the {reCAPTCHA API}[http://recaptcha.net]. In your
|
11
|
-
the +recaptcha_tags+ method to embed the needed javascript,
|
12
|
-
with +verify_recaptcha+.
|
10
|
+
This plugin adds helpers for the {reCAPTCHA API}[http://recaptcha.net]. In your
|
11
|
+
views you can use the +recaptcha_tags+ method to embed the needed javascript,
|
12
|
+
and you can validate in your controllers with +verify_recaptcha+.
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
Beforehand you need to configure Recaptcha with your custom private and public
|
15
|
+
key. You may find detailed examples below. Exceptions will be raised if you
|
16
|
+
call these methods and the keys can't be found.
|
17
|
+
|
18
|
+
== About this fork
|
19
|
+
|
20
|
+
This fork tries to introduces a more convenient way to configure recaptcha's
|
21
|
+
settings. The API will be inspired by {Thoughtbot's
|
22
|
+
Hoptoad}[http://robots.thoughtbot.com/post/344833329/mygem-configure-block].
|
17
23
|
|
18
24
|
== Rails Installation
|
19
25
|
|
20
26
|
reCAPTCHA for Rails can be installed as a gem:
|
21
27
|
|
22
|
-
config.gem "
|
28
|
+
config.gem "recaptcha", :lib => "recaptcha/rails"
|
23
29
|
|
24
30
|
Or, as a standard rails plugin:
|
25
31
|
|
@@ -35,27 +41,43 @@ Initial Merb compatability funded by ALM Labs.
|
|
35
41
|
|
36
42
|
== Setting up your API Keys
|
37
43
|
|
38
|
-
There are
|
39
|
-
a pair.
|
44
|
+
There are multiple ways to setup your reCAPTCHA API key once you
|
45
|
+
{obtain}[http://recaptcha.net/whyrecaptcha.html] a pair.
|
40
46
|
|
41
|
-
|
47
|
+
=== Recaptcha.configure
|
42
48
|
|
43
|
-
|
49
|
+
You may use the block style configuration. The following code could be placed
|
50
|
+
into a +config/initializers/recaptcha.rb+ when used in a Rails project.
|
44
51
|
|
45
|
-
|
52
|
+
Recaptcha.configure do |config|
|
53
|
+
config.public_key = '6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy'
|
54
|
+
config.private_key = '6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx'
|
55
|
+
end
|
56
|
+
|
57
|
+
This way, you may also set additional options to fit recaptcha into your
|
58
|
+
deployment environment.
|
46
59
|
|
60
|
+
=== Shell environment
|
47
61
|
|
48
|
-
Or,
|
49
|
-
|
50
|
-
application:
|
62
|
+
Or, you can keep your keys out of your code base by exporting the following
|
63
|
+
environment variables. You might do this in the .profile/rc, or equivalent for
|
64
|
+
the user running your application:
|
51
65
|
|
52
66
|
export RECAPTCHA_PUBLIC_KEY = '6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy'
|
53
67
|
export RECAPTCHA_PRIVATE_KEY = '6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx'
|
54
68
|
|
55
|
-
|
69
|
+
=== Per call
|
70
|
+
|
71
|
+
You can also pass in your keys as options at runtime, for example:
|
72
|
+
|
73
|
+
recaptcha_tags :public_key => '6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy'
|
74
|
+
|
75
|
+
and later,
|
76
|
+
|
77
|
+
verify_recaptcha :private_key => '6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx'
|
56
78
|
|
57
|
-
|
58
|
-
|
79
|
+
This option might be useful, if the same code base is used for multiple
|
80
|
+
reCAPTCHA setups.
|
59
81
|
|
60
82
|
== +recaptcha_tags+
|
61
83
|
|
@@ -81,12 +103,13 @@ error will be added to the object for you to use.
|
|
81
103
|
Some of the options available:
|
82
104
|
|
83
105
|
<tt>:model</tt>:: Model to set errors
|
106
|
+
<tt>:attribute</tt>:: Model attribute to receive errors (default :base)
|
84
107
|
<tt>:message</tt>:: Custom error message
|
85
108
|
<tt>:private_key</tt>:: Your private API key, takes precedence over the ENV variable (default +nil+).
|
86
109
|
<tt>:timeout</tt>:: The number of seconds to wait for reCAPTCHA servers before give up. (default +3+)
|
87
110
|
|
88
111
|
respond_to do |format|
|
89
|
-
if verify_recaptcha(:model => @post, :message =>
|
112
|
+
if verify_recaptcha(:model => @post, :message => "Oh! It's error with reCAPTCHA!") && @post.save
|
90
113
|
# ...
|
91
114
|
else
|
92
115
|
# ...
|
data/Rakefile
CHANGED
@@ -10,6 +10,8 @@ begin
|
|
10
10
|
gem.authors = ["Jason L. Perry"]
|
11
11
|
gem.email = "jasper@ambethia.com"
|
12
12
|
gem.files.reject! { |fn| fn.include? ".gitignore" }
|
13
|
+
gem.add_development_dependency "mocha"
|
14
|
+
gem.add_development_dependency "activesupport"
|
13
15
|
end
|
14
16
|
Jeweler::GemcutterTasks.new
|
15
17
|
rescue LoadError
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/recaptcha.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'recaptcha/configuration'
|
1
2
|
require 'recaptcha/client_helper'
|
2
3
|
require 'recaptcha/verify'
|
3
4
|
|
@@ -12,12 +13,28 @@ module Recaptcha
|
|
12
13
|
end
|
13
14
|
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
RECAPTCHA_API_SERVER_URL = 'http://www.google.com/recaptcha/api'
|
17
|
+
RECAPTCHA_API_SECURE_SERVER_URL = 'https://www.google.com/recaptcha/api'
|
18
|
+
RECAPTCHA_VERIFY_URL = 'http://www.google.com/recaptcha/api'
|
18
19
|
|
19
20
|
SKIP_VERIFY_ENV = ['test', 'cucumber']
|
20
21
|
|
22
|
+
# Gives access to the current Configuration.
|
23
|
+
def self.configuration
|
24
|
+
@configuration ||= Configuration.new
|
25
|
+
end
|
26
|
+
|
27
|
+
# Allows easy setting of multiple configuration options. See Configuration
|
28
|
+
# for all available options.
|
29
|
+
#--
|
30
|
+
# The temp assignment is only used to get a nicer rdoc. Feel free to remove
|
31
|
+
# this hack.
|
32
|
+
#++
|
33
|
+
def self.configure
|
34
|
+
config = configuration
|
35
|
+
yield(config)
|
36
|
+
end
|
37
|
+
|
21
38
|
class RecaptchaError < StandardError
|
22
39
|
end
|
23
|
-
end
|
40
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module Recaptcha
|
2
2
|
module ClientHelper
|
3
3
|
# Your public API can be specified in the +options+ hash or preferably
|
4
|
-
# the
|
4
|
+
# using the Configuration.
|
5
5
|
def recaptcha_tags(options = {})
|
6
6
|
# Default options
|
7
|
-
key = options[:public_key] ||=
|
7
|
+
key = options[:public_key] ||= Recaptcha.configuration.public_key
|
8
8
|
raise RecaptchaError, "No public key specified." unless key
|
9
9
|
error = options[:error] ||= (defined? flash ? flash[:recaptcha_error] : "")
|
10
|
-
uri = options[:ssl]
|
10
|
+
uri = Recaptcha.configuration.api_server_url(options[:ssl])
|
11
11
|
html = ""
|
12
12
|
if options[:display]
|
13
13
|
html << %{<script type="text/javascript">\n}
|
@@ -22,21 +22,21 @@ module Recaptcha
|
|
22
22
|
html << %{</script>\n}
|
23
23
|
else
|
24
24
|
html << %{<script type="text/javascript" src="#{uri}/challenge?k=#{key}}
|
25
|
-
html << %{#{error ? "&error=#{CGI::escape(error)}" : ""}"></script>\n}
|
25
|
+
html << %{#{error ? "&error=#{CGI::escape(error)}" : ""}"></script>\n}
|
26
26
|
unless options[:noscript] == false
|
27
27
|
html << %{<noscript>\n }
|
28
28
|
html << %{<iframe src="#{uri}/noscript?k=#{key}" }
|
29
29
|
html << %{height="#{options[:iframe_height] ||= 300}" }
|
30
30
|
html << %{width="#{options[:iframe_width] ||= 500}" }
|
31
|
-
html << %{
|
31
|
+
html << %{style="border:none;"></iframe><br/>\n }
|
32
32
|
html << %{<textarea name="recaptcha_challenge_field" }
|
33
33
|
html << %{rows="#{options[:textarea_rows] ||= 3}" }
|
34
34
|
html << %{cols="#{options[:textarea_cols] ||= 40}"></textarea>\n }
|
35
|
-
html << %{<input type="hidden" name="recaptcha_response_field" value="manual_challenge"
|
35
|
+
html << %{<input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>}
|
36
36
|
html << %{</noscript>\n}
|
37
37
|
end
|
38
38
|
end
|
39
|
-
return html
|
39
|
+
return html.html_safe
|
40
40
|
end # recaptcha_tags
|
41
41
|
end # ClientHelper
|
42
42
|
end # Recaptcha
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Recaptcha
|
2
|
+
# This class enables detailed configuration of the recaptcha services.
|
3
|
+
#
|
4
|
+
# By calling
|
5
|
+
#
|
6
|
+
# Recaptcha.configuration # => instance of Recaptcha::Configuration
|
7
|
+
#
|
8
|
+
# or
|
9
|
+
# Recaptcha.configure do |config|
|
10
|
+
# config # => instance of Recaptcha::Configuration
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# you are able to perform configuration updates.
|
14
|
+
#
|
15
|
+
# Your are able to customize all attributes listed below. All values have
|
16
|
+
# sensitive default and will very likely not need to be changed.
|
17
|
+
#
|
18
|
+
# Please note that the public and private key for the reCAPTCHA API Access
|
19
|
+
# have no useful default value. The keys may be set via the Shell enviroment
|
20
|
+
# or using this configuration. Settings within this configuration always take
|
21
|
+
# precedence.
|
22
|
+
#
|
23
|
+
# Setting the keys with this Configuration
|
24
|
+
#
|
25
|
+
# Recaptcha.configure do |config|
|
26
|
+
# config.public_key = '6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy'
|
27
|
+
# config.private_key = '6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx'
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
class Configuration
|
31
|
+
attr_accessor :nonssl_api_server_url,
|
32
|
+
:ssl_api_server_url,
|
33
|
+
:verify_url,
|
34
|
+
:skip_verify_env,
|
35
|
+
:private_key,
|
36
|
+
:public_key
|
37
|
+
|
38
|
+
def initialize #:nodoc:
|
39
|
+
@nonssl_api_server_url = RECAPTCHA_API_SERVER_URL
|
40
|
+
@ssl_api_server_url = RECAPTCHA_API_SECURE_SERVER_URL
|
41
|
+
@verify_url = RECAPTCHA_VERIFY_URL
|
42
|
+
@skip_verify_env = SKIP_VERIFY_ENV
|
43
|
+
|
44
|
+
@private_key = ENV['RECAPTCHA_PRIVATE_KEY']
|
45
|
+
@public_key = ENV['RECAPTCHA_PUBLIC_KEY']
|
46
|
+
end
|
47
|
+
|
48
|
+
def api_server_url(ssl = false) #:nodoc:
|
49
|
+
ssl ? ssl_api_server_url : nonssl_api_server_url
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/recaptcha/verify.rb
CHANGED
@@ -1,22 +1,23 @@
|
|
1
1
|
module Recaptcha
|
2
2
|
module Verify
|
3
3
|
# Your private API can be specified in the +options+ hash or preferably
|
4
|
-
# the
|
4
|
+
# using the Configuration.
|
5
5
|
def verify_recaptcha(options = {})
|
6
6
|
if !options.is_a? Hash
|
7
7
|
options = {:model => options}
|
8
8
|
end
|
9
9
|
|
10
10
|
env = options[:env] || ENV['RAILS_ENV']
|
11
|
-
return true if
|
11
|
+
return true if Recaptcha.configuration.skip_verify_env.include? env
|
12
12
|
model = options[:model]
|
13
|
-
|
13
|
+
attribute = options[:attribute] || :base
|
14
|
+
private_key = options[:private_key] || Recaptcha.configuration.private_key
|
14
15
|
raise RecaptchaError, "No private key specified." unless private_key
|
15
16
|
|
16
17
|
begin
|
17
18
|
recaptcha = nil
|
18
19
|
Timeout::timeout(options[:timeout] || 3) do
|
19
|
-
recaptcha = Net::HTTP.post_form URI.parse(
|
20
|
+
recaptcha = Net::HTTP.post_form URI.parse(Recaptcha.configuration.verify_url), {
|
20
21
|
"privatekey" => private_key,
|
21
22
|
"remoteip" => request.remote_ip,
|
22
23
|
"challenge" => params[:recaptcha_challenge_field],
|
@@ -28,7 +29,7 @@ module Recaptcha
|
|
28
29
|
flash[:recaptcha_error] = error
|
29
30
|
if model
|
30
31
|
model.valid?
|
31
|
-
model.errors.add
|
32
|
+
model.errors.add attribute, options[:message] || "Word verification response is incorrect, please try again."
|
32
33
|
end
|
33
34
|
return false
|
34
35
|
else
|
@@ -39,7 +40,7 @@ module Recaptcha
|
|
39
40
|
flash[:recaptcha_error] = "recaptcha-not-reachable"
|
40
41
|
if model
|
41
42
|
model.valid?
|
42
|
-
model.errors.add
|
43
|
+
model.errors.add attribute, options[:message] || "Oops, we failed to validate your word verification response. Please try again."
|
43
44
|
end
|
44
45
|
return false
|
45
46
|
rescue Exception => e
|
data/recaptcha.gemspec
CHANGED
@@ -1,56 +1,62 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{recaptcha}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jason L. Perry"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-12-16}
|
13
13
|
s.description = %q{This plugin adds helpers for the reCAPTCHA API }
|
14
14
|
s.email = %q{jasper@ambethia.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
|
17
|
+
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
"CHANGELOG",
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"init.rb",
|
26
|
+
"lib/recaptcha.rb",
|
27
|
+
"lib/recaptcha/client_helper.rb",
|
28
|
+
"lib/recaptcha/configuration.rb",
|
29
|
+
"lib/recaptcha/merb.rb",
|
30
|
+
"lib/recaptcha/rails.rb",
|
31
|
+
"lib/recaptcha/verify.rb",
|
32
|
+
"recaptcha.gemspec",
|
33
|
+
"tasks/recaptcha_tasks.rake",
|
34
|
+
"test/recaptcha_test.rb",
|
35
|
+
"test/verify_recaptcha_test.rb"
|
35
36
|
]
|
36
37
|
s.homepage = %q{http://ambethia.com/recaptcha}
|
37
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
38
38
|
s.require_paths = ["lib"]
|
39
|
-
s.rubygems_version = %q{1.3.
|
39
|
+
s.rubygems_version = %q{1.3.7}
|
40
40
|
s.summary = %q{Helpers for the reCAPTCHA API}
|
41
41
|
s.test_files = [
|
42
42
|
"test/recaptcha_test.rb",
|
43
|
-
|
43
|
+
"test/verify_recaptcha_test.rb"
|
44
44
|
]
|
45
45
|
|
46
46
|
if s.respond_to? :specification_version then
|
47
47
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
48
|
s.specification_version = 3
|
49
49
|
|
50
|
-
if Gem::Version.new(Gem::
|
50
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
52
|
+
s.add_development_dependency(%q<activesupport>, [">= 0"])
|
51
53
|
else
|
54
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
55
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
52
56
|
end
|
53
57
|
else
|
58
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
59
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
54
60
|
end
|
55
61
|
end
|
56
62
|
|
data/test/recaptcha_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'cgi'
|
3
|
-
require File.dirname(__FILE__) + '/../lib/recaptcha'
|
3
|
+
require File.dirname(File.expand_path(__FILE__)) + '/../lib/recaptcha'
|
4
4
|
|
5
5
|
class RecaptchaClientHelperTest < Test::Unit::TestCase
|
6
6
|
include Recaptcha
|
@@ -11,17 +11,19 @@ class RecaptchaClientHelperTest < Test::Unit::TestCase
|
|
11
11
|
|
12
12
|
def setup
|
13
13
|
@session = {}
|
14
|
-
|
15
|
-
|
14
|
+
Recaptcha.configure do |config|
|
15
|
+
config.public_key = '0000000000000000000000000000000000000000'
|
16
|
+
config.private_key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
|
17
|
+
end
|
16
18
|
end
|
17
19
|
|
18
20
|
def test_recaptcha_tags
|
19
21
|
# Might as well match something...
|
20
|
-
assert_match /http:\/\/
|
22
|
+
assert_match /http:\/\/www.google.com\/recaptcha\/api\/challenge/, recaptcha_tags
|
21
23
|
end
|
22
24
|
|
23
25
|
def test_recaptcha_tags_with_ssl
|
24
|
-
assert_match /https:\/\/
|
26
|
+
assert_match /https:\/\/www.google.com\/recaptcha\/api\/challenge/, recaptcha_tags(:ssl => true)
|
25
27
|
end
|
26
28
|
|
27
29
|
def test_recaptcha_tags_without_noscript
|
@@ -30,7 +32,7 @@ class RecaptchaClientHelperTest < Test::Unit::TestCase
|
|
30
32
|
|
31
33
|
def test_should_raise_exception_without_public_key
|
32
34
|
assert_raise RecaptchaError do
|
33
|
-
|
35
|
+
Recaptcha.configuration.public_key = nil
|
34
36
|
recaptcha_tags
|
35
37
|
end
|
36
38
|
end
|
@@ -1,30 +1,29 @@
|
|
1
1
|
require 'test/unit'
|
2
|
-
require '
|
3
|
-
require '
|
2
|
+
require 'active_support/core_ext/string'
|
3
|
+
require 'rubygems'
|
4
4
|
require 'mocha'
|
5
5
|
require 'net/http'
|
6
|
-
require File.dirname(__FILE__) + '/../lib/recaptcha'
|
6
|
+
require File.dirname(File.expand_path(__FILE__)) + '/../lib/recaptcha'
|
7
7
|
|
8
8
|
class RecaptchaVerifyTest < Test::Unit::TestCase
|
9
9
|
def setup
|
10
|
-
|
11
|
-
ENV['RECAPTCHA_PRIVATE_KEY'] = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
|
10
|
+
Recaptcha.configuration.private_key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
|
12
11
|
@controller = TestController.new
|
13
12
|
@controller.request = stub(:remote_ip => "1.1.1.1")
|
14
13
|
@controller.params = {:recaptcha_challenge_field => "challenge", :recaptcha_response_field => "response"}
|
15
14
|
|
16
15
|
@expected_post_data = {}
|
17
|
-
@expected_post_data["privatekey"] =
|
16
|
+
@expected_post_data["privatekey"] = Recaptcha.configuration.private_key
|
18
17
|
@expected_post_data["remoteip"] = @controller.request.remote_ip
|
19
18
|
@expected_post_data["challenge"] = "challenge"
|
20
19
|
@expected_post_data["response"] = "response"
|
21
20
|
|
22
|
-
@expected_uri = URI.parse(
|
21
|
+
@expected_uri = URI.parse(Recaptcha.configuration.verify_url)
|
23
22
|
end
|
24
23
|
|
25
24
|
def test_should_raise_exception_without_private_key
|
26
25
|
assert_raise Recaptcha::RecaptchaError do
|
27
|
-
|
26
|
+
Recaptcha.configuration.private_key = nil
|
28
27
|
@controller.verify_recaptcha
|
29
28
|
end
|
30
29
|
end
|
@@ -33,52 +32,52 @@ class RecaptchaVerifyTest < Test::Unit::TestCase
|
|
33
32
|
expect_http_post(response_with_body("false\ninvalid-site-private-key"))
|
34
33
|
|
35
34
|
assert !@controller.verify_recaptcha
|
36
|
-
assert_equal "invalid-site-private-key", @controller.
|
35
|
+
assert_equal "invalid-site-private-key", @controller.flash[:recaptcha_error]
|
37
36
|
end
|
38
37
|
|
39
38
|
def test_returns_true_on_success
|
40
|
-
@controller.
|
39
|
+
@controller.flash[:recaptcha_error] = "previous error that should be cleared"
|
41
40
|
expect_http_post(response_with_body("true\n"))
|
42
41
|
|
43
42
|
assert @controller.verify_recaptcha
|
44
|
-
assert_nil @controller.
|
43
|
+
assert_nil @controller.flash[:recaptcha_error]
|
45
44
|
end
|
46
45
|
|
47
46
|
def test_errors_should_be_added_to_model
|
48
47
|
expect_http_post(response_with_body("false\nbad-news"))
|
49
48
|
|
50
49
|
errors = mock
|
51
|
-
errors.expects(:add).with(:base, "
|
50
|
+
errors.expects(:add).with(:base, "Word verification response is incorrect, please try again.")
|
52
51
|
model = mock(:valid? => false, :errors => errors)
|
53
52
|
|
54
53
|
assert !@controller.verify_recaptcha(:model => model)
|
55
|
-
assert_equal "bad-news", @controller.
|
54
|
+
assert_equal "bad-news", @controller.flash[:recaptcha_error]
|
56
55
|
end
|
57
56
|
|
58
57
|
def test_returns_true_on_success_with_optional_key
|
59
|
-
@controller.
|
58
|
+
@controller.flash[:recaptcha_error] = "previous error that should be cleared"
|
60
59
|
# reset private key
|
61
60
|
@expected_post_data["privatekey"] = 'ADIFFERENTPRIVATEKEYXXXXXXXXXXXXXX'
|
62
61
|
expect_http_post(response_with_body("true\n"))
|
63
62
|
|
64
63
|
assert @controller.verify_recaptcha(:private_key => 'ADIFFERENTPRIVATEKEYXXXXXXXXXXXXXX')
|
65
|
-
assert_nil @controller.
|
64
|
+
assert_nil @controller.flash[:recaptcha_error]
|
66
65
|
end
|
67
66
|
|
68
67
|
def test_timeout
|
69
68
|
expect_http_post(Timeout::Error, :exception => true)
|
70
69
|
assert !@controller.verify_recaptcha()
|
71
|
-
assert_equal "recaptcha-not-reachable", @controller.
|
70
|
+
assert_equal "recaptcha-not-reachable", @controller.flash[:recaptcha_error]
|
72
71
|
end
|
73
72
|
|
74
73
|
private
|
75
74
|
|
76
75
|
class TestController
|
77
76
|
include Recaptcha::Verify
|
78
|
-
attr_accessor :request, :params, :
|
77
|
+
attr_accessor :request, :params, :flash
|
79
78
|
|
80
79
|
def initialize
|
81
|
-
@
|
80
|
+
@flash = {}
|
82
81
|
end
|
83
82
|
end
|
84
83
|
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: recaptcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Jason L. Perry
|
@@ -9,10 +14,35 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2010-12-16 00:00:00 -05:00
|
13
18
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: mocha
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :development
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: activesupport
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :development
|
45
|
+
version_requirements: *id002
|
16
46
|
description: "This plugin adds helpers for the reCAPTCHA API "
|
17
47
|
email: jasper@ambethia.com
|
18
48
|
executables: []
|
@@ -31,6 +61,7 @@ files:
|
|
31
61
|
- init.rb
|
32
62
|
- lib/recaptcha.rb
|
33
63
|
- lib/recaptcha/client_helper.rb
|
64
|
+
- lib/recaptcha/configuration.rb
|
34
65
|
- lib/recaptcha/merb.rb
|
35
66
|
- lib/recaptcha/rails.rb
|
36
67
|
- lib/recaptcha/verify.rb
|
@@ -43,26 +74,30 @@ homepage: http://ambethia.com/recaptcha
|
|
43
74
|
licenses: []
|
44
75
|
|
45
76
|
post_install_message:
|
46
|
-
rdoc_options:
|
47
|
-
|
77
|
+
rdoc_options: []
|
78
|
+
|
48
79
|
require_paths:
|
49
80
|
- lib
|
50
81
|
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
51
83
|
requirements:
|
52
84
|
- - ">="
|
53
85
|
- !ruby/object:Gem::Version
|
86
|
+
segments:
|
87
|
+
- 0
|
54
88
|
version: "0"
|
55
|
-
version:
|
56
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
57
91
|
requirements:
|
58
92
|
- - ">="
|
59
93
|
- !ruby/object:Gem::Version
|
94
|
+
segments:
|
95
|
+
- 0
|
60
96
|
version: "0"
|
61
|
-
version:
|
62
97
|
requirements: []
|
63
98
|
|
64
99
|
rubyforge_project:
|
65
|
-
rubygems_version: 1.3.
|
100
|
+
rubygems_version: 1.3.7
|
66
101
|
signing_key:
|
67
102
|
specification_version: 3
|
68
103
|
summary: Helpers for the reCAPTCHA API
|