Skip to content

Add HAVE_BAUTH conditional compilation for basic auth#367

Merged
etr merged 3 commits intomasterfrom
feature/bauth-conditional-compile
Feb 19, 2026
Merged

Add HAVE_BAUTH conditional compilation for basic auth#367
etr merged 3 commits intomasterfrom
feature/bauth-conditional-compile

Conversation

@etr
Copy link
Owner

@etr etr commented Feb 19, 2026

Summary

  • Auto-detect basic auth support in libmicrohttpd via AC_CHECK_LIB for MHD_queue_basic_auth_fail_response
  • Guard all basic auth code with #ifdef HAVE_BAUTH / #endif, mirroring the existing HAVE_DAUTH pattern
  • Add Basic Auth : yes/no to the ./configure summary output

Addresses item 6 from #61: conditional compilation for libmicrohttpd features (basic auth).

Changes

Build system (configure.ac, src/Makefile.am, examples/Makefile.am):

  • Detect MHD_queue_basic_auth_fail_response and set HAVE_BAUTH define + automake conditional
  • Conditionally compile basic_auth_fail_response.cpp and install its header
  • Conditionally build basic_authentication and centralized_authentication examples

Library sources (18 files, +85/-6 lines):

  • basic_auth_fail_response.hpp/.cpp — wrap class/impl in #ifdef HAVE_BAUTH
  • http_request.hpp/.cpp — guard get_user(), get_pass(), fetch_user_pass(), cache fields
  • create_webserver.hpp — guard basic_auth()/no_basic_auth() builder methods
  • webserver.hpp/.cpp — guard basic_auth_enabled member
  • httpserver.hpp — conditionally include basic_auth_fail_response.hpp
  • create_test_request.hpp/.cpp — guard .user()/.pass() builder and cache access

Tests:

  • authentication.cpp, basic.cpp, ws_start_stop.cpp, create_webserver_test.cpp, create_test_request_test.cpp — guard basic auth test cases

Test plan

  • All 14 tests pass with HAVE_BAUTH defined (standard libmicrohttpd)
  • Source files compile without HAVE_BAUTH (verified via direct compilation)
  • Clean build from master with cherry-picked commits passes all tests
  • Verify on an embedded system with libmicrohttpd lacking basic auth support

etr added 2 commits February 19, 2026 13:19
Add HAVE_BAUTH conditional compilation for basic authentication,
mirroring the existing HAVE_DAUTH pattern. This allows libhttpserver
to build against libmicrohttpd installations that lack basic auth
support.

Changes:
- configure.ac: Auto-detect MHD_queue_basic_auth_fail_response,
  define HAVE_BAUTH flag and AM_CONDITIONAL, add to summary output
- src/httpserver/basic_auth_fail_response.hpp: Guard with #ifdef HAVE_BAUTH
- src/basic_auth_fail_response.cpp: Guard with #ifdef HAVE_BAUTH
- src/httpserver.hpp: Conditionally include basic_auth_fail_response.hpp
- src/httpserver/http_request.hpp: Guard get_user(), get_pass(),
  fetch_user_pass() declarations and username/password cache fields
- src/http_request.cpp: Guard fetch_user_pass(), get_user(), get_pass()
  implementations and basic auth output in operator<<
- src/httpserver/create_webserver.hpp: Guard basic_auth()/no_basic_auth()
  methods and _basic_auth_enabled member
- src/httpserver/webserver.hpp: Guard basic_auth_enabled member
- src/webserver.cpp: Guard basic_auth_enabled initialization
- src/Makefile.am: Make basic_auth_fail_response conditional on HAVE_BAUTH
- examples/Makefile.am: Guard basic_authentication and
  centralized_authentication examples behind HAVE_BAUTH
- test/integ/authentication.cpp: Guard basic auth tests with HAVE_BAUTH
- test/unit/create_webserver_test.cpp: Guard basic_auth builder test
Guard basic auth references in ws_start_stop.cpp, basic.cpp,
create_test_request_test.cpp, create_test_request.hpp, and
create_test_request.cpp that would fail to compile when
libmicrohttpd lacks basic auth support.
@codecov
Copy link

codecov bot commented Feb 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.97%. Comparing base (1a26dfc) to head (ae59cc7).
⚠️ Report is 5 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #367      +/-   ##
==========================================
+ Coverage   67.93%   67.97%   +0.03%     
==========================================
  Files          28       28              
  Lines        1634     1636       +2     
  Branches      672      672              
==========================================
+ Hits         1110     1112       +2     
  Misses         64       64              
  Partials      460      460              
Files with missing lines Coverage Δ
src/basic_auth_fail_response.cpp 100.00% <ø> (ø)
src/http_request.cpp 60.68% <100.00%> (+0.27%) ⬆️
src/httpserver/basic_auth_fail_response.hpp 75.00% <ø> (ø)
src/httpserver/create_webserver.hpp 96.98% <ø> (ø)
src/httpserver/http_request.hpp 88.37% <ø> (ø)
src/webserver.cpp 56.33% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1a26dfc...ae59cc7. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Add Version 0.20.0 header with bauth conditional compilation and
security fix entries. Bump version in configure.ac to match.
@etr etr merged commit 95d6df4 into master Feb 19, 2026
42 checks passed
@etr etr mentioned this pull request Feb 19, 2026
6 tasks
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.

1 participant

Comments