Skip to content

Commit

Permalink
Some spammers are hip to the hidden field trick.
Browse files Browse the repository at this point in the history
Let's see if using a regular input with "display: none" is better.
  • Loading branch information
hardbap committed Feb 1, 2010
1 parent 3332e46 commit ec0bcbf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
7 changes: 4 additions & 3 deletions lib/trap_door.rb
@@ -1,6 +1,6 @@
module TrapDoor module TrapDoor
mattr_accessor :honeypot_field_name mattr_accessor :honeypot_field_name

def self.included(controller) def self.included(controller)
self.honeypot_field_name = honeypot_field_name || :affiliate_id self.honeypot_field_name = honeypot_field_name || :affiliate_id
controller.extend(ClassMethods) controller.extend(ClassMethods)
Expand All @@ -20,10 +20,11 @@ def check_params
redirect_to 'http://en.wikipedia.org/wiki/User:Mike_Rosoft/Spambot' unless params[honeypot_field_name.to_sym].blank? redirect_to 'http://en.wikipedia.org/wiki/User:Mike_Rosoft/Spambot' unless params[honeypot_field_name.to_sym].blank?
end end
end end

module TrapDoorHelper module TrapDoorHelper
def trap_door_field(options = {}) def trap_door_field(options = {})
hidden_field_tag(TrapDoor.honeypot_field_name, '', options) options = options.reverse_merge({:style => 'display:none;'})
text_field_tag(TrapDoor.honeypot_field_name, '', options)
end end
end end
end end
12 changes: 8 additions & 4 deletions test/trap_door_test.rb
Expand Up @@ -28,7 +28,7 @@ def setup
get :create get :create
assert_response :success assert_response :success
end end

test "should not redirect if honypot param is blank" do test "should not redirect if honypot param is blank" do
get :create, :affiliate_id => "" get :create, :affiliate_id => ""
assert_response :success assert_response :success
Expand All @@ -48,17 +48,21 @@ def setup


class TrapDoorHelperTest < ActionView::TestCase class TrapDoorHelperTest < ActionView::TestCase
tests TrapDoor::TrapDoorHelper tests TrapDoor::TrapDoorHelper

def setup def setup
TrapDoor.honeypot_field_name = :affiliate_id TrapDoor.honeypot_field_name = :affiliate_id
end end


test "should render the trap door field" do test "should render the trap door field" do
assert_dom_equal('<input name="affiliate_id" id="affiliate_id" value="" type="hidden" />', trap_door_field) assert_dom_equal('<input name="affiliate_id" id="affiliate_id" value="" type="text" style="display:none;" />', trap_door_field)
end end


test "should use the user defined honeypot field name" do test "should use the user defined honeypot field name" do
TrapDoor.honeypot_field_name = :spambot_id TrapDoor.honeypot_field_name = :spambot_id
assert_dom_equal('<input name="spambot_id" id="spambot_id" value="" type="hidden" />', trap_door_field) assert_dom_equal('<input name="spambot_id" id="spambot_id" value="" type="text" style="display:none;" />', trap_door_field)
end

test "should not override user supplied options" do
assert_dom_equal('<input name="affiliate_id" id="affiliate_id" value="" type="text" style="font:red;" />', trap_door_field(:style => 'font:red;'))
end end
end end

0 comments on commit ec0bcbf

Please sign in to comment.