BeEF Test Suite
This directory contains the BeEF test suite using RSpec and SimpleCov for comprehensive testing and coverage reporting.
Setup
Prerequisites
Ruby 3.0+
Bundler
All gems from
Gemfile
Configuration Files
spec/spec_helper.rb- Main test configuration.simplecov- Coverage configurationspec/support/- Test helpers and utilities
Running Tests
Basic Commands
Coverage Commands
Legacy Commands (Still Supported)
Architecture
SimpleCov Configuration
Environment-based: Uses
COVERAGE=core|modules|extensions|allenvironment variableGrouped reporting: Separate groups for Core, Extensions, and Modules
Filtered tracking: Only tracks relevant files based on focus area
HTML reports: Generated in
coverage/directory
Test Organization
Centralized config:
BeefTestConfigmodule provides test data instead of global constantsComponent isolation: Each component (core/extensions/modules) has dedicated specs
Branch coverage: Realistic test data for conditional logic testing
Mock management: Proper mocking of external dependencies
Rake Tasks
Clean separation: Base
spec*tasks vs coveragecoverage*tasksEnvironment variables: Coverage controlled via
COVERAGEenv varNo sequential execution: Single test runs with proper filtering
Backward compatibility: Old task names still work
Key Improvements
✅ Eliminated Global Constant Collisions
Branch-coverage data for the dynamic module spec loaders lives in
BeefTestConfig.branch_coverage_for(:component)(inspec/spec_helper.rb).Each module spec file pulls its own component (
:browser,:exploits,:host,:misc,:network,:social_engineering) into a uniquely-named local constant (e.g.BRANCH_COVERAGE_HOST), so loading the full suite no longer triggers "already initialized constant" warnings or silently overwrites data.
✅ Simplified Coverage Logic
Cleaner filtering using
track_filesinstead of complexadd_filterlogicEnvironment variable
COVERAGEinstead ofCOVERAGE_FOCUS
✅ Better Test Organization
Centralized test configuration in
BeefTestConfigComponent-specific test data loading
Reduced code duplication
✅ Cleaner Rake Tasks
Single execution instead of sequential runs
Proper environment variable usage
Backward compatibility maintained
✅ Standard Patterns
Uses
.simplecovconfig file (standard practice)Follows RSpec best practices
Better separation of concerns
Module Spec Pattern (dynamic loaders)
Specs under spec/beef/modules/**/<category>_spec.rb walk every modules/<category>/**/module.rb file and generate a RSpec.describe block per class. They cover:
.optionsreturns anArray(when defined)#pre_sendruns without raising (when defined)#post_executeruns without raising (when defined)An extra
#post_executeexample with a realistic datastore for any module listed inBeefTestConfig.branch_coverage_for(:category)
Trade-off: this is a coverage-driving baseline. The expect { ... }.not_to raise_error assertion catches load failures, missing constants, nil crashes, and undefined methods, but it does not assert behavioural correctness. Add targeted assertions for high-value modules (see the Wordpress_add_user and Test_get_variable examples in spec/beef/modules/misc/misc_spec.rb).
Coverage Focus Areas
core: Framework core functionality
extensions: Extension modules
modules: Command modules (main focus)
all: Complete coverage across all areas
Troubleshooting
Common Issues
"already initialized constant" warnings
Fixed by using centralized config instead of global constants
Low coverage percentages
Use
COVERAGE=allfor complete coverageEnsure realistic test data triggers conditional paths
Test failures
Check that mocks are properly configured
Verify test data matches module expectations
Debug Commands
Contributing
When adding new tests:
Use
BeefTestConfig.branch_coverage_for(:component)for branch test dataAdd realistic datastore values that trigger conditional logic
Mock external dependencies (database, network, etc.)
Follow existing patterns for consistency