Skip to content
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
905157e
TEST: gbmanager spec
jake-the-dev Jan 30, 2026
3287d3f
TEST: core main logger spec
jake-the-dev Jan 30, 2026
1b2bd10
TEST: core main constatns browsers spec
jake-the-dev Jan 30, 2026
fc10884
TEST: core main models specs
jake-the-dev Jan 30, 2026
a69423f
TEST: main autorun specs
jake-the-dev Jan 30, 2026
83d2b2f
TEST: main models command spec
jake-the-dev Jan 30, 2026
51afa04
TEST: main constants specs
jake-the-dev Jan 30, 2026
d27fba4
TEST: main constatns commandmodule spec
jake-the-dev Jan 30, 2026
dfce472
TEST: updates to base and crpto specs
jake-the-dev Jan 30, 2026
035f17a
TEST: core main various specs
jake-the-dev Jan 30, 2026
cad6fc9
TEST: core main server spec
jake-the-dev Jan 30, 2026
ee82349
TEST: more engine spec unit tests
jake-the-dev Jan 30, 2026
65395cd
TEST: more logger spec unit tests
jake-the-dev Jan 30, 2026
30ae29e
TEST: additional specs for command and commandline spec
jake-the-dev Jan 30, 2026
0ceb550
TEST: more server spec
jake-the-dev Jan 30, 2026
088b244
TEST: hookerbrowser and browserdetails spec
jake-the-dev Feb 2, 2026
2aec814
Merge remote-tracking branch 'origin/coverage-improvements' into test…
jake-the-dev Feb 2, 2026
e8427f0
TEST: modules/browser specs
jake-the-dev Feb 2, 2026
238922c
TEST: module/debug directory specs
jake-the-dev Feb 2, 2026
045b943
TEST: modules/chrome_extensions specs
jake-the-dev Feb 2, 2026
6ffc9cd
REMOVE: individual specs
jake-the-dev Feb 5, 2026
57c615d
ADD: module dynamic specs per section
jake-the-dev Feb 5, 2026
ad2fed5
UPDATE: simplecov config
jake-the-dev Feb 26, 2026
f0e47a8
FIX: unused variable
jake-the-dev Feb 27, 2026
bc80f8b
Merge branch 'master' into tests/extensions-modules
zinduolis Mar 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .bundle/config
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
---
BUNDLE_WITHOUT: "development:test"
BUNDLE_WITH: "geoip:ext_msf:ext_notifications:ext_dns:ext_qrcode"
3 changes: 3 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
--color
--require spec_helper
-I .
--order defined
--tag ~run_on_browserstack
--tag ~run_on_long_tests
32 changes: 32 additions & 0 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# SimpleCov configuration file
# This provides a cleaner alternative to configuring SimpleCov in spec_helper.rb

SimpleCov.configure do
# Basic filters
add_filter '/spec/'
add_filter '/config/'
add_filter '/test/'

# Group coverage by component
add_group 'Core', 'core'
add_group 'Extensions', 'extensions'
add_group 'Modules', 'modules'

# Track files based on coverage focus
if ENV['COVERAGE'] == 'core'
track_files 'core/**/*.rb'
elsif ENV['COVERAGE'] == 'extensions'
track_files 'extensions/**/*.rb'
elsif ENV['COVERAGE'] == 'modules'
track_files 'modules/**/*.rb'
else
# Default: track everything
track_files '{core,extensions,modules}/**/*.rb'
end

# Coverage thresholds
minimum_coverage 80 if ENV['CI']

# Formatters
formatter SimpleCov::Formatter::HTMLFormatter
end
76 changes: 73 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,82 @@
#
require 'rspec/core/rake_task'

task :default => ["short"]
task default: ['short']

# Run rspec with an explicit file list (avoids envs that only run 557).
# Note: when run with all 81 files, module specs load after extensions; the Dns stub in
# network_spec must not run before the real Dns extension (dns_spec) or you get "superclass mismatch".
desc 'Run short spec suite (all specs except browserstack/long)'
task :short do
short_files = Dir[File.join(Dir.pwd, 'spec', '**', '*_spec.rb')].sort
$stderr.puts "[rake short] spec files=#{short_files.size}"
abort '[rake short] Expected 81+ spec files; check you are in project root.' if short_files.size < 80
opts = [
'--tag', '~run_on_browserstack',
'--tag', '~run_on_long_tests'
]
ok = system('bundle', 'exec', 'rspec', *short_files, *opts)
abort 'rspec failed' unless ok
end

# Legacy namespace for backward compatibility
namespace :coverage do
task :modules => 'coverage_modules'
task :core => 'coverage_core'
task :extensions => 'coverage_extensions'
task :all => 'coverage'
end

# Base spec tasks
RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = 'spec/**/*_spec.rb'
t.rspec_opts = ['--tag', '~run_on_browserstack', '--tag', '~run_on_long_tests']
end

