Repository navigation
Commit cd99418
authored
Add comprehensive rate limiting module with policy management (#64)
* Add RateLimiting module with framework-level rate limiting support
- Add rate limiting abstractions to SimpleModule.Core: policy types (FixedWindow,
SlidingWindow, TokenBucket), target modes (IP, User, IpAndUser, Global),
IRateLimitBuilder, IRateLimitPolicyRegistry, and .RateLimit() endpoint extension
- Add ConfigureRateLimits() lifecycle hook to IModule interface
- Integrate ASP.NET Core RateLimiter middleware in SimpleModule.Hosting with
automatic policy registration from module definitions
- Add X-RateLimit-* response headers via RateLimitHeaderMiddleware
- Update source generator to discover and wire ConfigureRateLimits on modules
- Create RateLimiting module with:
- Contracts: RateLimitRule entity, CRUD DTOs, IRateLimitingContracts
- Implementation: DbContext, CRUD service, REST endpoints, permissions
- Admin UI: React/Inertia page for managing stored rules and viewing active policies
- 4 built-in policies: fixed-default, sliding-strict, token-bucket, auth-strict
- Navigation menu in admin sidebar
- Add 18 unit tests covering policy registry and CRUD service
- Register module in Host project, solution, and test infrastructure
* Simplify RateLimiting module: address code review findings
- Use Dictionary<string, RateLimitPolicyDefinition> for O(1) policy lookup
instead of linear List.Find on every rate-limited request
- Pre-build rate limiter options at registration time instead of allocating
per-request in the partition factory
- Accept IRateLimitPolicyRegistry interface instead of concrete type in
AddSimpleModuleRateLimiting to avoid leaking implementation details
- Extract CreateRequestValidator class following the codebase convention
used by Products, Orders, and Tenants modules
- Extract API_BASE constant in Admin.tsx to eliminate hardcoded URL strings
- Fix handleToggle to send only UpdateRateLimitRuleRequest fields instead
of spreading the full entity (which includes id, policyName, timestamps)
* Add E2E tests for RateLimiting module
- Add page object (RateLimitingAdminPage) with selectors for heading,
tabs, create dialog, rules table, and toggle/delete actions
- Add smoke tests: page loads, tabs visible, active policies table
- Add flow tests: full CRUD via API (create, read, update, delete),
active policies endpoint verification, UI visibility after API create,
create dialog opens from admin page
* ci: retrigger CI after merge with main
* Fix E2E failures: add EnsureTablesCreated for RateLimitingDbContext
The RateLimiting admin page returned 500 because the database tables
were never created in the test infrastructure. Added the missing
EnsureTablesCreated<RateLimitingDbContext> call to the WebApplicationFactory
initialization alongside all other module contexts.
Also adds integration tests that verify the admin page and API endpoints
return 200 for authenticated admin users.
* Add EF Core migration for RateLimiting module
The E2E tests failed because the RateLimiting_Rules table didn't exist
in the SQLite database. The server uses MigrateAsync() on the HostDbContext
which requires an explicit migration to create new tables.
This migration creates the RateLimiting_Rules table with all columns,
the unique index on PolicyName, and also includes pending BackgroundJobs
and Email tables from the main branch merge.1 parent 0e526bb commit cd99418
60 files changed
Lines changed: 4730 additions & 1 deletion
File tree
- framework
- SimpleModule.Core
- RateLimiting
- SimpleModule.Generator
- Discovery
- Emitters
- SimpleModule.Hosting
- RateLimiting
- modules/RateLimiting
- src
- SimpleModule.RateLimiting.Contracts
- SimpleModule.RateLimiting
- Endpoints/Policies
- EntityConfigurations
- Locales
- Pages
- Views
- tests/SimpleModule.RateLimiting.Tests
- template/SimpleModule.Host
- Migrations
- wwwroot/css
- tests
- SimpleModule.Generator.Tests
- e2e
- pages/rate-limiting
- tests
- flows
- smoke
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
117 | 122 | | |
118 | 123 | | |
119 | 124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| 129 | + | |
129 | 130 | | |
130 | 131 | | |
131 | 132 | | |
| |||
146 | 147 | | |
147 | 148 | | |
148 | 149 | | |
| 150 | + | |
149 | 151 | | |
150 | 152 | | |
151 | 153 | | |
| |||
167 | 169 | | |
168 | 170 | | |
169 | 171 | | |
| 172 | + | |
170 | 173 | | |
171 | 174 | | |
172 | 175 | | |
| |||
462 | 465 | | |
463 | 466 | | |
464 | 467 | | |
| 468 | + | |
465 | 469 | | |
466 | 470 | | |
467 | 471 | | |
| |||
0 commit comments