-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Subcategory
new-feature - Entirely new functionality
Description
Problem
The Safaricom Daraja Sandbox environment is protected by an aggressive Web Application Firewall (WAF) that frequently returns HTTP 403 Forbidden errors for automated integration tests. This currently causes flaky builds and blocks CI/CD pipelines, even when the underlying library code is correct.
Current State
We have implemented a localized mitigation in the auth module using:
User-Agentspoofing.- Request throttling (
0.5sdelay). pytest.xfailwrappers for 403 errors.
However, as we expand to C2B, B2C, and STK Push modules, these tests will face the same susceptibility.
Proposed Global Solution
To avoid repeating boilerplate resilience code, we should implement:
- Global Pytest Decorator: Create an
@mpesa_integration_testdecorator inconftest.pythat automatically handles async setup and WAF 403xfaillogic. - Exponential Backoff: Implement a retry mechanism within
MpesaAsyncHttpClientthat specifically targets 403 errors with increasing delays (e.g., 1s, 2s, 4s). - Session Persistence: Ensure the
httpx.AsyncClientis session-scoped to reuse TCP connections, which is less likely to trigger bot-detection patterns.
Impact
Implementing these will ensure that our integration tests remain green and reliable, providing a better developer experience for anyone contributing to the library.
Labels: enhancement, testing, environment-issue
Motivation
No response
Alternatives
No response
Additional Context
No response