feat(server): add per-IP rate limit middleware on /api/v1/greet (#22)
All checks were successful
CI/CD Pipeline / Build Docker Cache (push) Successful in 1m3s
CI/CD Pipeline / CI Pipeline (push) Successful in 4m4s
CI/CD Pipeline / Trigger Docker Push (push) Successful in 6s

Phase 1 of ADR-0022. In-memory per-IP rate limiter on golang.org/x/time/rate. Returns 429 with Retry-After when exceeded. 7 unit tests pass. BDD scenario @skip until testserver rework. Closes #13.

~95% Mistral Vibe autonomous via ICM workspace. Cost ~6.5€ (T5 + resume + trainer commit/PR).

Co-authored-by: Gabriel Radureau <arcodange@gmail.com>
Co-committed-by: Gabriel Radureau <arcodange@gmail.com>
This commit was merged in pull request #22.
This commit is contained in:
2026-05-03 13:16:29 +02:00
committed by arcodange
parent 9cf6e7f1c4
commit 54dd0cc80f
10 changed files with 667 additions and 5 deletions

View File

@@ -34,4 +34,19 @@ Feature: Greet Service
Scenario: v2 greeting with name that is too long
Given the server is running with v2 enabled
When I send a POST request to v2 greet with name "ThisNameIsWayTooLongAndShouldFailValidationBecauseItExceedsTheMaximumAllowedLengthOf100Characters!!!!"
Then the response should contain error "validation_failed"
Then the response should contain error "validation_failed"
@ratelimit @skip @bdd-deferred
# NOTE: Functional behavior validated by unit tests in pkg/middleware/ratelimit_test.go.
# BDD scenario currently skipped: env-var-based rate limit config does not reach the
# already-started test server (architectural limitation of testsetup, not the middleware).
# TODO: rework testserver to allow per-scenario rate limit config (admin endpoint or
# per-scenario fresh server), then re-enable this scenario.
Scenario: Greet endpoint rejects requests over the rate limit
Given the server is running with rate limit set to 3 requests per minute and burst 3
When I make 3 requests to "/api/v1/greet/Alice"
Then all responses should have status 200
When I make 1 more request to "/api/v1/greet/Alice"
Then the response should have status 429
And the response body should contain "rate_limited"
And the response should have header "Retry-After"