Skip to content

Extract OnBeginRequest logic into a testable core layer - #12

Merged
sassi67 merged 1 commit into
mainfrom
implement-onbeginrequest-unit-testing
Aug 22, 2026
Merged

sassi67 merged 1 commit into
mainfrom
implement-onbeginrequest-unit-testing

Conversation

@sassi67

@sassi67 sassi67 commented Aug 22, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds src/core, an IIS/Windows-independent static library (IISNativeModuleCore, namespace core) holding the Verdict enum (Continue/Finish mirroring RQ_NOTIFICATION_CONTINUE/RQ_NOTIFICATION_FINISH_REQUEST), the IRequest/IResponse/IContext/IEventProvider/IModule interfaces mirroring their IIS counterparts, and ModuleHandler — which now carries the full OnBeginRequest logic (403 + reason for /forbidden paths, X-IISRequestLevelModule: 1 header otherwise). Nothing in src/core includes Windows or IIS headers; HRESULT-shaped values travel as std::int32_t.
  • IISRequestLevelModule becomes a thin adapter: it takes a non-owning core::IModule* via constructor injection, wraps the live IIS objects in the IISContext/IISRequest/IISResponse/IISEventProvider adapters (one file pair per class), delegates, and maps the returned Verdict back to a REQUEST_NOTIFICATION_STATUS. The factory owns the shared stateless ModuleHandler and injects it into every instance it creates.
  • Adds test/core/ModuleHandlerTest.cpp: hand-rolled mocks of the core interfaces exercise the real ModuleHandler for the two scenarios from the issue — a /forbidden url (expects Finish, 403, access-denied error on response and provider, no header) and a generic url (expects Continue and the X-IISRequestLevelModule: 1 header).
  • Files in src/module, src/core, and test/core are named after the class they hold (PascalCase); register_module.cpp and iis_native_module.def keep their names since they hold no class.

Design decisions (confirmed during implementation)

  • IContext declares GetRequest() -> IRequest* / GetResponse() -> IResponse* (the issue text had the names swapped).
  • IResponse also declares SetHeader, so ModuleHandler can carry the complete current behavior including the header stamping.
  • Tests mock the core interfaces (with the url fed through the mock request's constructor) rather than mocking IModule itself, so the real ModuleHandler logic is what's exercised.

Test plan

  • Full build of all 5 targets clean (windows-x86-64-debug), including the new IISNativeModuleCore
  • All 3 tests pass: the 2 new TestCore scenarios plus the existing smoke test

Closes #11

🤖 Generated with Claude Code

Add src/core, an IIS/Windows-independent static library
(IISNativeModuleCore) holding the Verdict enum (Continue/Finish
mirroring RQ_NOTIFICATION_CONTINUE/RQ_NOTIFICATION_FINISH_REQUEST),
the IRequest/IResponse/IContext/IEventProvider/IModule interfaces
mirroring their IIS counterparts, and ModuleHandler, which now carries
the full OnBeginRequest logic (403 for /forbidden paths, response
header otherwise).

IISRequestLevelModule becomes a thin adapter: it takes a non-owning
core::IModule* via constructor injection, wraps the live IIS objects
in the IISContext/IISRequest/IISResponse/IISEventProvider adapters,
delegates, and maps the Verdict back to a
REQUEST_NOTIFICATION_STATUS. The factory owns the shared stateless
ModuleHandler and injects it into every instance it creates.

Each class lives in its own header/source pair, and files in
src/module, src/core, and test/core are named after the class they
hold (IContext.h, ModuleHandler.h/.cpp, IISRequestLevelModule.h/.cpp,
ModuleHandlerTest.cpp, ...); register_module.cpp and
iis_native_module.def keep their names since they hold no class.

test/core/ModuleHandlerTest.cpp exercises the real ModuleHandler
through hand-rolled mocks of the core interfaces for the two
scenarios from the issue: a /forbidden url (Finish, 403, error status
reported) and a generic url (Continue, X-IISRequestLevelModule: 1).

Closes #11

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sassi67 sassi67 self-assigned this Aug 22, 2026
@sassi67 sassi67 added the enhancement New feature or request label Aug 22, 2026
@sassi67
sassi67 merged commit 54a11aa into main Aug 22, 2026
2 checks passed
@sassi67
sassi67 deleted the implement-onbeginrequest-unit-testing branch August 22, 2026 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement OnBeginRequest unit testing

1 participant