Skip to content

Tests/improve core test coverage#3518

Open
jake-the-dev wants to merge 19 commits intobeefproject:masterfrom
jake-the-dev:tests/improve-core-test-coverage
Open

Tests/improve core test coverage#3518
jake-the-dev wants to merge 19 commits intobeefproject:masterfrom
jake-the-dev:tests/improve-core-test-coverage

Conversation

@jake-the-dev
Copy link
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
@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
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
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
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.

2 participants