#1# Copyright (c) 2006-2026 Wade Alcorn - [email protected]2# Browser Exploitation Framework (BeEF) - https://beefproject.com3# See the file 'doc/COPYING' for copying permission4#5# Helpers for unit specs of command modules (modules/*/module.rb).6# Use with stubbed config; no REST/API or real server.7#89module ModuleSpecHelper10#11# Build a command instance for testing post_execute (or other instance methods).12# Uses allocate so we avoid Command#initialize reading from config.13# Set @datastore before calling post_execute; results are stored in @results via save().14#15# @param klass [Class] The command module class (e.g. Test_beef_debug)16# @param datastore [Hash] Data to set on @datastore (simulates callback data)17# @return [Object] Instance with @datastore set; call post_execute then read instance_variable_get(:@results)18#19def build_command_instance(klass, datastore = {})20instance = klass.allocate21instance.instance_variable_set(:@datastore, datastore)22instance23end2425#26# Call post_execute on a command instance and return the saved results.27# Use after build_command_instance(klass, datastore).28#29# @param instance [Object] Command instance from build_command_instance30# @return [Hash, nil] The value passed to save() (stored in @results)31#32def run_post_execute(instance)33instance.post_execute34instance.instance_variable_get(:@results)35end3637#38# Call pre_send on a command instance (e.g. before sending the command to the hooked browser).39# Use after build_command_instance(klass, datastore). Stub AssetHandler, Configuration, etc. before calling.40#41# @param instance [Object] Command instance from build_command_instance42#43def run_pre_send(instance)44instance.pre_send45end46end4748RSpec.configure do |config|49config.include ModuleSpecHelper5051# Stub Kernel.sleep for all module specs so modules that call sleep52# (e.g. Irc_nat_pinning's post_execute sleep 30) don't slow the suite.53config.before(:each) do |example|54if example.metadata[:file_path]&.include?('spec/beef/modules')55allow(Kernel).to receive(:sleep)56end57end58end596061