leshill-bouncy_bots 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -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.
data/README.textile ADDED
@@ -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.
data/Rakefile ADDED
@@ -0,0 +1,47 @@
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.homepage = "http://github.com/leshill/bouncy_bots"
10
+ gem.authors = ["Les Hill, Desi McAdam"]
11
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
12
+ end
13
+
14
+ rescue LoadError
15
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
16
+ end
17
+
18
+ require 'spec/rake/spectask'
19
+ Spec::Rake::SpecTask.new(:spec) do |spec|
20
+ spec.libs << 'lib' << 'spec'
21
+ spec.spec_files = FileList['spec/**/*_spec.rb']
22
+ end
23
+
24
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
25
+ spec.libs << 'lib' << 'spec'
26
+ spec.pattern = 'spec/**/*_spec.rb'
27
+ spec.rcov = true
28
+ end
29
+
30
+
31
+ task :default => :spec
32
+
33
+ require 'rake/rdoctask'
34
+ Rake::RDocTask.new do |rdoc|
35
+ if File.exist?('VERSION.yml')
36
+ config = YAML.load(File.read('VERSION.yml'))
37
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
38
+ else
39
+ version = ""
40
+ end
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "bouncy_bots #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
47
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,47 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{bouncy_bots}
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Les Hill, Desi McAdam"]
9
+ s.date = %q{2009-07-02}
10
+ s.extra_rdoc_files = [
11
+ "LICENSE",
12
+ "README.textile"
13
+ ]
14
+ s.files = [
15
+ ".document",
16
+ ".gitignore",
17
+ "LICENSE",
18
+ "README.textile",
19
+ "Rakefile",
20
+ "VERSION",
21
+ "bouncy_bots.gemspec",
22
+ "lib/bouncy_bots.rb",
23
+ "lib/bouncy_bots/form_builder_ext.rb",
24
+ "spec/bouncy_bots_spec.rb",
25
+ "spec/spec_helper.rb"
26
+ ]
27
+ s.has_rdoc = true
28
+ s.homepage = %q{http://github.com/leshill/bouncy_bots}
29
+ s.rdoc_options = ["--charset=UTF-8"]
30
+ s.require_paths = ["lib"]
31
+ s.rubygems_version = %q{1.3.1}
32
+ s.summary = %q{Simple negative captcha for Rails}
33
+ s.test_files = [
34
+ "spec/bouncy_bots_spec.rb",
35
+ "spec/spec_helper.rb"
36
+ ]
37
+
38
+ if s.respond_to? :specification_version then
39
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
40
+ s.specification_version = 2
41
+
42
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
43
+ else
44
+ end
45
+ else
46
+ end
47
+ end
@@ -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 File.expand_path(File.dirname(__FILE__) + '/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,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 'activesupport'
8
+
9
+ Spec::Runner.configure do |config|
10
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: leshill-bouncy_bots
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Les Hill, Desi McAdam
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-02 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email:
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.textile
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.textile
30
+ - Rakefile
31
+ - VERSION
32
+ - bouncy_bots.gemspec
33
+ - lib/bouncy_bots.rb
34
+ - lib/bouncy_bots/form_builder_ext.rb
35
+ - spec/bouncy_bots_spec.rb
36
+ - spec/spec_helper.rb
37
+ has_rdoc: true
38
+ homepage: http://github.com/leshill/bouncy_bots
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --charset=UTF-8
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.2.0
60
+ signing_key:
61
+ specification_version: 2
62
+ summary: Simple negative captcha for Rails
63
+ test_files:
64
+ - spec/bouncy_bots_spec.rb
65
+ - spec/spec_helper.rb