lastobelus-merb-recaptcha 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +45 -0
- data/Rakefile +81 -0
- data/TODO +1 -0
- data/lib/merb-recaptcha.rb +30 -0
- data/lib/merb-recaptcha/constants.rb +7 -0
- data/lib/merb-recaptcha/controller_mixin.rb +47 -0
- data/lib/merb-recaptcha/exceptions.rb +30 -0
- data/lib/merb-recaptcha/merbtasks.rb +0 -0
- data/lib/merb-recaptcha/view_helpers.rb +117 -0
- data/merb-recaptcha.gemspec +44 -0
- data/spec/fixture/app/controllers/application.rb +2 -0
- data/spec/fixture/app/controllers/exceptions.rb +13 -0
- data/spec/fixture/app/controllers/recaptcha.rb +29 -0
- data/spec/fixture/app/helpers/global_helpers.rb +5 -0
- data/spec/fixture/app/helpers/recaptcha_helpers.rb +4 -0
- data/spec/fixture/app/views/exceptions/not_acceptable.html.erb +63 -0
- data/spec/fixture/app/views/exceptions/not_found.html.erb +47 -0
- data/spec/fixture/app/views/layout/application.html.erb +10 -0
- data/spec/fixture/app/views/recaptcha/ajax.html.erb +2 -0
- data/spec/fixture/app/views/recaptcha/ajax_with_callback.html.erb +2 -0
- data/spec/fixture/app/views/recaptcha/ajax_with_jquery.html.erb +2 -0
- data/spec/fixture/app/views/recaptcha/ajax_with_options.html.erb +2 -0
- data/spec/fixture/app/views/recaptcha/noajax_with_noscript.html.erb +1 -0
- data/spec/fixture/app/views/recaptcha/noajax_with_options.html.erb +1 -0
- data/spec/fixture/app/views/recaptcha/noajax_without_noscript.html.erb +1 -0
- data/spec/recaptcha_ajax_spec.rb +39 -0
- data/spec/recaptcha_ajax_with_callback_spec.rb +35 -0
- data/spec/recaptcha_ajax_with_jquery_spec.rb +39 -0
- data/spec/recaptcha_ajax_with_options_spec.rb +35 -0
- data/spec/recaptcha_noajax_with_noscript_spec.rb +59 -0
- data/spec/recaptcha_noajax_with_options_spec.rb +39 -0
- data/spec/recaptcha_noajax_without_noscript_spec.rb +39 -0
- data/spec/recaptcha_valid_spec.rb +125 -0
- data/spec/spec_helper.rb +46 -0
- metadata +152 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "Recaptcha#noajax_without_noscript" do
|
4
|
+
describe "HTTP" do
|
5
|
+
before(:each) do
|
6
|
+
@response = dispatch_to(Recaptcha, "noajax_without_noscript")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should load script from api url" do
|
10
|
+
@response.should have_xpath("//script[@src='http://api.recaptcha.net/challenge?k=#{Merb::Plugins.config[:merb_recaptcha][:public_key]}']")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should not send private key to anything" do
|
14
|
+
@response.should_not have_xpath("//*[contains(., '#{Merb::Plugins.config[:merb_recaptcha][:private_key]}')]")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should not have noscript element" do
|
18
|
+
@response.should_not have_xpath("//noscript")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should not have RecaptchaOptions array initialization" do
|
22
|
+
@response.should_not have_xpath("//script[contains(., 'var RecaptchaOptions')]")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "HTTPS" do
|
27
|
+
before(:each) do
|
28
|
+
@response = dispatch_to(Recaptcha, "noajax_without_noscript", {}, { "HTTPS" => "on" })
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should load script from secure api url" do
|
32
|
+
@response.should have_xpath("//script[@src='https://api-secure.recaptcha.net/challenge?k=#{Merb::Plugins.config[:merb_recaptcha][:public_key]}']")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should not send private key to anything" do
|
36
|
+
@response.should_not have_xpath("//*[contains(., '#{Merb::Plugins.config[:merb_recaptcha][:private_key]}')]")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
class FakeController < Merb::Controller
|
4
|
+
def check_recaptcha
|
5
|
+
return recaptcha_valid?.to_s
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "FakeController#check_recaptcha" do
|
10
|
+
def do_request(ssl = false)
|
11
|
+
@response = dispatch_to(FakeController, :check_recaptcha, { :recaptcha_challenge_field => "blabla", :recaptcha_response_field => "blabla" }, { "HTTPS" => ssl ? "on" : "off" })
|
12
|
+
end
|
13
|
+
|
14
|
+
def stub_response(body)
|
15
|
+
Net::HTTP.stubs(:post_form).returns stub("Net::HTTPResponse", :body => body)
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "with non-SSL request" do
|
19
|
+
it "should use non-ssl API server" do
|
20
|
+
cond = proc { |*args| args.first.is_a?(URI::HTTP) && args.first.scheme == "http" && args.first.host == "api-verify.recaptcha.net" }
|
21
|
+
Net::HTTP.expects(:post_form).with(&cond).returns(stub("Net::HTTPResponse", :body => "true"))
|
22
|
+
do_request(false)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "with SSL request" do
|
27
|
+
it "should use non-ssl API server" do
|
28
|
+
cond = proc { |*args| args.first.is_a?(URI::HTTP) && args.first.scheme == "http" && args.first.host == "api-verify.recaptcha.net" }
|
29
|
+
Net::HTTP.expects(:post_form).with(&cond).returns(stub("Net::HTTPResponse", :body => "true"))
|
30
|
+
do_request(true)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "with correct response" do
|
35
|
+
before(:each) do
|
36
|
+
stub_response("true\n")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should render 'true'" do
|
40
|
+
do_request
|
41
|
+
@response.should have_selector("*:contains('true')")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should not raise any exception" do
|
45
|
+
lambda { do_request }.should_not raise_error
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "with incorrect response" do
|
50
|
+
before(:each) do
|
51
|
+
stub_response("false\nincorrect-captcha-sol\n")
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should render 'false'" do
|
55
|
+
do_request
|
56
|
+
@response.should have_selector("*:contains('false')")
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should not raise any exception" do
|
60
|
+
lambda { do_request }.should_not raise_error
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "with incorrect public key" do
|
65
|
+
before(:each) do
|
66
|
+
stub_response("false\ninvalid-site-public-key\n")
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should raise Merb::Recaptcha::InvalidSitePublicKey" do
|
70
|
+
lambda { do_request }.should raise_error(Merb::Recaptcha::InvalidSitePublicKey)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "with incorrect private key" do
|
75
|
+
before(:each) do
|
76
|
+
stub_response("false\ninvalid-site-private-key\n")
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should raise Merb::Recaptcha::InvalidSitePrivateKey" do
|
80
|
+
lambda { do_request }.should raise_error(Merb::Recaptcha::InvalidSitePrivateKey)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "with invalid request cookie" do
|
85
|
+
before(:each) do
|
86
|
+
stub_response("false\ninvalid-request-cookie\n")
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should raise Merb::Recaptcha::InvalidRequestCookie" do
|
90
|
+
lambda { do_request }.should raise_error(Merb::Recaptcha::InvalidRequestCookie)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "with verify parameters incorrect" do
|
95
|
+
before(:each) do
|
96
|
+
stub_response("false\nverify-params-incorrect\n")
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should raise Merb::Recaptcha::VerifyParamsIncorrect" do
|
100
|
+
lambda { do_request }.should raise_error(Merb::Recaptcha::VerifyParamsIncorrect)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "with invalid referrer" do
|
105
|
+
before(:each) do
|
106
|
+
stub_response("false\ninvalid-referrer\n")
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should raise Merb::Recaptcha::IvalidReferrer" do
|
110
|
+
lambda { do_request }.should raise_error(Merb::Recaptcha::InvalidReferrer)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "when can't connect to recaptcha" do
|
115
|
+
before(:each) do
|
116
|
+
Net::HTTP.stubs(:post_form).times(2).raises(Exception, "can't connect to recaptcha")
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should pass through if env var OFFLINE is set" do
|
120
|
+
lambda { do_request }.should raise_error(Exception)
|
121
|
+
ENV['OFFLINE'] = '1'
|
122
|
+
lambda { do_request }.should_not raise_error
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
require 'merb-core'
|
4
|
+
|
5
|
+
$:.push File.join(File.dirname(__FILE__), '..', 'lib')
|
6
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'merb-recaptcha')
|
7
|
+
|
8
|
+
default_options = {
|
9
|
+
:testing => true,
|
10
|
+
:adapter => 'runner',
|
11
|
+
:merb_root => File.dirname(__FILE__) / 'fixture',
|
12
|
+
:log_stream => STDOUT
|
13
|
+
}
|
14
|
+
options = default_options.merge($START_OPTIONS || {})
|
15
|
+
|
16
|
+
Merb.disable(:initfile)
|
17
|
+
Merb::BootLoader.after_app_loads do
|
18
|
+
Merb::Plugins.config[:merb_recaptcha][:public_key] = "QAAAAAA--public-key--AAAAAAQ"
|
19
|
+
Merb::Plugins.config[:merb_recaptcha][:private_key] = "QAAAAAA--private-key--AAAAAAAQ"
|
20
|
+
|
21
|
+
Merb::Router.prepare { default_routes }
|
22
|
+
Merb::RecaptchaMixin.const_set(:DO_NOT_IGNORE_RECAPTCHA_IN_TESTING_ENV, true)
|
23
|
+
end
|
24
|
+
Merb.start_environment(options)
|
25
|
+
|
26
|
+
Spec::Runner.configure do |config|
|
27
|
+
config.include Merb::Test::ViewHelper
|
28
|
+
config.include Merb::Test::RouteHelper
|
29
|
+
config.include Merb::Test::ControllerHelper
|
30
|
+
|
31
|
+
config.mock_with :mocha
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "ajax recaptcha", :shared => true do
|
35
|
+
it "should invoke Recaptcha.create" do
|
36
|
+
@response.should have_xpath("//script[contains(., 'Recaptcha.create')]")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should send public key to Recaptcha.create" do
|
40
|
+
@response.should have_xpath("//script[contains(., 'Recaptcha.create') and contains(., '#{Merb::Plugins.config[:merb_recaptcha][:public_key]}')]")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should not send private key to anything" do
|
44
|
+
@response.should_not have_xpath("//*[contains(., '#{Merb::Plugins.config[:merb_recaptcha][:private_key]}')]")
|
45
|
+
end
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lastobelus-merb-recaptcha
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anton Ageev
|
8
|
+
- Michael Johnston
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2008-12-19 00:00:00 -08:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: merb-core
|
18
|
+
type: :runtime
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 1.0.0
|
25
|
+
version:
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: builder
|
28
|
+
type: :runtime
|
29
|
+
version_requirement:
|
30
|
+
version_requirements: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "2.0"
|
35
|
+
version:
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
type: :development
|
39
|
+
version_requirement:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 1.1.0
|
45
|
+
version:
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: mocha
|
48
|
+
type: :development
|
49
|
+
version_requirement:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.9.3
|
55
|
+
version:
|
56
|
+
description: Merb plugin that provides helpers for recaptcha.net service
|
57
|
+
email: antage@gmail.com
|
58
|
+
executables: []
|
59
|
+
|
60
|
+
extensions: []
|
61
|
+
|
62
|
+
extra_rdoc_files:
|
63
|
+
- README.rdoc
|
64
|
+
- LICENSE
|
65
|
+
files:
|
66
|
+
- LICENSE
|
67
|
+
- README.rdoc
|
68
|
+
- Rakefile
|
69
|
+
- TODO
|
70
|
+
- merb-recaptcha.gemspec
|
71
|
+
- lib/merb-recaptcha/constants.rb
|
72
|
+
- lib/merb-recaptcha/merbtasks.rb
|
73
|
+
- lib/merb-recaptcha/controller_mixin.rb
|
74
|
+
- lib/merb-recaptcha/view_helpers.rb
|
75
|
+
- lib/merb-recaptcha/exceptions.rb
|
76
|
+
- lib/merb-recaptcha.rb
|
77
|
+
- spec/spec_helper.rb
|
78
|
+
- spec/recaptcha_ajax_with_options_spec.rb
|
79
|
+
- spec/recaptcha_noajax_without_noscript_spec.rb
|
80
|
+
- spec/recaptcha_noajax_with_noscript_spec.rb
|
81
|
+
- spec/recaptcha_valid_spec.rb
|
82
|
+
- spec/recaptcha_ajax_spec.rb
|
83
|
+
- spec/recaptcha_ajax_with_callback_spec.rb
|
84
|
+
- spec/recaptcha_noajax_with_options_spec.rb
|
85
|
+
- spec/recaptcha_ajax_with_jquery_spec.rb
|
86
|
+
- spec/fixture/app/controllers/application.rb
|
87
|
+
- spec/fixture/app/controllers/exceptions.rb
|
88
|
+
- spec/fixture/app/controllers/recaptcha.rb
|
89
|
+
- spec/fixture/app/views/exceptions/not_acceptable.html.erb
|
90
|
+
- spec/fixture/app/views/exceptions/not_found.html.erb
|
91
|
+
- spec/fixture/app/views/layout/application.html.erb
|
92
|
+
- spec/fixture/app/views/recaptcha/ajax.html.erb
|
93
|
+
- spec/fixture/app/views/recaptcha/ajax_with_callback.html.erb
|
94
|
+
- spec/fixture/app/views/recaptcha/ajax_with_options.html.erb
|
95
|
+
- spec/fixture/app/views/recaptcha/noajax_without_noscript.html.erb
|
96
|
+
- spec/fixture/app/views/recaptcha/noajax_with_options.html.erb
|
97
|
+
- spec/fixture/app/views/recaptcha/noajax_with_noscript.html.erb
|
98
|
+
- spec/fixture/app/views/recaptcha/ajax_with_jquery.html.erb
|
99
|
+
- spec/fixture/app/helpers/global_helpers.rb
|
100
|
+
- spec/fixture/app/helpers/recaptcha_helpers.rb
|
101
|
+
has_rdoc: true
|
102
|
+
homepage: http://github.com/antage/merb-recaptcha/
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options:
|
105
|
+
- --main
|
106
|
+
- README.rdoc
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: "0"
|
114
|
+
version:
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: "0"
|
120
|
+
version:
|
121
|
+
requirements: []
|
122
|
+
|
123
|
+
rubyforge_project: merb-recaptcha
|
124
|
+
rubygems_version: 1.2.0
|
125
|
+
signing_key:
|
126
|
+
specification_version: 3
|
127
|
+
summary: Merb plugin that provides helpers for recaptcha.net service
|
128
|
+
test_files:
|
129
|
+
- spec/spec_helper.rb
|
130
|
+
- spec/recaptcha_ajax_with_options_spec.rb
|
131
|
+
- spec/recaptcha_noajax_without_noscript_spec.rb
|
132
|
+
- spec/recaptcha_noajax_with_noscript_spec.rb
|
133
|
+
- spec/recaptcha_valid_spec.rb
|
134
|
+
- spec/recaptcha_ajax_spec.rb
|
135
|
+
- spec/recaptcha_ajax_with_callback_spec.rb
|
136
|
+
- spec/recaptcha_noajax_with_options_spec.rb
|
137
|
+
- spec/recaptcha_ajax_with_jquery_spec.rb
|
138
|
+
- spec/fixture/app/controllers/application.rb
|
139
|
+
- spec/fixture/app/controllers/exceptions.rb
|
140
|
+
- spec/fixture/app/controllers/recaptcha.rb
|
141
|
+
- spec/fixture/app/views/exceptions/not_acceptable.html.erb
|
142
|
+
- spec/fixture/app/views/exceptions/not_found.html.erb
|
143
|
+
- spec/fixture/app/views/layout/application.html.erb
|
144
|
+
- spec/fixture/app/views/recaptcha/ajax.html.erb
|
145
|
+
- spec/fixture/app/views/recaptcha/ajax_with_callback.html.erb
|
146
|
+
- spec/fixture/app/views/recaptcha/ajax_with_options.html.erb
|
147
|
+
- spec/fixture/app/views/recaptcha/noajax_without_noscript.html.erb
|
148
|
+
- spec/fixture/app/views/recaptcha/noajax_with_options.html.erb
|
149
|
+
- spec/fixture/app/views/recaptcha/noajax_with_noscript.html.erb
|
150
|
+
- spec/fixture/app/views/recaptcha/ajax_with_jquery.html.erb
|
151
|
+
- spec/fixture/app/helpers/global_helpers.rb
|
152
|
+
- spec/fixture/app/helpers/recaptcha_helpers.rb
|