Add disconnect_all_active_record! calls before forking in multiple specs for improved SQL connection handling safety
This commit is contained in:
@@ -68,6 +68,9 @@ RSpec.describe 'AutoRunEngine Test', run_on_browserstack: true do
|
||||
# Generate a token for the server to respond with
|
||||
@token = BeEF::Core::Crypto.api_token
|
||||
|
||||
# ***** IMPORTANT: close any and all AR/OTR connections before forking *****
|
||||
disconnect_all_active_record!
|
||||
|
||||
# Initiate server start-up
|
||||
@pids = fork do
|
||||
BeEF::API::Registrar.instance.fire(BeEF::API::Server, 'pre_http_start', http_hook_server)
|
||||
|
||||
@@ -63,6 +63,9 @@ RSpec.describe 'Browser Details Handler', run_on_browserstack: true do
|
||||
# Generate a token for the server to respond with
|
||||
@token = BeEF::Core::Crypto.api_token
|
||||
|
||||
# ***** IMPORTANT: close any and all AR/OTR connections before forking *****
|
||||
disconnect_all_active_record!
|
||||
|
||||
# Initiate server start-up
|
||||
@pids = fork do
|
||||
BeEF::API::Registrar.instance.fire(BeEF::API::Server, 'pre_http_start', http_hook_server)
|
||||
|
||||
@@ -12,6 +12,10 @@ RSpec.describe 'BeEF Dynamic Reconsturction' do
|
||||
@server = Thin::Server.new('127.0.0.1', @port.to_s, @rackApp)
|
||||
trap("INT") { @server.stop }
|
||||
trap("TERM") { @server.stop }
|
||||
|
||||
# ***** IMPORTANT: close any and all AR/OTR connections before forking *****
|
||||
disconnect_all_active_record!
|
||||
|
||||
@pid = fork do
|
||||
@server.start!
|
||||
end
|
||||
|
||||
@@ -12,6 +12,11 @@ RSpec.describe 'BeEF Redirector' do
|
||||
@server = Thin::Server.new('127.0.0.1', @port.to_s, @rackApp)
|
||||
trap("INT") { @server.stop }
|
||||
trap("TERM") { @server.stop }
|
||||
|
||||
|
||||
# ***** IMPORTANT: close any and all AR/OTR connections before forking *****
|
||||
disconnect_all_active_record!
|
||||
|
||||
@pid = fork do
|
||||
@server.start!
|
||||
end
|
||||
|
||||
@@ -59,6 +59,11 @@ RSpec.describe 'Browser hooking with Websockets', run_on_browserstack: true do
|
||||
http_hook_server.prepare
|
||||
# Generate a token for the server to respond with
|
||||
@token = BeEF::Core::Crypto.api_token
|
||||
|
||||
|
||||
# ***** IMPORTANT: close any and all AR/OTR connections before forking *****
|
||||
disconnect_all_active_record!
|
||||
|
||||
# Initiate server start-up
|
||||
@pids = fork do
|
||||
BeEF::API::Registrar.instance.fire(BeEF::API::Server, 'pre_http_start', http_hook_server)
|
||||
|
||||
@@ -60,6 +60,9 @@ RSpec.describe 'BeEF Debug Command Modules:', run_on_browserstack: true do
|
||||
# Generate a token for the server to respond with
|
||||
@token = BeEF::Core::Crypto.api_token
|
||||
|
||||
# ***** IMPORTANT: close any and all AR/OTR connections before forking *****
|
||||
disconnect_all_active_record!
|
||||
|
||||
# Initiate server start-up
|
||||
@pids = fork do
|
||||
BeEF::API::Registrar.instance.fire(BeEF::API::Server, 'pre_http_start', http_hook_server)
|
||||
|
||||
@@ -193,14 +193,20 @@ RSpec.configure do |config|
|
||||
|
||||
# --- HARD fork-safety: disconnect every pool/adapter we can find ---
|
||||
def disconnect_all_active_record!
|
||||
print_info "Entering disconnect_all_active_record!"
|
||||
if defined?(ActiveRecord::Base)
|
||||
# Disconnect every connection pool explicitly
|
||||
print_info "Disconnecting ActiveRecord connections"
|
||||
handler = ActiveRecord::Base.connection_handler
|
||||
handler.connection_pool_list.each { |pool| pool.disconnect! } if handler.respond_to?(:connection_pool_list)
|
||||
ActiveRecord::Base.clear_active_connections!
|
||||
ActiveRecord::Base.clear_all_connections!
|
||||
if handler.respond_to?(:connection_pool_list)
|
||||
print_info "Using connection_pool_list"
|
||||
handler.connection_pool_list.each { |pool| pool.disconnect! }
|
||||
elsif handler.respond_to?(:connection_pools)
|
||||
print_info "Using connection_pools"
|
||||
handler.connection_pools.each_value { |pool| pool.disconnect! }
|
||||
end
|
||||
else
|
||||
print_info "ActiveRecord::Base not defined"
|
||||
end
|
||||
OTR::ActiveRecord.disconnect! if defined?(OTR::ActiveRecord)
|
||||
end
|
||||
|
||||
def start_beef_server
|
||||
|
||||
Reference in New Issue
Block a user