invisible_captcha 0.6.5 → 0.7.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.
- checksums.yaml +7 -0
- data/.gitignore +3 -1
- data/.travis.yml +5 -0
- data/README.md +107 -47
- data/Rakefile +17 -1
- data/invisible_captcha.gemspec +2 -2
- data/lib/invisible_captcha.rb +28 -24
- data/lib/invisible_captcha/controller_ext.rb +48 -0
- data/lib/invisible_captcha/form_helpers.rb +3 -7
- data/lib/invisible_captcha/railtie.rb +9 -0
- data/lib/invisible_captcha/validator.rb +3 -7
- data/lib/invisible_captcha/version.rb +1 -1
- data/lib/invisible_captcha/view_helpers.rb +25 -23
- data/spec/controllers_spec.rb +25 -0
- data/spec/dummy/README.md +3 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/topics_controller.rb +27 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/models/topic.rb +18 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/topics/new.html.erb +17 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +20 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +30 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +34 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/invisible_captcha.rb +6 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +9 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +5 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +5 -0
- data/spec/helpers_spec.rb +43 -0
- data/spec/invisible_captcha_spec.rb +19 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/validator_spec.rb +12 -0
- metadata +100 -24
- data/lib/invisible_captcha/controller_methods.rb +0 -21
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/422.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The change you wanted was rejected.</h1>
|
23
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/500.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>We're sorry, but something went wrong.</h1>
|
23
|
+
</div>
|
24
|
+
</body>
|
25
|
+
</html>
|
File without changes
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe InvisibleCaptcha::ViewHelpers, type: :helper do
|
4
|
+
def helper_output(honeypot = nil, scope = nil)
|
5
|
+
honeypot ||= InvisibleCaptcha.get_honeypot
|
6
|
+
input_id = build_label_name(honeypot, scope)
|
7
|
+
input_name = build_text_field_name(honeypot, scope)
|
8
|
+
html_id = generate_html_id(honeypot, scope)
|
9
|
+
|
10
|
+
%{
|
11
|
+
<div id="#{html_id}">
|
12
|
+
<style media="screen" scoped="scoped" type="text/css">#{InvisibleCaptcha.visual_honeypots ? '' : "##{html_id} { display:none; }"}</style>
|
13
|
+
<label for="#{input_id}">#{InvisibleCaptcha.sentence_for_humans}</label>
|
14
|
+
<input id="#{input_id}" name="#{input_name}" type="text" />
|
15
|
+
</div>
|
16
|
+
}.gsub(/\s+/, ' ').strip.gsub('> <', '><')
|
17
|
+
end
|
18
|
+
|
19
|
+
before do
|
20
|
+
allow(Time).to receive(:now).and_return(Time.parse('Feb 19 1986'))
|
21
|
+
InvisibleCaptcha.visual_honeypots = false
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'view helper with no arguments' do
|
25
|
+
InvisibleCaptcha.honeypots = [:foo_id]
|
26
|
+
expect(invisible_captcha).to eq(helper_output)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'view helper with specific honeypot' do
|
30
|
+
expect(invisible_captcha(:subtitle)).to eq(helper_output(:subtitle))
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'view helper with specific honeypot and scope' do
|
34
|
+
expect(invisible_captcha(:subtitle, :topic)).to eq(helper_output(:subtitle, :topic))
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'view helper with visual honeypots enabled' do
|
38
|
+
InvisibleCaptcha.honeypots = [:foo_id]
|
39
|
+
InvisibleCaptcha.visual_honeypots = true
|
40
|
+
|
41
|
+
expect(invisible_captcha).to eq(helper_output)
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe InvisibleCaptcha do
|
4
|
+
it 'initialize with defaults' do
|
5
|
+
InvisibleCaptcha.init!
|
6
|
+
|
7
|
+
expect(InvisibleCaptcha.sentence_for_humans).to eq('If you are a human, ignore this field')
|
8
|
+
expect(InvisibleCaptcha.error_message).to eq('You are a robot!')
|
9
|
+
expect(InvisibleCaptcha.honeypots).to eq(['foo_id', 'bar_id', 'baz_id'])
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'allow setup via block' do
|
13
|
+
InvisibleCaptcha.setup do |ic|
|
14
|
+
ic.sentence_for_humans = 'Another sentence'
|
15
|
+
end
|
16
|
+
|
17
|
+
expect(InvisibleCaptcha.sentence_for_humans).to eq('Another sentence')
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
2
|
+
|
3
|
+
ENV['RAILS_ENV'] = 'test'
|
4
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
|
+
|
6
|
+
require 'rspec/rails'
|
7
|
+
|
8
|
+
require 'invisible_captcha'
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.order = 'random'
|
12
|
+
config.expect_with :rspec
|
13
|
+
config.mock_with :rspec do |mocks|
|
14
|
+
mocks.verify_partial_doubles = true
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe InvisibleCaptcha::InvisibleCaptchaValidator do
|
4
|
+
it 'do not pass validations if honeypot is presented' do
|
5
|
+
topic = Topic.new
|
6
|
+
expect(topic.valid?).to be true
|
7
|
+
|
8
|
+
topic.subtitle = 'foo'
|
9
|
+
expect(topic.valid?).to be false
|
10
|
+
expect(topic.errors.messages[:base]).to eq [InvisibleCaptcha.error_message]
|
11
|
+
end
|
12
|
+
end
|
metadata
CHANGED
@@ -1,48 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: invisible_captcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.7.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Marc Anguera Insa
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-10-22 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
14
|
+
name: rails
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
28
|
+
name: rspec-rails
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version: '
|
33
|
+
version: '3.1'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version: '
|
40
|
+
version: '3.1'
|
46
41
|
description: Simple spam protection for Rails applications using honeypot strategy
|
47
42
|
for better user experience.
|
48
43
|
email:
|
@@ -51,41 +46,122 @@ executables: []
|
|
51
46
|
extensions: []
|
52
47
|
extra_rdoc_files: []
|
53
48
|
files:
|
54
|
-
- .gitignore
|
49
|
+
- ".gitignore"
|
50
|
+
- ".travis.yml"
|
55
51
|
- Gemfile
|
56
52
|
- LICENSE
|
57
53
|
- README.md
|
58
54
|
- Rakefile
|
59
55
|
- invisible_captcha.gemspec
|
60
56
|
- lib/invisible_captcha.rb
|
61
|
-
- lib/invisible_captcha/
|
57
|
+
- lib/invisible_captcha/controller_ext.rb
|
62
58
|
- lib/invisible_captcha/form_helpers.rb
|
59
|
+
- lib/invisible_captcha/railtie.rb
|
63
60
|
- lib/invisible_captcha/validator.rb
|
64
61
|
- lib/invisible_captcha/version.rb
|
65
62
|
- lib/invisible_captcha/view_helpers.rb
|
63
|
+
- spec/controllers_spec.rb
|
64
|
+
- spec/dummy/README.md
|
65
|
+
- spec/dummy/Rakefile
|
66
|
+
- spec/dummy/app/assets/javascripts/application.js
|
67
|
+
- spec/dummy/app/assets/stylesheets/application.css
|
68
|
+
- spec/dummy/app/controllers/application_controller.rb
|
69
|
+
- spec/dummy/app/controllers/topics_controller.rb
|
70
|
+
- spec/dummy/app/helpers/application_helper.rb
|
71
|
+
- spec/dummy/app/mailers/.gitkeep
|
72
|
+
- spec/dummy/app/models/.gitkeep
|
73
|
+
- spec/dummy/app/models/topic.rb
|
74
|
+
- spec/dummy/app/views/layouts/application.html.erb
|
75
|
+
- spec/dummy/app/views/topics/new.html.erb
|
76
|
+
- spec/dummy/config.ru
|
77
|
+
- spec/dummy/config/application.rb
|
78
|
+
- spec/dummy/config/boot.rb
|
79
|
+
- spec/dummy/config/environment.rb
|
80
|
+
- spec/dummy/config/environments/development.rb
|
81
|
+
- spec/dummy/config/environments/production.rb
|
82
|
+
- spec/dummy/config/environments/test.rb
|
83
|
+
- spec/dummy/config/initializers/backtrace_silencers.rb
|
84
|
+
- spec/dummy/config/initializers/inflections.rb
|
85
|
+
- spec/dummy/config/initializers/invisible_captcha.rb
|
86
|
+
- spec/dummy/config/initializers/mime_types.rb
|
87
|
+
- spec/dummy/config/initializers/secret_token.rb
|
88
|
+
- spec/dummy/config/initializers/session_store.rb
|
89
|
+
- spec/dummy/config/initializers/wrap_parameters.rb
|
90
|
+
- spec/dummy/config/locales/en.yml
|
91
|
+
- spec/dummy/config/routes.rb
|
92
|
+
- spec/dummy/lib/assets/.gitkeep
|
93
|
+
- spec/dummy/log/.gitkeep
|
94
|
+
- spec/dummy/public/404.html
|
95
|
+
- spec/dummy/public/422.html
|
96
|
+
- spec/dummy/public/500.html
|
97
|
+
- spec/dummy/public/favicon.ico
|
98
|
+
- spec/dummy/script/rails
|
99
|
+
- spec/helpers_spec.rb
|
100
|
+
- spec/invisible_captcha_spec.rb
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
- spec/validator_spec.rb
|
66
103
|
homepage: https://github.com/markets/invisible_captcha
|
67
104
|
licenses:
|
68
105
|
- MIT
|
106
|
+
metadata: {}
|
69
107
|
post_install_message:
|
70
108
|
rdoc_options: []
|
71
109
|
require_paths:
|
72
110
|
- lib
|
73
111
|
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
112
|
requirements:
|
76
|
-
- -
|
113
|
+
- - ">="
|
77
114
|
- !ruby/object:Gem::Version
|
78
115
|
version: '0'
|
79
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
-
none: false
|
81
117
|
requirements:
|
82
|
-
- -
|
118
|
+
- - ">="
|
83
119
|
- !ruby/object:Gem::Version
|
84
120
|
version: '0'
|
85
121
|
requirements: []
|
86
122
|
rubyforge_project:
|
87
|
-
rubygems_version:
|
123
|
+
rubygems_version: 2.2.2
|
88
124
|
signing_key:
|
89
|
-
specification_version:
|
125
|
+
specification_version: 4
|
90
126
|
summary: Simple honeypot protection for RoR apps
|
91
|
-
test_files:
|
127
|
+
test_files:
|
128
|
+
- spec/controllers_spec.rb
|
129
|
+
- spec/dummy/README.md
|
130
|
+
- spec/dummy/Rakefile
|
131
|
+
- spec/dummy/app/assets/javascripts/application.js
|
132
|
+
- spec/dummy/app/assets/stylesheets/application.css
|
133
|
+
- spec/dummy/app/controllers/application_controller.rb
|
134
|
+
- spec/dummy/app/controllers/topics_controller.rb
|
135
|
+
- spec/dummy/app/helpers/application_helper.rb
|
136
|
+
- spec/dummy/app/mailers/.gitkeep
|
137
|
+
- spec/dummy/app/models/.gitkeep
|
138
|
+
- spec/dummy/app/models/topic.rb
|
139
|
+
- spec/dummy/app/views/layouts/application.html.erb
|
140
|
+
- spec/dummy/app/views/topics/new.html.erb
|
141
|
+
- spec/dummy/config.ru
|
142
|
+
- spec/dummy/config/application.rb
|
143
|
+
- spec/dummy/config/boot.rb
|
144
|
+
- spec/dummy/config/environment.rb
|
145
|
+
- spec/dummy/config/environments/development.rb
|
146
|
+
- spec/dummy/config/environments/production.rb
|
147
|
+
- spec/dummy/config/environments/test.rb
|
148
|
+
- spec/dummy/config/initializers/backtrace_silencers.rb
|
149
|
+
- spec/dummy/config/initializers/inflections.rb
|
150
|
+
- spec/dummy/config/initializers/invisible_captcha.rb
|
151
|
+
- spec/dummy/config/initializers/mime_types.rb
|
152
|
+
- spec/dummy/config/initializers/secret_token.rb
|
153
|
+
- spec/dummy/config/initializers/session_store.rb
|
154
|
+
- spec/dummy/config/initializers/wrap_parameters.rb
|
155
|
+
- spec/dummy/config/locales/en.yml
|
156
|
+
- spec/dummy/config/routes.rb
|
157
|
+
- spec/dummy/lib/assets/.gitkeep
|
158
|
+
- spec/dummy/log/.gitkeep
|
159
|
+
- spec/dummy/public/404.html
|
160
|
+
- spec/dummy/public/422.html
|
161
|
+
- spec/dummy/public/500.html
|
162
|
+
- spec/dummy/public/favicon.ico
|
163
|
+
- spec/dummy/script/rails
|
164
|
+
- spec/helpers_spec.rb
|
165
|
+
- spec/invisible_captcha_spec.rb
|
166
|
+
- spec/spec_helper.rb
|
167
|
+
- spec/validator_spec.rb
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module InvisibleCaptcha
|
2
|
-
module ControllerMethods
|
3
|
-
|
4
|
-
def check_invisible_captcha
|
5
|
-
head 200 if invisible_captcha?
|
6
|
-
end
|
7
|
-
|
8
|
-
def invisible_captcha?(fake_resource = nil, fake_field = nil)
|
9
|
-
if fake_resource && fake_field
|
10
|
-
return true if params[fake_resource][fake_field].present?
|
11
|
-
else
|
12
|
-
InvisibleCaptcha.fake_fields.each do |field|
|
13
|
-
return true if params[field].present?
|
14
|
-
end
|
15
|
-
end
|
16
|
-
false
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
ActionController::Base.send :include, InvisibleCaptcha::ControllerMethods
|