users: move sockpuppet detection from model to controller.

This commit is contained in:
evazion
2020-03-24 18:41:27 -05:00
parent 50b0b79891
commit cbd713dea8
6 changed files with 7 additions and 37 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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")