M-1 TokenExtract: exact-name cookie parse (new pure cookieValue helper) —
a substring find("session=") could be shadowed by a sibling xsession=,
defeating __Host-/__Secure- prefix guarantees.
M-2 AuthInterceptor: gate setup-mode pseudo-admin on a loopback bind and log
the grant; document that IAuthBackend::hasActiveUsers() must fail closed.
M-3 ws/Hub: empty propertyIds now means NO access for non-admins (was "all") —
a non-admin whose scope set failed to populate no longer gets every
property's notifications. Admins still get all via role.
M-4 new util/OriginCheck.hpp (originHostname/sameOrigin/originAllowed) +
Hub doc: WSController must validate Origin at the handshake (CSWSH).
M-6 RedactedFieldRepository: ctor throws on an unknown redaction field name
(a typo would silently redact nothing, leaving credentials in history).
M-7 RateLimiter: ctor validates capacity (finite >=1) / refillRate (finite >0),
throws std::invalid_argument — zero/negative/NaN silently disabled it.
M-8 TokenExtract: document that clientIpTrusted's "unknown"/"invalid" sentinels
collapse to one shared rate-limit bucket off-proxy.
M-9 new util/SessionCookie.hpp: safe-by-default Set-Cookie builder
(HttpOnly+Secure+SameSite=Strict+Path=/), rejects control chars / ';'.
M-10 AuthInterceptor: Origin/Referer-vs-Host check on session mutations
(defence in depth atop X-Requested-With); cert path documented as
non-browser / not CSRF-gated.
M-11 AuthInterceptor: optional injected RateLimiter throttles invalid-token
attempts per client IP → 429.
M-12 AuthInterceptor: sanitize request method/path (strip control chars, cap
length) before logging — closes log-line forging (CWE-117).
(M-5 — temporal non-atomic save — was already resolved by the H-4 fix.)
Tests: new test_token_extract / test_rate_limiter / test_origin_check /
test_session_cookie; extended test_redacted_field_repository. All 19 ctest
targets pass. README + header docs updated.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
99 lines
4.9 KiB
CMake
99 lines
4.9 KiB
CMake
# Minimal test harness for oatpp-authkit.
|
|
#
|
|
# Adds plain executable tests linked against the INTERFACE library and oatpp.
|
|
# No third-party test framework — assertions use <cassert> and a tiny REQUIRE
|
|
# macro so the suite stays portable and dependency-free.
|
|
|
|
find_package(oatpp REQUIRED)
|
|
|
|
add_executable(test_negotiation test_negotiation.cpp)
|
|
target_link_libraries(test_negotiation PRIVATE oatpp::authkit oatpp::oatpp)
|
|
add_test(NAME negotiation COMMAND test_negotiation)
|
|
|
|
add_executable(test_token_extract test_token_extract.cpp)
|
|
target_link_libraries(test_token_extract PRIVATE oatpp::authkit oatpp::oatpp)
|
|
add_test(NAME token_extract COMMAND test_token_extract)
|
|
|
|
add_executable(test_rate_limiter test_rate_limiter.cpp)
|
|
target_link_libraries(test_rate_limiter PRIVATE oatpp::authkit oatpp::oatpp)
|
|
add_test(NAME rate_limiter COMMAND test_rate_limiter)
|
|
|
|
add_executable(test_origin_check test_origin_check.cpp)
|
|
target_link_libraries(test_origin_check PRIVATE oatpp::authkit oatpp::oatpp)
|
|
add_test(NAME origin_check COMMAND test_origin_check)
|
|
|
|
add_executable(test_session_cookie test_session_cookie.cpp)
|
|
target_link_libraries(test_session_cookie PRIVATE oatpp::authkit oatpp::oatpp)
|
|
add_test(NAME session_cookie COMMAND test_session_cookie)
|
|
|
|
add_executable(test_body_size_limit test_body_size_limit.cpp)
|
|
target_link_libraries(test_body_size_limit PRIVATE oatpp::authkit oatpp::oatpp)
|
|
add_test(NAME body_size_limit COMMAND test_body_size_limit)
|
|
|
|
add_executable(test_security_headers test_security_headers.cpp)
|
|
target_link_libraries(test_security_headers PRIVATE oatpp::authkit oatpp::oatpp)
|
|
add_test(NAME security_headers COMMAND test_security_headers)
|
|
|
|
add_executable(test_json_serialization test_json_serialization.cpp)
|
|
target_link_libraries(test_json_serialization PRIVATE oatpp::authkit oatpp::oatpp)
|
|
add_test(NAME json_serialization COMMAND test_json_serialization)
|
|
|
|
add_executable(test_repository_interface test_repository_interface.cpp)
|
|
target_link_libraries(test_repository_interface PRIVATE oatpp::authkit oatpp::oatpp)
|
|
add_test(NAME repository_interface COMMAND test_repository_interface)
|
|
|
|
add_executable(test_repository_decorators test_repository_decorators.cpp)
|
|
target_link_libraries(test_repository_decorators PRIVATE oatpp::authkit oatpp::oatpp)
|
|
add_test(NAME repository_decorators COMMAND test_repository_decorators)
|
|
|
|
add_executable(test_queryable test_queryable.cpp)
|
|
target_link_libraries(test_queryable PRIVATE oatpp::authkit oatpp::oatpp)
|
|
add_test(NAME queryable COMMAND test_queryable)
|
|
|
|
add_executable(test_temporal_field_traits test_temporal_field_traits.cpp)
|
|
target_link_libraries(test_temporal_field_traits PRIVATE oatpp::authkit oatpp::oatpp)
|
|
add_test(NAME temporal_field_traits COMMAND test_temporal_field_traits)
|
|
|
|
add_executable(test_audit_log_repository test_audit_log_repository.cpp)
|
|
target_link_libraries(test_audit_log_repository PRIVATE oatpp::authkit oatpp::oatpp)
|
|
add_test(NAME audit_log_repository COMMAND test_audit_log_repository)
|
|
|
|
add_executable(test_schema_contract test_schema_contract.cpp)
|
|
target_link_libraries(test_schema_contract PRIVATE oatpp::authkit oatpp::oatpp)
|
|
add_test(NAME schema_contract COMMAND test_schema_contract)
|
|
|
|
add_executable(test_redacted_field_repository test_redacted_field_repository.cpp)
|
|
target_link_libraries(test_redacted_field_repository PRIVATE oatpp::authkit oatpp::oatpp)
|
|
add_test(NAME redacted_field_repository COMMAND test_redacted_field_repository)
|
|
|
|
# SmtpTransport.hpp pulls in <curl/curl.h> and needs libcurl at link time.
|
|
# Guard the test so the suite still builds where curl dev headers are absent.
|
|
find_package(CURL QUIET)
|
|
if(CURL_FOUND)
|
|
add_executable(test_smtp_transport test_smtp_transport.cpp)
|
|
target_link_libraries(test_smtp_transport PRIVATE oatpp::authkit oatpp::oatpp CURL::libcurl)
|
|
add_test(NAME smtp_transport COMMAND test_smtp_transport)
|
|
endif()
|
|
|
|
# RoleTemplateDb pulls in oatpp-sqlite for its DbClient queries. Linking
|
|
# the test against oatpp::oatpp-sqlite provides the QUERY codegen
|
|
# definitions; the test itself doesn't open a real DB, only compiles
|
|
# against the schema declarations.
|
|
find_package(oatpp-sqlite QUIET)
|
|
find_package(Threads QUIET)
|
|
if(oatpp-sqlite_FOUND AND Threads_FOUND)
|
|
add_executable(test_role_template_schema test_role_template_schema.cpp)
|
|
target_link_libraries(test_role_template_schema
|
|
PRIVATE oatpp::authkit oatpp::oatpp oatpp::oatpp-sqlite Threads::Threads)
|
|
add_test(NAME role_template_schema COMMAND test_role_template_schema)
|
|
|
|
add_executable(test_user_permission_schema test_user_permission_schema.cpp)
|
|
target_link_libraries(test_user_permission_schema
|
|
PRIVATE oatpp::authkit oatpp::oatpp oatpp::oatpp-sqlite Threads::Threads)
|
|
add_test(NAME user_permission_schema COMMAND test_user_permission_schema)
|
|
|
|
add_executable(test_user_schema test_user_schema.cpp)
|
|
target_link_libraries(test_user_schema
|
|
PRIVATE oatpp::authkit oatpp::oatpp oatpp::oatpp-sqlite Threads::Threads)
|
|
add_test(NAME user_schema COMMAND test_user_schema)
|
|
endif()
|