diff --git a/app/models/user.rb b/app/models/user.rb index c3f2d2500..89219d85a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -78,7 +78,6 @@ class User < ApplicationRecord validates_inclusion_of :per_page, in: (1..PostSets::Post::MAX_PER_PAGE) validates_confirmation_of :password validates_presence_of :comment_threshold - validate :validate_sock_puppets, :on => :create, :if => -> { Danbooru.config.enable_sock_puppet_validation? } before_validation :normalize_blacklisted_tags before_create :promote_to_admin_if_first_user before_create :customize_new_user @@ -623,14 +622,6 @@ class User < ApplicationRecord end end - concerning :SockPuppetMethods do - def validate_sock_puppets - if User.where(last_ip_addr: CurrentUser.ip_addr).where("created_at > ?", 1.day.ago).exists? - errors.add(:last_ip_addr, "was used recently for another account and cannot be reused for another day") - end - end - end - include BanMethods include PasswordMethods include AuthenticationMethods diff --git a/app/policies/user_policy.rb b/app/policies/user_policy.rb index 057141ab1..e9c0f7915 100644 --- a/app/policies/user_policy.rb +++ b/app/policies/user_policy.rb @@ -1,6 +1,6 @@ class UserPolicy < ApplicationPolicy def create? - true + !sockpuppet? end def update? @@ -27,6 +27,10 @@ class UserPolicy < ApplicationPolicy user.is_admin? || record.id == user.id || !record.enable_private_favorites? end + def sockpuppet? + User.where(last_ip_addr: request.remote_ip).where("created_at > ?", 1.day.ago).exists? + end + def permitted_attributes_for_create [:name, :password, :password_confirmation, { email_address_attributes: [:address] }] end diff --git a/config/danbooru_default_config.rb b/config/danbooru_default_config.rb index 09edcebe2..894532adb 100644 --- a/config/danbooru_default_config.rb +++ b/config/danbooru_default_config.rb @@ -443,11 +443,6 @@ module Danbooru false end - # disable this for tests - def enable_sock_puppet_validation? - true - end - # Enables recording of popular searches, missed searches, and post view # counts. Requires Reportbooru to be configured and running - see below. def enable_post_search_counts diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index 67a782d7e..a7adcaffc 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -170,14 +170,11 @@ class UsersControllerTest < ActionDispatch::IntegrationTest end context "with sockpuppet validation enabled" do - setup do - Danbooru.config.unstub(:enable_sock_puppet_validation?) - @user.update(last_ip_addr: "127.0.0.1") - end - should "not allow registering multiple accounts with the same IP" do assert_difference("User.count", 0) do + @user.update(last_ip_addr: "127.0.0.1") post users_path, params: {:user => {:name => "dupe", :password => "xxxxx1", :password_confirmation => "xxxxx1"}} + assert_response 403 end end end diff --git a/test/test_helper.rb b/test/test_helper.rb index bdc746fbf..6fafbaa57 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -69,7 +69,6 @@ class ActiveSupport::TestCase mock_popular_search_service! mock_missed_search_service! WebMock.allow_net_connect! - Danbooru.config.stubs(:enable_sock_puppet_validation?).returns(false) storage_manager = StorageManager::Local.new(base_dir: "#{Rails.root}/public/data/test") Danbooru.config.stubs(:storage_manager).returns(storage_manager) @@ -114,7 +113,6 @@ class ActionDispatch::IntegrationTest def setup super Socket.stubs(:gethostname).returns("www.example.com") - Danbooru.config.stubs(:enable_sock_puppet_validation?).returns(false) ActionDispatch::IntegrationTest.register_encoder :xml, response_parser: ->(body) { Nokogiri.XML(body) } end diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 68210932b..4ac415fe3 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -231,21 +231,6 @@ class UserTest < ActiveSupport::TestCase end end - context "that might be a sock puppet" do - setup do - @user = FactoryBot.create(:user, last_ip_addr: "127.0.0.2") - Danbooru.config.unstub(:enable_sock_puppet_validation?) - end - - should "not validate" do - CurrentUser.scoped(nil, "127.0.0.2") do - @user = FactoryBot.build(:user) - @user.save - assert_equal(["Last ip addr was used recently for another account and cannot be reused for another day"], @user.errors.full_messages) - end - end - end - context "when searched by name" do should "match wildcards" do user1 = FactoryBot.create(:user, :name => "foo")