Tests/improve core test coverage#3518
Conversation
…s/improve-core-test-coverage
| 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 | ||
|
|
There was a problem hiding this comment.
This had to be rewritten a little, was just a lil inconsistent.
|
@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. |
|
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 CodeThis PR creates 3 brand-new spec files (~560 lines total) that test source files PR #3482 deletes:
2. Redundant Model References to Deleted TablesThis PR's tests reference
PR #3482 deletes 3.
|
|
Stale pull request message |
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
left a comment
There was a problem hiding this comment.
The required updates have been made and now it's good to merge.
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.