rack-recaptcha 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/README.md +17 -1
- data/lib/rack/recaptcha.rb +6 -1
- data/lib/rack/recaptcha/helpers.rb +2 -1
- data/rack-recaptcha.gemspec +1 -1
- data/test/helpers_test.rb +15 -11
- data/test/recaptcha_test.rb +28 -17
- metadata +5 -13
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -43,11 +43,16 @@ Now configure your app to use the middleware. This might be different across eac
|
|
43
43
|
config.middleware.use Rack::Recaptcha, :public_key => 'KEY', :private_key => 'SECRET'
|
44
44
|
end
|
45
45
|
|
46
|
-
## application_helper.rb
|
46
|
+
## application_helper.rb or whatever helper you want it in.
|
47
47
|
module ApplicationHelper
|
48
48
|
include Rack::Recaptcha::Helpers
|
49
49
|
end
|
50
50
|
|
51
|
+
## application_controller.rb or whatever controller you want it in.
|
52
|
+
module ApplicationController
|
53
|
+
include Rack::Recaptcha::Helpers
|
54
|
+
end
|
55
|
+
|
51
56
|
### Helpers
|
52
57
|
|
53
58
|
The `Rack::Recaptcha::Helpers` module (for Sinatra, Rails, Padrino) adds these methods to your app:
|
@@ -63,6 +68,17 @@ The `Rack::Recaptcha::Helpers` module (for Sinatra, Rails, Padrino) adds these m
|
|
63
68
|
|
64
69
|
* `recaptcha_valid?` -- returns whether or not the verification passed.
|
65
70
|
|
71
|
+
The `recaptcha_valid?` helper can also be overloaded during tests. You
|
72
|
+
can set its response to either true or false by doing the follow:
|
73
|
+
|
74
|
+
Rack::Recaptcha.test_mode!
|
75
|
+
|
76
|
+
will have the helper return true or
|
77
|
+
|
78
|
+
Rack::Recaptcha.test_mode! :return => false
|
79
|
+
|
80
|
+
to have the helper always return false.
|
81
|
+
|
66
82
|
#### Example
|
67
83
|
|
68
84
|
In Padrino, here's how you would use the helpers.
|
data/lib/rack/recaptcha.rb
CHANGED
@@ -10,7 +10,12 @@ module Rack
|
|
10
10
|
RESPONSE_FIELD = 'recaptcha_response_field'
|
11
11
|
|
12
12
|
class << self
|
13
|
-
attr_accessor :private_key, :public_key
|
13
|
+
attr_accessor :private_key, :public_key, :test_mode
|
14
|
+
|
15
|
+
def test_mode!(options = {})
|
16
|
+
value = options[:return]
|
17
|
+
self.test_mode = value.nil? ? true : options[:return]
|
18
|
+
end
|
14
19
|
end
|
15
20
|
|
16
21
|
# Initialize the Rack Middleware. Some of the available options are:
|
data/rack-recaptcha.gemspec
CHANGED
data/test/helpers_test.rb
CHANGED
@@ -73,21 +73,25 @@ context "Rack::Recaptcha::Helpers" do
|
|
73
73
|
end
|
74
74
|
|
75
75
|
context "recaptcha_valid?" do
|
76
|
-
|
77
|
-
context "passing" do
|
78
|
-
setup do
|
79
|
-
mock(helper_test.request.env).[]('recaptcha.valid').returns(true)
|
80
|
-
end
|
81
76
|
|
82
|
-
|
77
|
+
asserts "that it passes when recaptcha.valid is true" do
|
78
|
+
mock(helper_test.request.env).[]('recaptcha.valid').returns(true)
|
79
|
+
helper_test.recaptcha_valid?
|
83
80
|
end
|
84
81
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
82
|
+
denies "that it passes when recaptcha.valid is false" do
|
83
|
+
mock(helper_test.request.env).[]('recaptcha.valid').returns(false)
|
84
|
+
helper_test.recaptcha_valid?
|
85
|
+
end
|
86
|
+
|
87
|
+
asserts "that it passes when test mode set to pass" do
|
88
|
+
Rack::Recaptcha.test_mode!
|
89
|
+
helper_test.recaptcha_valid?
|
90
|
+
end
|
89
91
|
|
90
|
-
|
92
|
+
denies "that it passes when test mode set to fil" do
|
93
|
+
Rack::Recaptcha.test_mode! :return => false
|
94
|
+
helper_test.recaptcha_valid?
|
91
95
|
end
|
92
96
|
|
93
97
|
end
|
data/test/recaptcha_test.rb
CHANGED
@@ -17,28 +17,39 @@ context "Rack::Recaptcha" do
|
|
17
17
|
asserts(:public_key).equals PUBLIC_KEY
|
18
18
|
end
|
19
19
|
|
20
|
-
context "
|
20
|
+
context "#test_mode!" do
|
21
|
+
setup { Rack::Recaptcha }
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
asserts "that it sets @@test_mode to be true" do
|
24
|
+
topic.test_mode!
|
25
|
+
topic.test_mode
|
25
26
|
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
post("/login", 'recaptcha_challenge_field' => 'challenge', 'recaptcha_response_field' => 'response')
|
31
|
-
end
|
32
|
-
asserts("post login") { last_response.body }.equals 'post login'
|
28
|
+
denies "that it sets @@test_mode to be true if option set to false" do
|
29
|
+
topic.test_mode! :return => false
|
30
|
+
topic.test_mode
|
33
31
|
end
|
32
|
+
end
|
34
33
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
34
|
+
context "login path" do
|
35
|
+
|
36
|
+
asserts "GET login" do
|
37
|
+
get '/login'
|
38
|
+
last_response.body
|
39
|
+
end.equals 'login'
|
40
|
+
|
41
|
+
|
42
|
+
asserts "POST login passes and" do
|
43
|
+
FakeWeb.register_uri(:post, Rack::Recaptcha::VERIFY_URL, :body => "true\nsuccess")
|
44
|
+
post("/login", 'recaptcha_challenge_field' => 'challenge', 'recaptcha_response_field' => 'response')
|
45
|
+
last_response.body
|
46
|
+
end.equals 'post login'
|
47
|
+
|
48
|
+
asserts "POST login fails and" do
|
49
|
+
FakeWeb.register_uri(:post, Rack::Recaptcha::VERIFY_URL, :body => "false\nfailed")
|
50
|
+
post("/login", 'recaptcha_challenge_field' => 'challenge', 'recaptcha_response_field' => 'response')
|
51
|
+
last_response.body
|
52
|
+
end.equals 'post fail'
|
42
53
|
end
|
43
54
|
|
44
55
|
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-recaptcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
4
|
+
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
7
|
+
- 5
|
8
|
+
- 0
|
9
|
+
version: 0.5.0
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Arthur Chiu
|
@@ -26,7 +25,6 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
28
|
segments:
|
31
29
|
- 0
|
32
30
|
version: "0"
|
@@ -40,7 +38,6 @@ dependencies:
|
|
40
38
|
requirements:
|
41
39
|
- - ~>
|
42
40
|
- !ruby/object:Gem::Version
|
43
|
-
hash: 41
|
44
41
|
segments:
|
45
42
|
- 0
|
46
43
|
- 12
|
@@ -56,7 +53,6 @@ dependencies:
|
|
56
53
|
requirements:
|
57
54
|
- - ~>
|
58
55
|
- !ruby/object:Gem::Version
|
59
|
-
hash: 5
|
60
56
|
segments:
|
61
57
|
- 0
|
62
58
|
- 5
|
@@ -72,7 +68,6 @@ dependencies:
|
|
72
68
|
requirements:
|
73
69
|
- - ~>
|
74
70
|
- !ruby/object:Gem::Version
|
75
|
-
hash: 27
|
76
71
|
segments:
|
77
72
|
- 1
|
78
73
|
- 3
|
@@ -88,7 +83,6 @@ dependencies:
|
|
88
83
|
requirements:
|
89
84
|
- - ~>
|
90
85
|
- !ruby/object:Gem::Version
|
91
|
-
hash: 19
|
92
86
|
segments:
|
93
87
|
- 1
|
94
88
|
- 0
|
@@ -131,7 +125,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
131
125
|
requirements:
|
132
126
|
- - ">="
|
133
127
|
- !ruby/object:Gem::Version
|
134
|
-
hash: 3
|
135
128
|
segments:
|
136
129
|
- 0
|
137
130
|
version: "0"
|
@@ -140,7 +133,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
133
|
requirements:
|
141
134
|
- - ">="
|
142
135
|
- !ruby/object:Gem::Version
|
143
|
-
hash: 23
|
144
136
|
segments:
|
145
137
|
- 1
|
146
138
|
- 3
|
@@ -149,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
141
|
requirements: []
|
150
142
|
|
151
143
|
rubyforge_project:
|
152
|
-
rubygems_version: 1.
|
144
|
+
rubygems_version: 1.3.7
|
153
145
|
signing_key:
|
154
146
|
specification_version: 3
|
155
147
|
summary: Rack middleware for Recaptcha
|