Heuristic:APIJSON APIJSON Demo Internal Call Key Based Limit Elevation
| Knowledge Sources | |
|---|---|
| Domains | Security, Testing, Access_Control |
| Last Updated | 2026-10-14 00:00 GMT |
Overview
Inject a random key into DemoParser.KEY_MAP to elevate API rate limits for internal automated test calls, bypassing per-user request throttling.
Description
The AutoTestRegressionScheduler generates a random 6-digit key via buildTestKey() and registers a BackgroundHttpSession in DemoParser.KEY_MAP before triggering the test start URL. The key is appended as a query parameter (?key=XXXXXX) to the start and status URLs. The APIJSON framework checks KEY_MAP for internally authenticated sessions, allowing the regression test to bypass normal per-user rate limits. After the test completes (or fails), the key is removed from KEY_MAP and the session is invalidated.
Usage
Apply this heuristic when automated internal processes need to call API endpoints that are rate-limited for normal users. Register a key in KEY_MAP before the call, pass it as a query parameter, and clean up afterward.
The Insight (Rule of Thumb)
- Action: Put a random key + session into
DemoParser.KEY_MAPbefore making internal API calls. - Value: Random 6-digit key (
100000–999999). - Trade-off: Temporarily elevates rate limits for the key holder; must be cleaned up to prevent key leakage.
- Compatibility: The key must be passed as a
keyquery parameter to the API endpoints.
Reasoning
APIJSON enforces per-user request count limits to prevent abuse. Automated regression testing makes hundreds of API calls in rapid succession, which would exceed normal limits. By registering in KEY_MAP, the framework recognizes the calls as internal/system-level and applies elevated limits. The BackgroundHttpSession provides a mock HTTP session for cookie storage, allowing the test runner to maintain authentication state across requests. Cleanup in the finally block prevents key accumulation and ensures security.
Code Evidence
Key registration from `AutoTestRegressionScheduler.java:106-109`:
result.key = buildTestKey();
BackgroundHttpSession session = new BackgroundHttpSession("auto-api-test-" + UUID.randomUUID());
DemoParser.KEY_MAP.put(result.key, session);
Key as query parameter from `AutoTestRegressionScheduler.java:112`:
doGet(session, appendQueryParam(startUrl, "key", result.key));
Key generation from `AutoTestRegressionScheduler.java:434-436`:
private String buildTestKey() {
return String.valueOf(100000 + Math.round(899999 * Math.random()));
}
Cleanup from `AutoTestRegressionScheduler.java:134-139`:
} finally {
DemoParser.KEY_MAP.remove(result.key);
try {
session.invalidate();
} catch (Throwable ignore) {
}