Testing Strategy and Execution Guide (Testing Guide)
This document describes the project's test layering strategy, the coverage of each test file, and how to run the full test suite locally.
1. Test Prerequisites
Before running tests, make sure the following services are ready:
| Service | Address | Notes |
|---|---|---|
| PostgreSQL | localhost:5432 | Database: fulla_db / user: fulla_user / password: 123456 |
| Redis | localhost:6379 | Password: 123456 (consistent with config.json) |
Serialization warning: the full test suite (
full_test.bat/full-test.sh) and the benchmark stack (benchmarks/fulla/setup.sh) share port 5555 and the same PostgreSQL database. Never run them in parallel on one machine — start the benchmark setup only after the test suite (including its endpoint scripts) has fully finished, and vice versa.
Quick-start infrastructure: if you use Docker, you can start the postgres and redis containers separately:
docker run -d -p 5432:5432 -e POSTGRES_USER=fulla_user -e POSTGRES_PASSWORD=123456 -e POSTGRES_DB=fulla_db postgres:17-alpinedocker run -d -p 6379:6379 redis:7-alpine redis-server --requirepass 123456
2. Test Layering
Tests are compiled into two categories of executables:
-
Per-library gtest binaries (Domain layer, pure unit tests, no DB / no Drogon):
libs/common/test/fulla-common-test—ConfigManager,ErrorCatalog,Result, value objectslibs/common/testing/test/fulla-common-testing-test— deterministic verification of fake implementations (FakeClock/FakeCryptoProvider/FakeLogger, etc.)libs/oauth2/test/fulla-oauth2-test—TokenService/AuthorizationService/ClientService/JwkManager/Pkce/ScopeDecisionEngine/TokenCryptolibs/identity/test/fulla-identity-test—AuthService/MfaService/TotpUtils/SessionManager/WebAuthnService/social login (Google/WeChat/GitHub)- These use gtest (not
DROGON_TEST) and are registered as independent ctest entries by each lib'stest/CMakeLists.txtviagtest_discover_tests.
-
Main test binary
tests/fulla-tests(DROGON_TESTframework, contains all layers that require Drogon/DB):
| Level | Directory | Coverage | External dependencies |
|---|---|---|---|
| Level 1 — Unit tests | tests/unit/ (config/, error/, utils/, validation/, plugin/, schema/, subject/, initorder/) | Pure logic: error envelopes, password hashing, PKCE/CryptoUtils, RuleSet validation, config loading, OpenAPI generation | None |
| Level 2 — Contract tests | tests/contract/ | Repository contract consistency across backends (Postgres/Redis/Memory): IClientRepository/IGrantRepository/ITokenRepository/IConsentRepository/IUserRepository | Memory always runs; Postgres/Redis are automatically skipped when getPostgresClientOrNull()/getRedisClientOrNull() return null |
| Level 3 — Integration tests | tests/integration/ (auth/, token/, storage/, concurrency/, error/, plugin/) | Full business flows, concurrency races, error envelopes, plugin assembly | Postgres / Redis (in memory-only mode -DFULLA_MEMORY_TESTS_ONLY=ON, the Memory subset runs) |
| Level 4 — Security tests | tests/security/ | SQL injection, XSS, command injection, CORS, token security, rate limiting | Postgres / Redis |
| Level 5 — E2E/functional | tests/e2e-backend/, tests/performance/ | Complete OAuth2 flows, performance benchmarks | Postgres + Redis + Drogon App |
Memory mode: configuring
-DFULLA_MEMORY_TESTS_ONLY=ONlets the full suite run without an external DB (Postgres/Redis tests are automatically skipped) — this is how Windows CI does it.
For security test case counts, functional test case counts, and coverage lists, see the header comments of the test files in each directory; this section no longer hardcodes specific counts (counts grow with each iteration — the measured statistics in §7 are authoritative).
DROGON_TEST assertion style — bare boolean operators are forbidden inside CHECK/REQUIRE [#MUST]
drogon's CHECK/REQUIRE are macros, not functions: CHECK_INTERNAL__ expands the expression to (drogon::test::internal::Decomposer() <= expr), and macro argument substitution adds no parentheses, so a bare a || b (or a && b) re-associates into (Decomposer() <= a) || b — the result is silently wrong, with symptoms that look like "assertions randomly failing". Real case (PR #68 debugging): CHECK(body.isMember("error") || body.isMember("code")) failed, even though the raw body printed by LOG_INFO clearly contained the error key.
Rule: whenever ||/&& appears in the top-level argument of CHECK(...)/REQUIRE(...), one of the following must hold:
// ✅ Split into two assertions (preferred — more precise failure messages)
CHECK(body.isMember("error"));
CHECK(body.isMember("code"));
// ✅ Wrap the whole expression in parentheses (outer parentheses bind the chained expression as a single operand to <=)
CHECK((a != std::string::npos || b != std::string::npos));
// ✅ Existing repo precedent: explicit (bool) cast (tests/e2e-backend/oauth2_flows/FunctionalTest.cc)
CHECK((bool)(response.find("code=") != std::string::npos ||
response.find("error") != std::string::npos));
// ❌ Forbidden: bare top-level boolean chain (semantics broken after macro expansion)
CHECK(body.isMember("error") || body.isMember("code"));
Note: operators nested inside call/subscript/sub-expression parentheses (e.g. CHECK(f(a || b)), CHECK(x == (a || b))) are unaffected — they are evaluated before being bound to <=. The CHECK_THROWS/REQUIRE_THROWS family goes through the EVAL__ path and is also unaffected.
CI enforcement: tools/test/scripts/drogon_macro_bool_check.py scans the tests/ tree and fails on violations (a static-checks step, alongside the naming-convention check); --selftest can self-verify.
Level 4 details — Security Tests
| Test file | Coverage |
|---|---|
SecurityTest.cc | SQL injection, XSS, command injection, input validation, CORS, token security, rate limiting, health-check security |
Coverage highlights: input validation (injection/length/null values), authentication and authorization (invalid credentials, rate limiting), CORS in both directions, sensitive-data transmission, token security (invalid/missing authorization codes and refresh tokens), security headers (including HSTS), brute-force protection, health-check information leakage.
Level 5 details — E2E / Functional Tests
| Test file | Coverage | Dependencies |
|---|---|---|
IntegrationE2ETest.cc | Simulates the complete OAuth2 authorization code flow: HTTP request → authorize → login → token exchange → UserInfo verification | Postgres + Redis + a running Drogon App |
FunctionalTest.cc | Complete OAuth2 flows, error handling, UTF-8/Emoji characters, health checks, RBAC, token lifecycle, input validation, rate limiting | Postgres + Redis |
Coverage highlights: the complete authorization code flow, error scenarios, UTF-8/Emoji boundaries, RBAC unauthorized paths, token lifecycle exception paths, overlong input, rate-limit detection, endpoint availability.
Test case counts evolve with each version — the
ctest -Nmeasurement is authoritative (see §7 for the current full-suite baseline).
Level 6 details — RP Interop Smoke (tests/interop/)
Standard relying-party libraries drive fulla's authorization code + PKCE(S256) → token → userinfo → refresh → end-session chain in strict mode, from OUTSIDE the C++ test binaries — the v1.5.0 P0 exit gate ("three libraries, zero warnings") and the standing regression harness for later protocol work (PAR, resource indicators). A fourth driver runs a real browser through the same chain:
| Driver | Library / app | What it alone can see |
|---|---|---|
tests/interop/node/ | openid-client v6 (strict) | id_token signature/iss/aud/exp/nonce via JWKS, PKCE, state |
tests/interop/python/ | authlib | authorize-URL/token interop, refresh, userinfo scope gating |
tests/interop/go/ | coreos/go-oidc/v3 + x/oauth2 | IDToken.Verify, userinfo sub consistency |
examples/nextjs-demo/ (Playwright) | the reference web app via the TS SDK | cookies, redirects, the real login form — found the login-CSP form-action bug (v1.6.0) that json-mode drivers structurally cannot see |
- CI:
.github/workflows/interop.ymlbuilds the server, boots the stack and runs all drivers on every push tomaster/release/**(plus manual dispatch); it is deliberately NOT on the per-PR hot path. - Local run: see
tests/interop/README.mdin the repository (outside the docs tree, so not hyperlinked here) — the stack must be up and seeded (dev seeds:fulla-portalPUBLIC client,admin/admin).
3. How to Run
Option 1: via CTest (recommended)
# Run after the build completes (directory is build/<preset>; on Windows Release it is windows-msvc)
cd build\windows-msvc
ctest -C Release --output-on-failure --timeout 120
Output policy: by default only the logs of failed test cases and the final summary (
passed / failed / total) are printed. To see the full output of every test case (including passing ones), add--verbose(-V); for complete silence with only the summary line, add-Q.manage.sh test-backend -q/manage.ps1 test-backend -qis equivalent to-Q.
Option 2: run the test executable directly
The test executable automatically starts a Drogon App instance internally (synchronized via a semaphore in test_main.cc); there is no need to start the backend service manually.
cd build\windows-msvc\tests\Release
.\fulla-tests.exe
Option 3: use the manage scripts
manage.ps1 (Windows) / manage.sh (Linux/macOS) wraps the same build + test pipeline used by CI:
# Build and run the backend test suite (equivalent to manage.sh test-backend)
.\manage.ps1 test-backend
# Full loop: build + unit/integration tests + admin endpoint API tests
.\manage.ps1 full-test
# Run only the admin-endpoint / OAuth2-endpoint API scripts
.\manage.ps1 test-admin-endpoints
.\manage.ps1 test-oauth2-endpoints
The full-test pipeline: three execution layers (and what is deduplicated)
manage full-test (backed by scripts/backend/full_test.bat /
full-test.sh / full-test-docker.sh) stacks three layers. Knowing how they
overlap explains what a full run actually executes:
- ctest layer —
EndpointTests_OutOfProcess(labelEndpoint) is a regular ctest entry: it starts its own server, runs the 59 OAuth2 + 52 admin endpoint scripts against it, then stops it (tests/CMakeLists.txt). It reportsSKIP_RETURN_CODE=77when its environment (server binary / shell) is unusable. - Dual-config layer —
test.bat/test.shrun the entire ctest suite twice: once with the standardconfig.json(PostgreSQL) and once withconfig.ci.json(memory storage). This duplication is intentional — it is the release-confidence signal that both storage backends pass the same suite. - Manual endpoint layer — the pipeline's own "start server → run the
endpoint scripts → stop server" steps. Since layer 1 already runs the
same scripts in the same standard configuration, this layer is skipped
automatically when the ctest run's JUnit report
(
build/<preset>/Testing/junit-config-standard.xml, written bytest.bat/test.sh) provesEndpointTests_OutOfProcessran green in that invocation (#119). On any doubt — report missing, entry missing, skipped, or unreadable — the manual layer runs as before, so environments where the ctest entry bails out (77) keep their endpoint coverage path.
The same applies to the per-case Contract.* ctest entries: each is also
executed as part of the OAuth2Tests binary run. Their individual ctest
registrations exist only to provide a labeled entry point
(ctest -L Contract); they do not add a second execution of those cases
beyond the labeled entry.
4. Sample Test Output
All tests passed (N assertions in M tests)
If a failure occurs, the failed test name and assertion location are printed:
In test case SomeTestName
SomeTestFile.cc:63 FAILED:
CHECK(c.has_optional())
Common failure causes:
- Redis or PostgreSQL service not started → check that the services are reachable
- Redis password mismatch → check the
passwdfield inconfig.json - Database not initialized → run the migration scripts under
apps/server/migrations/(the backend also runs them automatically whenFULLA_AUTO_MIGRATE=true)
5. Tests in CI
On every push to master or PR, GitHub Actions CI automatically:
- Starts the Postgres and Redis service containers
- Initializes the database schema
- Builds the project
- Runs
ctest - Separately (NOT on the per-PR hot path): the RP interop smoke gate
(
interop.yml, see §2 Level 6) runs the three standard RP libraries plus the browser demo against the built server on every push tomaster/release/**
See the CI/CD Guide for details.
6. Test Reports
Historical security/functional test reports, bug status analyses, and connection-leak verification reports are process archives that were moved out of the repository as part of documentation governance (kept locally by maintainers). Current test status is defined by CI and the scope of this section:
- A fully green CI is the merge gate (three-platform matrix; see the CI/CD Guide).
- For security and functional coverage see the §2 Level 4/5 details; counts are authoritative per
ctest -N. - Actionable findings from the historical reports (e.g. security defects found in the April snapshot) have been fixed and preserved as regression test cases.
7. Test Coverage Summary
Overall test status
The numbers below are measured statistics (Windows MSVC Release build, no external DB, Postgres/Redis tests skipped). In an environment with Postgres+Redis (e.g. Linux CI or local WSL+Docker), the skipped contract/integration tests activate and the ctest entry count increases further.
| Test source | Passed | Failed | Total | Pass rate |
|---|---|---|---|---|
Per-library gtest binaries (2026-06 baseline snapshot; the current full ctest count is 501 — the ctest -N measurement is authoritative) | 364 | 0 | 364 | 100% |
| Main test binary ctest entries (including the Contract label + the full OAuth2Tests run) | 450 | 0 | 450 | 100% |
Note: the two rows overlap — the main binary contains all
DROGON_TESTunit/integration tests (run as a singleOAuth2Testsentry), while the per-library gtest binaries are pure Domain-layer unit tests compiled and run independently. Of the450ctest entries, 84 carry theContractlabel (run them alone withctest -L Contract).
Code coverage
The table below is the CI ratchet baseline: the per-library floor that the Coverage workflow checks on every run (.github/workflows/coverage.yml → scripts/measure_coverage.py --ratchet tools/coverage/ratchet-baseline.json). The numbers are copied verbatim from tools/coverage/ratchet-baseline.json — the enforced reference, not a one-off local measurement. Data provenance: seeded 2026-09-05 from PR #176's own green CI run (gcov, Linux Debug linux-coverage preset, Postgres+Redis active, all 5 test binaries executed, ORM-generated models/ excluded).
| Library | Baseline line coverage | Notes |
|---|---|---|
| libs/common | 74.3% (364/490) | ErrorCatalog/ErrorTypes/ErrorContext/ConfigManager (driven by the per-lib gtest binary fulla-common-test) |
| libs/identity | 87.1% (1294/1485) | Auth/Mfa/WebAuthn/Social/Totp/Session |
| libs/storage-memory | 97.0% (421/434) | All methods of the Memory backend covered (the mandatory CI path) |
| libs/oauth2 | 88.8% (936/1054) | TokenService/AuthService/ClientService/JwkManager/Pkce |
| libs/storage-redis | 62.2% (705/1134) | Contract tests cover the main paths; Lua scripts and transaction CRUD still to be covered |
| libs/storage-postgres | 54.1% (1047/1936) | Contract tests cover the main paths; the remaining blind spots are transaction/error-fallback branches (require fault injection to trigger) |
| libs/drogon | 57.8% (6967/12056) | Controllers, admin layer and adapters (by far the largest denominator) |
| Overall (derived) | 63.1% (11734/18589) | Sum of the rows above. The baseline JSON holds only per-library entries; the ratchet compares per library, never the overall |
History: 48.5% (early 2026-08 baseline) → 57.9% overall measured 2026-08-07 at 7ba8068 (local WSL gcov; the numbers this table used to show) → 63.1% derived overall in the 2026-09-05 baseline. The per-library changes vs the old table (storage-redis 46.2% → 62.2%, storage-postgres 43.9% → 54.1%, drogon 53.5% → 57.8%, common 69.4% → 74.3%, while identity 96.9% → 87.1% and oauth2 92.1% → 88.8%) come with much larger denominators (identity 609 → 1485, oauth2 681 → 1054 instrumented lines): the CI coverage leg instruments the full stack and executes paths the local WSL measurement never reached, so both directions of movement are denominator effects, not coverage losses. The memory-mode techniques behind the social-OAuth/WebAuthn numbers are unchanged (
tests/common/SocialMockFixture.hfake injection; the GitHub happy-path freed fromgetDbClient()by theOAuth2Plugin::saveTokenPairstorage-abstraction refactor).
How the coverage ratchet works
- The baseline is a floor, not a target.
tools/coverage/ratchet-baseline.jsonrecordscovered / total / pctper library. On every Coverage run,measure_coverage.py --ratchetcompares each library's current percentage (truncated to 0.1pp) againstbaseline pct - 0.5pp(RATCHET_TOLERANCE_PP); falling below that floor fails the gate (exit 1). Libraries with fewer than 200 instrumented lines in the baseline (MIN_LINES) are exempt — currently none are. A baseline library missing from the run, or whose instrumented line count collapses belowMIN_LINES, also fails: lost instrumentation is never a pass. A library new to the run passes until it is baselined. - There is no automatic upward ratchet. To raise the floor after coverage improves, re-baseline deliberately: take the per-library numbers the workflow prints (locally,
measure_coverage.py --jsonemits exactly the baseline shape) and edittools/coverage/ratchet-baseline.jsonin a reviewed PR that states which tests raised the numbers. Lowering a baseline is the same edit and needs the same justification. - Seed mode: with the baseline file absent, the script prints the JSON to commit and exits 0 — that is how the current baseline was produced (PR #176).
- Gating status (two legs since 2026-11-07): the PR coverage leg stays advisory (
continue-on-error, 60 min — the gcov-instrumented server is 10–20× slower than Release and the full suite cannot finish there; a partial.gcdaset would read as false regressions, so treat a red ratchet there as a signal to investigate). The gate leg — push master + nightly (03:30 UTC), 150 min — requires suite completion and enforces the ratchet as a hard no-decrease gate: a regression fails within a day of merge. See the CI/CD Guide §3.9 for the measured basis and the sharding/dedicated-runner evaluation.
⚠ Measured coverage requires running all 5 test binaries
The measured numbers depend on all 5 test binaries being executed (running only the main binary fulla-tests misses the domain-layer coverage contributed by the 4 per-lib gtest binaries, and common would be underestimated at ~60%):
libs/common/test/fulla-common-test(40 test cases)libs/common/testing/test/fulla-common-testing-test(43 test cases)libs/identity/test/fulla-identity-test(130 test cases)libs/oauth2/test/fulla-oauth2-test(151 test cases)tests/fulla-tests(450 ctest entries, including allDROGON_TESTunit/integration/contract/admin HTTP tests)
Run these 5 binaries in sequence under the coverage build directory, then aggregate the .gcda files.
⚠ gcovr path-matching bug — use scripts/measure_coverage.py instead
gcovr 8.6 falsely reports 0% for some files (e.g. ClientManagementService.cc): raw gcov clearly shows Lines executed:55.79% of 328, yet gcovr's --print-summary lists only the file name without a percentage (gcovr's source-path matching handles .gcov output containing absolute paths + Drogon headers inconsistently). This is a known gcovr path-matching issue, not a zero-count bug (gcov flushing works correctly; see below).
Reliable aggregation: scripts/measure_coverage.py aggregates directly with gcov -j (JSON format, per file {file, lines[{count, unexecuted_block}]}), bypassing gcovr's text path matching. Usage:
cd <repo>
# First run all 5 binaries (see the previous section), then generate JSON + aggregate:
find build/linux-coverage/libs -path "*/src/*" -name "*.gcda" ! -path "*/models/*" \
| xargs -I{} bash -c 'cd "$(dirname {})" && gcov -j "$(basename {})" >/dev/null 2>&1'
find build/linux-coverage/libs -path "*/src/*" -name "*.gcov.json.gz" ! -path "*/models/*" \
| python3 scripts/measure_coverage.py
gcovr is still usable for per-file HTML reports (--html-details), but for summary percentages scripts/measure_coverage.py is authoritative.
Coverage toolchain
cmake/Coverage.cmake(oauth2_apply_gcov(target)) adds-fprofile-arcs -ftest-coverageto every first-party library + test executable and explicitly links libgcov (GCC only; on Clang the profile runtime is provided automatically by the-fprofile-arcslink option, no libgcov).tests/test_main.ccexplicitly calls__gcov_dump()before bothstd::_Exit()sites: because_Exitbypassesatexit, libgcov's counter flush does not run automatically (otherwise gcov reads all-zero counts). This is a known interaction between the Drogon test framework's fast exit and gcov, requiring a manual flush in the test main. (Note: the 4 per-lib gtest binaries exit normally without_Exit, so they need no manual flush.)- Coverage policy: the enforced floor is the ratchet baseline above (63.1% derived overall, 2026-09-05) — the 60% phase target set at 7ba8068 has been passed; further movement means raising the baseline deliberately (see "How the coverage ratchet works"). The remaining blind spots concentrate in branches that are hard to test over HTTP: deep WebAuthn ceremony/crypto branches, UserSelfService (requires driving the auth pre-filter in reverse), storage-postgres transaction/error-fallback branches (require fault injection). Social OAuth controllers can now be covered in memory mode via the Fake injection of
SocialMockFixture.h(the GitHub happy-path no longer depends ongetDbClient()after thesaveTokenPairstorage-abstraction refactor). The ORM-generatedlibs/storage-postgres/src/models/*.ccfiles are excluded from the denominator.
8. Manual Validation & API Testing (Manual Validation)
Beyond the automated test suite, the project also provides tools and scripts for manually validating endpoint functionality.
8.1 Endpoint automation scripts (.sh / .ps1)
The project ships complete endpoint test suites (test-oauth2-endpoints and test-admin-endpoints) maintained in two parity dialects: .sh for Linux/macOS and .ps1 for Windows (invoked via ./manage.sh / ./manage.ps1; there is no .bat dialect).
Usage:
# Run the test, temporarily bypassing the execution policy
powershell -ExecutionPolicy Bypass -File scripts/backend/test-oauth2-endpoints.ps1
The script runs, in order: a health check, login, authorization code exchange, UserInfo access, and admin panel verification.
8.2 Multi-environment API testing (curl)
Different command-line tools vary in their support for curl syntax:
- PowerShell (recommended): use
Invoke-RestMethod. - Git Bash: supports standard Unix single-quote syntax.
- CMD: requires double quotes and escaping
&as^&.
Example: log in and get a JSON response
# Git Bash example
curl -X POST http://127.0.0.1:5555/oauth2/login \
-d 'username=admin&password=admin&client_id=fulla-portal&redirect_uri=http://localhost:5173/callback&json=true'
9. Troubleshooting
9.1 Common problems and remedies
- Server fails to start: check whether port 5555 is occupied (
netstat -ano | findstr :5555) and make sure theconfig.jsonpath is correct. - Login fails (400): confirm the username and password match and that the user exists in the database. Check that
redirect_uriexactly matches the configuration. - Token exchange fails: the authorization code can be used only once and has a validity window. Make sure
client_idandclient_secretare correct. - PowerShell script restriction: if you see a "running scripts is disabled" message, use the
-ExecutionPolicy Bypassparameter.
9.2 Debugging tips
- Log level: when troubleshooting, temporarily set
log_levelinconfig.jsontoDEBUG(or evenTRACE) for verbose output, and back toINFOonce the issue is located. For the full six-level semantics and conventions see observability.md §3.2. - Live logs: use
Get-Content apps/server/logs/drogon.log -Wait -Tail 20to monitor the running state.
Related documentation:
- Security Architecture - security hardening and security architecture design
- Data Consistency - data consistency and the threat model
- API Reference - API interface documentation