Skip to content

test: add unit coverage for Phase 1 modules (cloudflare, messenger, rblcheck, servercheck, serverstats)#10

Open
zeroth-blip wants to merge 8 commits into
Black-HOST:mainfrom
zeroth-blip:rework/csf-testability
Open

test: add unit coverage for Phase 1 modules (cloudflare, messenger, rblcheck, servercheck, serverstats)#10
zeroth-blip wants to merge 8 commits into
Black-HOST:mainfrom
zeroth-blip:rework/csf-testability

Conversation

@zeroth-blip
Copy link
Copy Markdown
Contributor

@zeroth-blip zeroth-blip commented Apr 6, 2026

Summary

Pivot from invasive csf.pl refactor → additive unit test coverage.

The original commit (4d197db) restructured ~300 lines of csf.pl to introduce a testing seam (modulino + dispatch refactor). After review we decided that level of change in the entry point is too risky for the goal at hand and reverted it.

This PR now adds 5 new test files covering Phase 1 helper modules, with no changes to production code:

  • cloudflare.tConfigServer::CloudFlare
  • messenger.tConfigServer::Messenger
  • rblcheck.tConfigServer::RBLCheck
  • servercheck.tConfigServer::ServerCheck
  • serverstats.tConfigServer::ServerStats

Test results

Files=20, Tests=107, Result: PASS

All existing tests still green; +5 new test files, +107 total assertions.

Notes for maintainers

  • Zero changes to csf.pl or any production code in this PR.
  • A separate, smaller seam-introduction PR for csf.pl can follow if/when there's appetite — happy to scope it tightly (e.g. one extracted sub at a time) so it's easier to review.

@UptimeEnforcer
Copy link
Copy Markdown
Member

@zeroth-blip thanks for the PR, reviewing it we noticed some changes in the core csf.pl script which we're trying to avoid for now due to the project restructuring.

Will you be able to refactor your unit test code, and make it similar to the current unit tests?

@zeroth-blip
Copy link
Copy Markdown
Contributor Author

Understood, I will look what I can do at first opportunity.
Perhaps you guys can build some kind of roadmap or milestones table, so we can know in which direction the project is headed?

Covers init() GD-absent fallback, charts_html() layout with and without
cc_lookups, and minmaxavg() observed through graphs_html() rendering
(MIN/MAX/AVG accumulation and per-bucket isolation across HOUR/DAY/WEEK/
MONTH timeframes).
Covers checktarget() target classification (country/ip_range/ip), getscope()
parsing of DOMAIN/DISABLE/ANY directives in csf.cloudflare, and the LWP
interaction surface of block(), whitelist(), and remove() (success body,
error status-line surfacing, and the empty-id remove branch).
Covers init() returning a blessed v2 instance without touching the v1/v3
side effects, and _read_request_line() against a fake client (plain LF
termination, CRLF stripping, and MAX_LINE_LENGTH cap behavior).
Covers report()'s externally observable behavior under non-verbose mode:
empty-IP set returns no failures and only the endoutput marker, a fresh
PUBLIC IP gets a "New ... (PUBLIC)" / "Not Checked" placeholder when no
cached result exists, and non-PUBLIC IPs are silently skipped. Mocks
ConfigServer::GetEthDev, slurp, and rbllookup; reloads the module between
calls to reset its file-scope output buffer.
The module's surface is dominated by hardcoded reads of /etc/csf, /proc,
/usr/local/cpanel, and shellouts to iptables/systemctl/chkconfig, all
captured into a file-scope output lexical. Without Phase-B refactor seams
this can only be smoke-tested. Asserts that the module loads cleanly,
exports the documented entry points, and that getportinfo() returns 0 for
out-of-range ports when /proc/net is available (skipped elsewhere).
@zeroth-blip zeroth-blip force-pushed the rework/csf-testability branch from 4d197db to 27e774b Compare May 25, 2026 08:27
@zeroth-blip zeroth-blip changed the title test: make csf.pl easier to unit test test: add unit coverage for Phase 1 modules (cloudflare, messenger, rblcheck, servercheck, serverstats) May 25, 2026
@zeroth-blip
Copy link
Copy Markdown
Contributor Author

zeroth-blip commented May 25, 2026

@UptimeEnforcer — heads up: after a deeper review I decided the original csf.pl refactor was too invasive (touched ~300 lines of the entry point just to enable testing). I've reverted that commit and pivoted to additive test coverage instead: 5 new test files for cloudflare, messenger, rblcheck, servercheck, serverstats.

Full suite now at 20 files / 107 tests, all green. PR title + body updated to match.

A separate, smaller csf.pl seam-introduction PR can follow if/when there's appetite.

…w-perl

CloudFlare.pm has a top-level 'use LWP::UserAgent', which fails to compile
on CI runners (or any host) without libwww-perl installed. Pre-populate
$INC and provide minimal package stubs so the module loads in isolation;
each subtest still overrides the relevant LWP::UserAgent method with a
local *glob assignment, so behaviour is unchanged.
Adds the higher-value messenger coverage that this fork was missing and
that fits the existing test infrastructure without invasive changes to
Messenger.pm:

  * module public surface: can('init'), can('start'), can('messengerv2'),
    $VERSION presence + numeric baseline check (catches accidental
    renames/regressions)
  * init(1) returns a blessed object once ConfigServer::GetEthDev is
    stubbed out (no real network probing)
  * init(3) returns a blessed object without dying when
    /var/lib/csf/ssl/ is not writable (CI runner case)
  * init(1) tolerates a populated RECAPTCHA_NAT list (spaces +
    multiple comma-separated entries)
  * init(1) tolerates MESSENGER6 + IPV6 enabled together
  * _read_request_line accepts a line of exactly MAX_LINE_LENGTH bytes
    terminated by LF (the upper-bound boundary case)

Subtests that introspect %ConfigServer::Messenger::config (cached config
matrices: DEBUG levels, MESSENGER_HTTPS_SKIPMAIL, RECAPTCHA_SITEKEY,
webserver type) are intentionally not added here: %config is a file-
lexical 'my' in this fork's Messenger.pm, so it cannot be read from a
test without an out-of-scope re-scoping change. Those checks effectively
exercise ConfigServer::Config, not Messenger, and belong in a separate
ConfigServer::Config test.

messenger.t: 4 subtests -> 10 subtests, 7 asserts -> 17 asserts.
…el installs

Keeps the NOTE generic about hardcoded install-prefix paths without
referencing a specific vendor by name.
@zeroth-blip zeroth-blip force-pushed the rework/csf-testability branch from 7f187d2 to 659808a Compare May 25, 2026 09:31
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