From 32ac09ee480e6dc3197d0134c8d9796e1c90e66e Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 21 Dec 2017 21:59:57 -0600 Subject: [PATCH] Add test for registering sock puppet accounts. --- test/functional/users_controller_test.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index 70d1945dd..7bb0412cb 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -93,6 +93,22 @@ class UsersControllerTest < ActionController::TestCase assert_equal([], assigns(:user).errors.full_messages) end end + + should "not allow registering multiple accounts with the same IP" do + User.any_instance.unstub(:validate_sock_puppets) + request.env["REMOTE_ADDR"] = "1.2.3.4" + CurrentUser.user = nil + + post :create, {:user => {:name => "user", :password => "xxxxx1", :password_confirmation => "xxxxx1"}}, {} + session.clear + post :create, {:user => {:name => "dupe", :password => "xxxxx1", :password_confirmation => "xxxxx1"}}, {} + + assert_equal(true, User.where(name: "user").exists?) + assert_equal(false, User.where(name: "dupe").exists?) + + assert_equal(IPAddr.new("1.2.3.4"), User.find_by_name("user").last_ip_addr) + assert_match(/Sign up failed: Last ip addr was used recently/, flash[:notice]) + end end context "edit action" do