RSpec::Core::RakeTask.new(:spec_core) do |t|
t.pattern = 'spec/beef/core/**/*_spec.rb'
t.rspec_opts = ['--tag', '~run_on_browserstack', '--tag', '~run_on_long_tests']
end

RSpec::Core::RakeTask.new(:spec_extensions) do |t|
t.pattern = 'spec/beef/extensions/**/*_spec.rb'
t.rspec_opts = ['--tag', '~run_on_browserstack', '--tag', '~run_on_long_tests']
end

RSpec::Core::RakeTask.new(:short) do |task|
task.rspec_opts = ['--tag ~run_on_browserstack', '--tag ~run_on_long_tests']
RSpec::Core::RakeTask.new(:spec_modules) do |t|
t.pattern = 'spec/beef/modules/**/*_spec.rb'
t.rspec_opts = ['--tag', '~run_on_browserstack', '--tag', '~run_on_long_tests']
end

# Coverage tasks using environment variables for cleaner configuration
desc 'Run all specs with complete coverage tracking'
task :coverage do
ENV['COVERAGE'] = 'all'
Rake::Task['spec'].invoke
end

desc 'Run core specs with coverage'
task :coverage_core do
ENV['COVERAGE'] = 'core'
Rake::Task['spec_core'].invoke
end

desc 'Run extensions specs with coverage'
task :coverage_extensions do
ENV['COVERAGE'] = 'extensions'
Rake::Task['spec_extensions'].invoke
end

desc 'Run modules specs with coverage'
task :coverage_modules do
ENV['COVERAGE'] = 'modules'
Rake::Task['spec_modules'].invoke
end

# Alias for backward compatibility
task :coverage_complete => :coverage
task :coverage_all => :coverage

RSpec::Core::RakeTask.new(:long) do |task|
task.rspec_opts = ['--tag ~run_on_browserstack']
end
Expand Down
Binary file modified modules/host/hook_default_browser/bounce_to_ie_configured.pdf
Binary file not shown.
146 changes: 146 additions & 0 deletions spec/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# 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 configuration
- `spec/support/` - Test helpers and utilities

## Running Tests

### Basic Commands

```bash
# Run all tests (fast, no coverage)
bundle exec rake short
# or
bundle exec rspec spec/ --tag '~run_on_browserstack' --tag '~run_on_long_tests'

# Run specific component tests
bundle exec rspec spec/beef/core/
bundle exec rspec spec/beef/extensions/
bundle exec rspec spec/beef/modules/
```

### Coverage Commands

```bash
# Complete coverage (recommended)
bundle exec rake coverage
# or
COVERAGE=all bundle exec rspec spec/ --tag '~run_on_browserstack' --tag '~run_on_long_tests'

# Component-specific coverage
bundle exec rake coverage_core # Core only
bundle exec rake coverage_modules # Modules only
bundle exec rake coverage_extensions # Extensions only
```

### Legacy Commands (Still Supported)

```bash
# Old coverage commands still work
bundle exec rake coverage:modules
bundle exec rake coverage:all
bundle exec rake coverage_complete
```

## Architecture

### SimpleCov Configuration

- **Environment-based**: Uses `COVERAGE=core|modules|extensions|all` environment variable
- **Grouped 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**: `BeefTestConfig` module provides test data instead of global constants
- **Component 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 coverage `coverage*` tasks
- **Environment variables**: Coverage controlled via `COVERAGE` env var
- **No sequential execution**: Single test runs with proper filtering
- **Backward compatibility**: Old task names still work

## Key Improvements

### ✅ **Eliminated Global Constants**
- Replaced `BRANCH_COVERAGE` constants with centralized `BeefTestConfig` module
- No more "already initialized constant" warnings

### ✅ **Simplified Coverage Logic**
- Cleaner filtering using `track_files` instead of complex `add_filter` logic
- Environment variable `COVERAGE` instead of `COVERAGE_FOCUS`

### ✅ **Better Test Organization**
- Centralized test configuration in `BeefTestConfig`
- Component-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 `.simplecov` config file (standard practice)
- Follows RSpec best practices
- Better separation of concerns

## Coverage Focus Areas

- **core**: Framework core functionality
- **extensions**: Extension modules
- **modules**: Command modules (main focus)
- **all**: Complete coverage across all areas

## Troubleshooting

### Common Issues

1. **"already initialized constant" warnings**
- Fixed by using centralized config instead of global constants

2. **Low coverage percentages**
- Use `COVERAGE=all` for complete coverage
- Ensure realistic test data triggers conditional paths

3. **Test failures**
- Check that mocks are properly configured
- Verify test data matches module expectations

### Debug Commands

```bash
# Run with debug output
bundle exec rspec --format documentation

# Run single test file
bundle exec rspec spec/beef/modules/browser/browser_spec.rb

# Check coverage report
open coverage/index.html
```

## Contributing

When adding new tests:

1. Use `BeefTestConfig.branch_coverage_for(:component)` for branch test data
2. Add realistic datastore values that trigger conditional logic
3. Mock external dependencies (database, network, etc.)
4. Follow existing patterns for consistency
Loading
Loading