bouncy_bots 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Les Hill
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,49 @@
1
+ h1. Bouncy Bots!
2
+
3
+ A simple negative captcha for rails.
4
+
5
+ A negative captcha flips the normal captcha on its head, rather than asking humans identify themselves, we trick the bots into identifying themselves. We do this by placing honey pots in a form that are invisible to a human, but visible to a bot. When the bot submits the form, we look for the honey pot entries and discard the form submission if we find any.
6
+
7
+ h2. Installing Bouncy Bots!
8
+
9
+ Bouncy Bots! is available as a gem from github. Install the gem with the following command:
10
+
11
+ % sudo gem install --source http://gems.github.com/ leshill-bouncy_bots
12
+
13
+ After you have the gem installed, add a @config.gem@ line to your @environment.rb@ file:
14
+
15
+ config.gem 'leshill-bouncy_bots', :lib => 'bouncy_bots', :version => '>= 0.1.1'
16
+
17
+ h2. Using Bouncy Bots!
18
+
19
+ h3. Controllers
20
+
21
+ Use the @bounce_bots@ macro in your controllers to detect and bounce bots. The macro takes two parameters, the honey pot field name and the redirect path or url. For example, to check for the field @:blog_url@ and redirect bots to the @pages_path@ :
22
+
23
+ bounce_bots :blog_url, :pages_path
24
+
25
+ You can also pass the standard controller filter options such as @:only@ or @:except@ :
26
+
27
+ bounce_bots :blog_url, :pages_path, :only => [:create, :update]
28
+
29
+ h3. Views
30
+
31
+ In your form views, add the honey pot field. If you are using @form_tag@, you can use any form element, for example (using "haml":http://haml.hamptoncatlin.com/):
32
+
33
+ = text_field_tag :blog_url, nil, :class => 'long_required'
34
+
35
+ In your stylesheet, add a rule to 'hide' the field:
36
+
37
+ input.long_required { display:none; }
38
+
39
+ If you use @form_for@, there are two helpers to simplify making the honey pot.
40
+
41
+ = f.bounce_label 'Blog Url', :class => 'long_required'
42
+ %br
43
+ = f.bounce_field :class => 'long_required'
44
+
45
+ And that's it.
46
+
47
+ h2. Copyright
48
+
49
+ Copyright (c) 2009 Les Hill and Desi McAdam. See LICENSE for details.
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "bouncy_bots"
8
+ gem.summary = %Q{Simple negative captcha for Rails}
9
+ gem.description = %Q{Simple negative captcha for Rails}
10
+ gem.homepage = "http://github.com/leshill/bouncy_bots"
11
+ gem.email = "leshill@gmail.com"
12
+ gem.authors = ["Les Hill, Desi McAdam"]
13
+ gem.add_development_dependency "rspec", "= 1.3.0"
14
+ gem.add_development_dependency "activesupport", ">= 2.2"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.spec_opts = ['--options', "#{File.expand_path(File.dirname(__FILE__))}/spec/spec.opts"]
25
+ spec.libs << 'lib' << 'spec'
26
+ spec.spec_files = FileList['spec/**/*_spec.rb']
27
+ end
28
+
29
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
30
+ spec.spec_opts = ['--options', "#{File.expand_path(File.dirname(__FILE__))}/spec/spec.opts"]
31
+ spec.libs << 'lib' << 'spec'
32
+ spec.pattern = 'spec/**/*_spec.rb'
33
+ spec.rcov = true
34
+ end
35
+
36
+ task :spec => :check_dependencies
37
+
38
+ task :default => :spec
39
+
40
+ require 'rake/rdoctask'
41
+ Rake::RDocTask.new do |rdoc|
42
+ if File.exist?('VERSION.yml')
43
+ config = YAML.load(File.read('VERSION.yml'))
44
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
45
+ else
46
+ version = ""
47
+ end
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "bouncy_bots #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
@@ -0,0 +1,59 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{bouncy_bots}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Les Hill, Desi McAdam"]
12
+ s.date = %q{2010-03-20}
13
+ s.description = %q{Simple negative captcha for Rails}
14
+ s.email = %q{leshill@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.textile"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.textile",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "bouncy_bots.gemspec",
27
+ "lib/bouncy_bots.rb",
28
+ "lib/bouncy_bots/form_builder_ext.rb",
29
+ "spec/bouncy_bots_spec.rb",
30
+ "spec/spec.opts",
31
+ "spec/spec_helper.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/leshill/bouncy_bots}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.6}
37
+ s.summary = %q{Simple negative captcha for Rails}
38
+ s.test_files = [
39
+ "spec/bouncy_bots_spec.rb",
40
+ "spec/spec_helper.rb"
41
+ ]
42
+
43
+ if s.respond_to? :specification_version then
44
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
48
+ s.add_development_dependency(%q<rspec>, ["= 1.3.0"])
49
+ s.add_development_dependency(%q<activesupport>, [">= 2.2"])
50
+ else
51
+ s.add_dependency(%q<rspec>, ["= 1.3.0"])
52
+ s.add_dependency(%q<activesupport>, [">= 2.2"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<rspec>, ["= 1.3.0"])
56
+ s.add_dependency(%q<activesupport>, [">= 2.2"])
57
+ end
58
+ end
59
+
@@ -0,0 +1,52 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+
3
+ require 'bouncy_bots/form_builder_ext'
4
+
5
+ module BouncyBots
6
+ def self.included(base)
7
+ base.extend ClassMethods
8
+ end
9
+
10
+ module ClassMethods
11
+ def bounce_bots(field, to, filter_opts = {})
12
+ before_filter :bounce_bot, filter_opts
13
+
14
+ cattr_accessor :bounce_to
15
+ cattr_accessor :bounce_field
16
+ bouncy_settings(field, to)
17
+ end
18
+
19
+ protected
20
+
21
+ def bouncy_settings(field, to)
22
+ self.bounce_field = field
23
+ self.bounce_to = to
24
+ end
25
+ end
26
+
27
+ protected
28
+
29
+ def bounce_bot
30
+ bot_check = find_bounce_field(params)
31
+ redirect_to(send(bounce_to)) and return false unless bot_check.blank?
32
+ true
33
+ end
34
+
35
+ def find_bounce_field(hash)
36
+ if hash.has_key?(bounce_field)
37
+ return hash.delete(bounce_field)
38
+ else
39
+ hash.values.each do |value|
40
+ if value.kind_of?(Hash)
41
+ bounce = find_bounce_field(value)
42
+ return bounce unless bounce.nil?
43
+ end
44
+ end
45
+ return nil
46
+ end
47
+ end
48
+ end
49
+
50
+ if defined? ActionController
51
+ ActionController::Base.send(:include, BouncyBots)
52
+ end
@@ -0,0 +1,16 @@
1
+ module BouncyBots
2
+ module FormBuilderExt
3
+ def bounce_field(options = {})
4
+ ActionView::Helpers::InstanceTag.new(object_name, @template.controller.bounce_field, self, options.delete(:object)).to_input_field_tag("text", options)
5
+ end
6
+
7
+ def bounce_label(text = nil, options = {})
8
+ ActionView::Helpers::InstanceTag.new(object_name, @template.controller.bounce_field, self, options.delete(:object)).to_label_tag(text, options)
9
+ end
10
+ end
11
+ end
12
+
13
+ if defined? ActionView
14
+ ActionView::Helpers::FormBuilder.send(:include, BouncyBots::FormBuilderExt)
15
+ end
16
+
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ class MacroTest
4
+ def self.before_filter(*args); end
5
+ end
6
+
7
+ class FilterTest
8
+ def self.before_filter(*args); end
9
+ def redirect_to(*args); end
10
+
11
+ include BouncyBots
12
+ bounce_bots :three, :bounce_dest
13
+
14
+ attr_accessor :params
15
+ end
16
+
17
+ describe "BouncyBots" do
18
+ before do
19
+ MacroTest.stub!(:bouncy_settings)
20
+ end
21
+
22
+ describe ".bounce_bots macro" do
23
+ it "sets the before filter" do
24
+ MacroTest.should_receive(:before_filter).with(:bounce_bot, {})
25
+ MacroTest.class_eval do
26
+ include BouncyBots
27
+ bounce_bots :three, :bounce_to
28
+ end
29
+ end
30
+
31
+ it "breaks out options" do
32
+ MacroTest.should_receive(:cattr_accessor).with(:bounce_to)
33
+ MacroTest.should_receive(:cattr_accessor).with(:bounce_field)
34
+ MacroTest.should_receive(:bouncy_settings).with(:three, :bounce_to)
35
+ MacroTest.class_eval do
36
+ include BouncyBots
37
+ bounce_bots :three, :bounce_to
38
+ end
39
+ end
40
+
41
+ it "passes on filter options" do
42
+ MacroTest.should_receive(:before_filter).with(:bounce_bot, {:only => :index})
43
+ MacroTest.class_eval do
44
+ include BouncyBots
45
+ bounce_bots :three, :bounce_to, :only => :index
46
+ end
47
+ end
48
+ end
49
+
50
+ describe "#bounce_bot" do
51
+ it "calls the bounce_to if the field is not blank" do
52
+ filter = FilterTest.new
53
+ filter.params = {:one => {:two => {:three => 'something'}}}
54
+ filter.should_receive(:bounce_dest).and_return('bounced')
55
+ filter.send(:bounce_bot)
56
+ end
57
+
58
+ it "does not call the bounce_to if the field is blank" do
59
+ filter = FilterTest.new
60
+ filter.params = {:one => {:two => {:three => nil}}}
61
+ filter.should_not_receive(:bounce_dest)
62
+ filter.send(:bounce_bot)
63
+ end
64
+
65
+ it "redirects if the field is not blank" do
66
+ filter = FilterTest.new
67
+ filter.params = {:one => {:two => {:two => 2, :three => 'something'}}}
68
+ filter.stub!(:bounce_dest).and_return('bounced')
69
+ filter.should_receive(:redirect_to).with('bounced')
70
+ filter.send(:bounce_bot)
71
+ end
72
+
73
+ it "returns true when the field does not exist" do
74
+ filter = FilterTest.new
75
+ filter.params = {:one => {:two => {:two => 2}}}
76
+ filter.send(:bounce_bot).should be_true
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format nested
@@ -0,0 +1,10 @@
1
+ require 'spec'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require 'bouncy_bots'
6
+
7
+ require 'active_support'
8
+
9
+ Spec::Runner.configure do |config|
10
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bouncy_bots
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
+ platform: ruby
11
+ authors:
12
+ - Les Hill, Desi McAdam
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-20 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 3
30
+ - 0
31
+ version: 1.3.0
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: activesupport
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 2
43
+ - 2
44
+ version: "2.2"
45
+ type: :development
46
+ version_requirements: *id002
47
+ description: Simple negative captcha for Rails
48
+ email: leshill@gmail.com
49
+ executables: []
50
+
51
+ extensions: []
52
+
53
+ extra_rdoc_files:
54
+ - LICENSE
55
+ - README.textile
56
+ files:
57
+ - .document
58
+ - .gitignore
59
+ - LICENSE
60
+ - README.textile
61
+ - Rakefile
62
+ - VERSION
63
+ - bouncy_bots.gemspec
64
+ - lib/bouncy_bots.rb
65
+ - lib/bouncy_bots/form_builder_ext.rb
66
+ - spec/bouncy_bots_spec.rb
67
+ - spec/spec.opts
68
+ - spec/spec_helper.rb
69
+ has_rdoc: true
70
+ homepage: http://github.com/leshill/bouncy_bots
71
+ licenses: []
72
+
73
+ post_install_message:
74
+ rdoc_options:
75
+ - --charset=UTF-8
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ requirements: []
93
+
94
+ rubyforge_project:
95
+ rubygems_version: 1.3.6
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Simple negative captcha for Rails
99
+ test_files:
100
+ - spec/bouncy_bots_spec.rb
101
+ - spec/spec_helper.rb