Skip to content

Tests/improve core test coverage#3518

Merged
zinduolis merged 21 commits into
beefproject:masterfrom
jake-the-dev:tests/improve-core-test-coverage
May 22, 2026
Merged

Tests/improve core test coverage#3518
zinduolis merged 21 commits into
beefproject:masterfrom
jake-the-dev:tests/improve-core-test-coverage

Conversation

@jake-the-dev
Copy link
Copy Markdown
Collaborator

Category

Tests

Feature/Issue Description

Q: Please give a brief summary of your feature/fix
A: This PR introduces round 2 of test coverage for the /core feature set.
This improves coverage from 56.72% to 68.07% - consider that this PR is 2000 lines it's looking increasingly more difficult to get this test coverage (for /core) higher.

Why the rest of core coverage is hard to improve

The remaining code is either bound to DB/server/sockets, needs refactors to unit-test cleanly, or is low-value.
Autorun engine: Rule matching and execution are tied to the DB (Rule, Command, Execution, HookedBrowser). Covering them means heavy stubbing or real DB/server, both brittle.
Handlers: HTTP/session and subnet logic depend on real-looking requests and config; more coverage needs many mocks and setup.
Websocket: EventMachine and real sockets; only really testable with a running server or by stubbing the whole stack.
Server / network stack: Some branches (e.g. SSL, cert checks) only run at startup or with a live request pipeline.
Loader / bootstrap / console: Mostly requires and CLI output; low value to cover.

Q: Give a technical rundown of what you have changed (if applicable)
A: Continued from coverage-improvements, this covers the remaining /core files with unit tests.

Test Cases

Q: Describe your test cases, what you have covered and if there are any use cases that still need addressing.
A: Unit tests for /core section logic.

@jake-the-dev jake-the-dev temporarily deployed to Integrate Pull Request February 26, 2026 06:56 — with GitHub Actions Inactive
@jake-the-dev jake-the-dev marked this pull request as draft February 26, 2026 06:56
Comment thread spec/beef/core/main/models/command_spec.rb Fixed
@jake-the-dev jake-the-dev temporarily deployed to Integrate Pull Request February 27, 2026 01:40 — with GitHub Actions Inactive
Comment on lines +152 to +157
it 'returns false when no legacy UA includes the browser type' do
allow(BeEF::Core::Models::LegacyBrowserUserAgents).to receive(:user_agents).and_return([])

user_agent = 'Chrome/91.0'
browser_type = user_agent.split(' ').last

matched = false
BeEF::Core::Models::LegacyBrowserUserAgents.user_agents.each do |ua_string|
matched = true if ua_string.include?(browser_type)
end

expect(matched).to be false

expect(handler.confirm_browser_user_agent('Mozilla/5.0 Chrome/91.0')).to be false
end

Copy link
Copy Markdown
Collaborator Author

@jake-the-dev jake-the-dev Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This had to be rewritten a little, was just a lil inconsistent.

@jake-the-dev jake-the-dev marked this pull request as ready for review February 27, 2026 02:06
@jake-the-dev
Copy link
Copy Markdown
Collaborator Author

@zinduolis if you wouldn't mind have a look over these new tests and merging if you're happy with it. Same as before, just a bunch of unit tests for coverage. Thanks mate.

@zinduolis zinduolis added the safe_to_test Label to trigger tests on PR label Mar 2, 2026
@github-actions github-actions Bot removed the safe_to_test Label to trigger tests on PR label Mar 2, 2026
@jake-the-dev jake-the-dev self-assigned this Mar 2, 2026
@zinduolis zinduolis removed their assignment Mar 6, 2026
@zinduolis zinduolis self-requested a review March 6, 2026 09:18
@zinduolis zinduolis added the safe_to_test Label to trigger tests on PR label Mar 6, 2026
@github-actions github-actions Bot removed the safe_to_test Label to trigger tests on PR label Mar 6, 2026
@zinduolis
Copy link
Copy Markdown
Contributor

Thanks, @jake-the-dev , for this PR. I'm looking at it and will be adding comments. Here's the first one.

🔴 Contradictions with PR #3482 (ARE Removal)

PR #3482 by kaitozaw (opened Dec 29, 2025, approved with required changes, not yet merged) removes the entire Auto-Run Engine.

1. Redundant Test Files for Deleted Source Code

This PR creates 3 brand-new spec files (~560 lines total) that test source files PR #3482 deletes:

PR #3518 Adds PR #3482 Deletes
spec/beef/core/main/autorun_engine/engine_spec.rb (359 lines) core/main/autorun_engine/engine.rb (590 lines)
spec/beef/core/main/autorun_engine/parser_spec.rb (119 lines) core/main/autorun_engine/parser.rb (82 lines)
spec/beef/core/main/autorun_engine/rule_loader_spec.rb (83 lines) core/main/autorun_engine/rule_loader.rb (220 lines)

2. Redundant Model References to Deleted Tables

This PR's tests reference BeEF::Core::Models::Rule across multiple files:

  • engine_spec.rballow(BeEF::Core::Models::Rule).to receive(:all), receive(:find)
  • rule_loader_spec.rbBeEF::Core::Models::Rule.create!(...) (writes to rules table)

PR #3482 deletes core/main/models/rule.rb and core/main/models/execution.rb, and adds migration 026_remove_autorun_tables.rb dropping both tables.

3. browserdetails.rb Conflict

Both PRs touch core/main/handlers/browserdetails.rb:

  • PR Fixes issue/remove-ARE (#3475) #3482 removes the ARE trigger at lines 561-563 (find_and_run_all_matching_rules_for_zombie)
  • This PR adds 153 lines of tests for browserdetails_spec.rb including filter-failure branches

These aren't directly contradictory (tests vs. source), but they will generate merge conflicts on the spec file since both modify adjacent areas.

4. Existing ARE Spec File

PR #3482 already deletes spec/beef/core/main/autorun_engine/autorun_engine_spec.rb. This PR adds 3 new spec files in the same directory. This means the autorun_engine/ spec directory would be recreated by this PR after PR #3482 removes it.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 4, 2026

Stale pull request message

@zinduolis zinduolis added safe_to_test Label to trigger tests on PR and removed no-pr-activity labels May 22, 2026
@github-actions github-actions Bot removed the safe_to_test Label to trigger tests on PR label May 22, 2026
PR beefproject#3482 deleted the AutorunEngine source code (engine.rb, parser.rb,
rule_loader.rb) along with the Rule and Execution models. The three new
spec files added by this PR were testing classes that no longer exist
on master, so they would fail at load time once beefproject#3482 merged.

Also drop a leftover BeEF::Core::Models::Execution stub in
hookedbrowsers_spec.rb — the handler no longer queries pending ARE
executions, so the stub is dead.

Removed:
  spec/beef/core/main/autorun_engine/engine_spec.rb       (359 lines)
  spec/beef/core/main/autorun_engine/parser_spec.rb       (119 lines)
  spec/beef/core/main/autorun_engine/rule_loader_spec.rb  ( 83 lines)

Modified:
  spec/beef/core/main/handlers/hookedbrowsers_spec.rb (-1 dead stub)
@zinduolis zinduolis added the safe_to_test Label to trigger tests on PR label May 22, 2026
@github-actions github-actions Bot removed the safe_to_test Label to trigger tests on PR label May 22, 2026
Copy link
Copy Markdown
Contributor

@zinduolis zinduolis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The required updates have been made and now it's good to merge.

@zinduolis zinduolis merged commit 25c79a2 into beefproject:master May 22, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants