rack-recaptcha 0.6.5 → 0.6.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -0
- data/lib/rack/recaptcha.rb +3 -1
- data/rack-recaptcha.gemspec +2 -2
- data/test/helpers_test.rb +101 -113
- data/test/recaptcha_test.rb +21 -44
- data/test/{teststrap.rb → test_helper.rb} +6 -8
- metadata +7 -7
data/README.md
CHANGED
@@ -192,6 +192,10 @@ Rob Worley - [robworley](https://github.com/robworley)
|
|
192
192
|
|
193
193
|
* Adding language setting for recaptcha form
|
194
194
|
|
195
|
+
sam71 - [sam71](https://github.com/sam71)
|
196
|
+
|
197
|
+
* Fix recaptcha hanging when used in proxy environment.
|
198
|
+
|
195
199
|
#### Note on Patches/Pull Requests
|
196
200
|
|
197
201
|
* Fork the project.
|
data/lib/rack/recaptcha.rb
CHANGED
@@ -59,13 +59,15 @@ module Rack
|
|
59
59
|
}
|
60
60
|
|
61
61
|
uri = URI.parse(VERIFY_URL)
|
62
|
-
|
62
|
+
|
63
63
|
|
64
64
|
if self.class.proxy_host && self.class.proxy_port
|
65
65
|
http = Net::HTTP.Proxy(self.class.proxy_host,
|
66
66
|
self.class.proxy_port,
|
67
67
|
self.class.proxy_user,
|
68
68
|
self.class.proxy_password).start(uri.host, uri.port)
|
69
|
+
else
|
70
|
+
http = Net::HTTP.start(uri.host, uri.port)
|
69
71
|
end
|
70
72
|
|
71
73
|
request = Net::HTTP::Post.new(uri.path)
|
data/rack-recaptcha.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = %q{rack-recaptcha}
|
3
|
-
s.version = "0.6.
|
3
|
+
s.version = "0.6.6"
|
4
4
|
s.required_rubygems_version = ">=1.3.6"
|
5
5
|
s.authors = ["Arthur Chiu"]
|
6
6
|
s.date = %q{2010-07-18}
|
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.test_files = Dir.glob("test/**/*")
|
17
17
|
s.add_runtime_dependency "json", ">= 0"
|
18
18
|
s.add_development_dependency "rake", "~> 0.9.2"
|
19
|
-
s.add_development_dependency "
|
19
|
+
s.add_development_dependency "minitest", "~> 4.6"
|
20
20
|
s.add_development_dependency "rack-test", "~> 0.5.7"
|
21
21
|
s.add_development_dependency "fakeweb", "~> 1.3.0"
|
22
22
|
s.add_development_dependency "rr", "~> 1.0.2"
|
data/test/helpers_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path '../
|
1
|
+
require File.expand_path '../test_helper', __FILE__
|
2
2
|
|
3
3
|
class HelperTest
|
4
4
|
attr_accessor :request
|
@@ -13,7 +13,6 @@ class HelperTest
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
16
|
# With "attr_accessor :request" HelperTest has "request" defined as a method
|
18
17
|
# even when @request is set to nil
|
19
18
|
#
|
@@ -27,150 +26,139 @@ class HelperTestWithoutRequest
|
|
27
26
|
include Rack::Recaptcha::Helpers
|
28
27
|
end
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
asserts_topic('has js').matches %r{recaptcha_ajax.js}
|
57
|
-
asserts_topic('has div').matches %r{<div id="ajax_recaptcha"></div>}
|
58
|
-
denies_topic('has display').matches %r{RecaptchaOptions}
|
59
|
-
denies_topic('has theme').matches %r{"theme":"red"}
|
60
|
-
end
|
29
|
+
describe Rack::Recaptcha::Helpers do
|
30
|
+
|
31
|
+
def helper_test
|
32
|
+
HelperTest.new
|
33
|
+
end
|
34
|
+
|
35
|
+
def helper_test_without_request
|
36
|
+
HelperTestWithoutRequest.new
|
37
|
+
end
|
38
|
+
|
39
|
+
before do
|
40
|
+
Rack::Recaptcha.public_key = ::PUBLIC_KEY
|
41
|
+
end
|
42
|
+
|
43
|
+
describe ".recaptcha_tag" do
|
44
|
+
|
45
|
+
it "should render ajax with display" do
|
46
|
+
mock(helper_test.request.env).[]('recaptcha.msg').returns(nil)
|
47
|
+
topic = helper_test.recaptcha_tag(:ajax,:display => {:theme => 'red'})
|
48
|
+
|
49
|
+
assert_match %r{recaptcha_ajax.js}, topic
|
50
|
+
assert_match %r{<div id="ajax_recaptcha"></div>}, topic
|
51
|
+
assert_match %r{RecaptchaOptions}, topic
|
52
|
+
assert_match %r{"theme":"red"}, topic
|
61
53
|
end
|
62
54
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
asserts_topic("public key").matches %r{hello_world_world}
|
72
|
-
asserts_topic("has language").matches %r{hl=en}
|
73
|
-
denies_topic("has js").matches %r{recaptcha_ajax.js}
|
55
|
+
it "should render ajax without display" do
|
56
|
+
mock(helper_test.request.env).[]('recaptcha.msg').returns(nil)
|
57
|
+
topic = helper_test.recaptcha_tag(:ajax)
|
58
|
+
|
59
|
+
assert_match %r{recaptcha_ajax.js}, topic
|
60
|
+
assert_match %r{<div id="ajax_recaptcha"></div>}, topic
|
61
|
+
refute_match %r{RecaptchaOptions}, topic
|
62
|
+
refute_match %r{"theme":"red"}, topic
|
74
63
|
end
|
75
64
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
denies_topic("has display").matches %r{RecaptchaOptions}
|
86
|
-
asserts_topic("has public_key").matches %r{#{'0'*40}}
|
87
|
-
asserts_topic("has language").matches %r{hl=en}
|
65
|
+
it "should render noscript" do
|
66
|
+
mock(helper_test.request.env).[]('recaptcha.msg').returns(nil)
|
67
|
+
topic = helper_test.recaptcha_tag :noscript, :public_key => "hello_world_world", :language => :en
|
68
|
+
|
69
|
+
assert_match %r{iframe}, topic
|
70
|
+
assert_match %r{<noscript>}, topic
|
71
|
+
assert_match %r{hello_world_world}, topic
|
72
|
+
assert_match %r{hl=en}, topic
|
73
|
+
refute_match %r{recaptcha_ajax.js}, topic
|
88
74
|
end
|
89
75
|
|
90
|
-
|
76
|
+
it "should render challenge" do
|
77
|
+
mock(helper_test.request.env).[]('recaptcha.msg').returns(nil)
|
78
|
+
topic = helper_test.recaptcha_tag(:challenge, :language => :en)
|
91
79
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
80
|
+
assert_match %r{script}, topic
|
81
|
+
assert_match %r{challenge}, topic
|
82
|
+
refute_match %r{recaptcha_ajax.js}, topic
|
83
|
+
refute_match %r{RecaptchaOptions}, topic
|
84
|
+
assert_match %r{#{'0'*40}}, topic
|
85
|
+
assert_match %r{hl=en}, topic
|
86
|
+
end
|
96
87
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
88
|
+
it "should render script with SSL URL" do
|
89
|
+
mock(helper_test.request.env).[]('recaptcha.msg').returns(nil)
|
90
|
+
topic = helper_test.recaptcha_tag(:challenge, :ssl => true)
|
91
|
+
assert_match %r{#{Rack::Recaptcha::API_SECURE_URL}}, topic
|
101
92
|
end
|
102
93
|
|
94
|
+
it "should render script with no SSL URL" do
|
95
|
+
mock(helper_test.request.env).[]('recaptcha.msg').returns(nil)
|
96
|
+
topic = helper_test.recaptcha_tag(:ajax)
|
97
|
+
assert_match %r{#{Rack::Recaptcha::API_URL}}, topic
|
98
|
+
end
|
103
99
|
end
|
104
100
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
asserts_topic("has public_key").matches %r{#{'0'*40}}
|
117
|
-
asserts_topic("has previous error").matches %r{Sample%20Error}
|
101
|
+
describe ".recaptcha_tag with errors" do
|
102
|
+
it "should render challenge with error" do
|
103
|
+
mock(helper_test.request.env).[]('recaptcha.msg').returns("Sample Error")
|
104
|
+
topic = helper_test.recaptcha_tag(:challenge)
|
105
|
+
|
106
|
+
assert_match %r{script}, topic
|
107
|
+
assert_match %r{challenge}, topic
|
108
|
+
refute_match %r{recaptcha_ajax.js}, topic
|
109
|
+
refute_match %r{RecaptchaOptions}, topic
|
110
|
+
assert_match %r{#{'0'*40}}, topic
|
111
|
+
assert_match %r{Sample%20Error}, topic
|
118
112
|
end
|
119
113
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
helper_test.recaptcha_tag :noscript, :public_key => "hello_world_world"
|
124
|
-
end
|
125
|
-
|
126
|
-
asserts_topic("iframe").matches %r{iframe}
|
127
|
-
asserts_topic("no script tag").matches %r{<noscript>}
|
128
|
-
asserts_topic("public key").matches %r{hello_world_world}
|
129
|
-
denies_topic("has js").matches %r{recaptcha_ajax.js}
|
130
|
-
asserts_topic("has previous error").matches %r{Sample%20Error}
|
131
|
-
end
|
114
|
+
it "should render noscript with error" do
|
115
|
+
mock(helper_test.request.env).[]('recaptcha.msg').returns("Sample Error")
|
116
|
+
topic = helper_test.recaptcha_tag :noscript, :public_key => "hello_world_world"
|
132
117
|
|
118
|
+
assert_match %r{iframe}, topic
|
119
|
+
assert_match %r{<noscript>}, topic
|
120
|
+
assert_match %r{hello_world_world}, topic
|
121
|
+
refute_match %r{recaptcha_ajax.js}, topic
|
122
|
+
assert_match %r{Sample%20Error}, topic
|
123
|
+
end
|
133
124
|
end
|
134
125
|
|
135
|
-
|
136
|
-
|
137
|
-
asserts "that it passes when recaptcha.valid is true" do
|
126
|
+
describe ".recaptcha_valid?" do
|
127
|
+
it "should assert that it passes when recaptcha.valid is true" do
|
138
128
|
Rack::Recaptcha.test_mode = nil
|
139
129
|
mock(helper_test.request.env).[]('recaptcha.valid').returns(true)
|
140
|
-
helper_test.recaptcha_valid?
|
130
|
+
assert helper_test.recaptcha_valid?
|
141
131
|
end
|
142
132
|
|
143
|
-
|
133
|
+
it "should refute that it passes when recaptcha.valid is false" do
|
144
134
|
Rack::Recaptcha.test_mode = nil
|
145
135
|
mock(helper_test.request.env).[]('recaptcha.valid').returns(false)
|
146
|
-
helper_test.recaptcha_valid?
|
136
|
+
refute helper_test.recaptcha_valid?
|
147
137
|
end
|
148
138
|
|
149
|
-
|
139
|
+
it "should assert that it passes when test mode set to pass" do
|
150
140
|
Rack::Recaptcha.test_mode!
|
151
|
-
helper_test.recaptcha_valid?
|
141
|
+
assert helper_test.recaptcha_valid?
|
152
142
|
end
|
153
143
|
|
154
|
-
|
144
|
+
it "should assert that it passes when test mode set to fail" do
|
155
145
|
Rack::Recaptcha.test_mode! :return => false
|
156
|
-
helper_test.recaptcha_valid?
|
146
|
+
refute helper_test.recaptcha_valid?
|
157
147
|
end
|
158
|
-
|
159
148
|
end
|
160
|
-
end
|
161
149
|
|
150
|
+
describe ".recaptcha_tag without request object" do
|
162
151
|
|
163
|
-
|
164
|
-
|
165
|
-
context "request object not available. Rack-recaptcha shouldn't die" do
|
166
|
-
setup do
|
167
|
-
helper_test.recaptcha_tag(:challenge)
|
168
|
-
end
|
152
|
+
it "should work without request object" do
|
153
|
+
topic = helper_test_without_request.recaptcha_tag(:challenge)
|
169
154
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
155
|
+
assert_match %r{script}, topic
|
156
|
+
assert_match %r{challenge}, topic
|
157
|
+
refute_match %r{recaptcha_ajax.js}, topic
|
158
|
+
refute_match %r{RecaptchaOptions}, topic
|
159
|
+
assert_match %r{#{'0'*40}}, topic
|
175
160
|
end
|
161
|
+
|
162
|
+
end
|
163
|
+
|
176
164
|
end
|
data/test/recaptcha_test.rb
CHANGED
@@ -1,55 +1,32 @@
|
|
1
|
-
require File.expand_path '../
|
1
|
+
require File.expand_path '../test_helper', __FILE__
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
context "basic request" do
|
7
|
-
setup { get("/") ; last_response }
|
8
|
-
|
9
|
-
asserts(:status).equals 200
|
10
|
-
asserts(:body).equals "Hello world"
|
11
|
-
end
|
12
|
-
|
13
|
-
context "exposes" do
|
14
|
-
setup { Rack::Recaptcha }
|
15
|
-
|
16
|
-
asserts(:private_key).equals PRIVATE_KEY
|
17
|
-
asserts(:public_key).equals PUBLIC_KEY
|
3
|
+
describe Rack::Recaptcha do
|
4
|
+
before do
|
5
|
+
FakeWeb.allow_net_connect = false
|
18
6
|
end
|
19
7
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
topic.test_mode!
|
25
|
-
topic.test_mode
|
8
|
+
describe "#test_mode!" do
|
9
|
+
it "should set test_mode to true" do
|
10
|
+
Rack::Recaptcha.test_mode!
|
11
|
+
assert Rack::Recaptcha.test_mode
|
26
12
|
end
|
27
13
|
|
28
|
-
|
29
|
-
|
30
|
-
|
14
|
+
it "should set test_mode to true" do
|
15
|
+
Rack::Recaptcha.test_mode! :return => false
|
16
|
+
refute Rack::Recaptcha.test_mode
|
31
17
|
end
|
32
18
|
end
|
33
19
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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'
|
20
|
+
it "should hit the login and pass" do
|
21
|
+
FakeWeb.register_uri(:post, Rack::Recaptcha::VERIFY_URL, :body => "true\nsuccess")
|
22
|
+
post("/login", 'recaptcha_challenge_field' => 'challenge', 'recaptcha_response_field' => 'response')
|
23
|
+
assert_equal 'post login', last_response.body
|
53
24
|
end
|
54
25
|
|
26
|
+
it "should hit the login and fail" do
|
27
|
+
FakeWeb.register_uri(:post, Rack::Recaptcha::VERIFY_URL, :body => "false\nfailed")
|
28
|
+
post("/login", 'recaptcha_challenge_field' => 'challenge', 'recaptcha_response_field' => 'response')
|
29
|
+
assert_equal 'post fail', last_response.body
|
30
|
+
end
|
55
31
|
end
|
32
|
+
|
@@ -1,20 +1,21 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
gem 'minitest'
|
3
|
+
require 'minitest/autorun'
|
2
4
|
require 'rack/test'
|
3
5
|
require 'rack/mock'
|
4
6
|
require 'rack/utils'
|
5
7
|
require 'rack/session/cookie'
|
6
8
|
require 'rack/builder'
|
7
|
-
require 'rr'
|
8
|
-
require 'riot'
|
9
|
-
require 'riot/rr'
|
10
9
|
require 'fakeweb'
|
10
|
+
require 'rr'
|
11
11
|
require File.expand_path '../../lib/rack/recaptcha', __FILE__
|
12
12
|
|
13
|
-
PUBLIC_KEY
|
13
|
+
PUBLIC_KEY = '0'*40
|
14
14
|
PRIVATE_KEY = 'X'*40
|
15
15
|
|
16
|
-
class
|
16
|
+
class MiniTest::Spec
|
17
17
|
include Rack::Test::Methods
|
18
|
+
include RR::Adapters::MiniTest
|
18
19
|
|
19
20
|
def app
|
20
21
|
main_app = lambda { |env|
|
@@ -40,6 +41,3 @@ class Riot::Situation
|
|
40
41
|
builder.to_app
|
41
42
|
end
|
42
43
|
end
|
43
|
-
|
44
|
-
class Riot::Context
|
45
|
-
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-recaptcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -44,13 +44,13 @@ dependencies:
|
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 0.9.2
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: minitest
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
51
|
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: '4.6'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -58,7 +58,7 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '4.6'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: rack-test
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -125,7 +125,7 @@ files:
|
|
125
125
|
- lib/rack/recaptcha.rb
|
126
126
|
- test/helpers_test.rb
|
127
127
|
- test/recaptcha_test.rb
|
128
|
-
- test/
|
128
|
+
- test/test_helper.rb
|
129
129
|
homepage: http://github.com/achiu/rack-recaptcha
|
130
130
|
licenses: []
|
131
131
|
post_install_message:
|
@@ -147,11 +147,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
147
|
version: 1.3.6
|
148
148
|
requirements: []
|
149
149
|
rubyforge_project:
|
150
|
-
rubygems_version: 1.8.
|
150
|
+
rubygems_version: 1.8.23
|
151
151
|
signing_key:
|
152
152
|
specification_version: 3
|
153
153
|
summary: Rack middleware for Recaptcha
|
154
154
|
test_files:
|
155
155
|
- test/helpers_test.rb
|
156
156
|
- test/recaptcha_test.rb
|
157
|
-
- test/
|
157
|
+
- test/test_helper.rb
|