|
|
@@ -90,4 +90,62 @@ final class RequestTest extends TestCase
|
|
|
$req = $this->makeRequest(['HTTPS' => 'off']);
|
|
|
self::assertFalse($req->isHttps());
|
|
|
}
|
|
|
+
|
|
|
+ // ------------------------------------------------------------------
|
|
|
+ // R01-N24: body size cap
|
|
|
+ // ------------------------------------------------------------------
|
|
|
+
|
|
|
+ public function testMaxBodyBytesCapIsExactlyOneMebibyte(): void
|
|
|
+ {
|
|
|
+ // Drift fence — bumping this changes a published HTTP contract
|
|
|
+ // (clients that rely on the 413 boundary). Update REVIEW_01.md
|
|
|
+ // §R01-N24, public/index.php's error message, and any per-cap
|
|
|
+ // operator docs alongside the value here.
|
|
|
+ self::assertSame(1024 * 1024, Request::MAX_BODY_BYTES);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testBodyTooLargeFlagDefaultsToFalse(): void
|
|
|
+ {
|
|
|
+ $req = $this->makeRequest([]);
|
|
|
+ self::assertFalse($req->bodyTooLarge);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testBodyTooLargeFlagWiresThroughConstructor(): void
|
|
|
+ {
|
|
|
+ // The front controller (`public/index.php`) reads this property to
|
|
|
+ // emit a 413 before dispatch. A future refactor must not lose the
|
|
|
+ // wiring or the cap silently disappears.
|
|
|
+ $req = new Request(
|
|
|
+ method: 'POST',
|
|
|
+ path: '/sprints/1/week-cells',
|
|
|
+ query: [],
|
|
|
+ post: [],
|
|
|
+ rawBody: '',
|
|
|
+ headers: [],
|
|
|
+ server: [],
|
|
|
+ bodyTooLarge: true,
|
|
|
+ );
|
|
|
+ self::assertTrue($req->bodyTooLarge);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testJsonReturnsNullWhenBodyWasOversized(): void
|
|
|
+ {
|
|
|
+ // `fromGlobals()` blanks `rawBody` once it decides the request was
|
|
|
+ // oversized, so the existing `json()` parser naturally returns null.
|
|
|
+ // Pin that downstream-safety contract — controllers that fall back
|
|
|
+ // to `?? []` continue to work; the front-controller 413 has
|
|
|
+ // already replied so this branch should never run in production,
|
|
|
+ // but defending against a misuse path is cheap.
|
|
|
+ $req = new Request(
|
|
|
+ method: 'POST',
|
|
|
+ path: '/x',
|
|
|
+ query: [],
|
|
|
+ post: [],
|
|
|
+ rawBody: '',
|
|
|
+ headers: ['content-type' => 'application/json'],
|
|
|
+ server: [],
|
|
|
+ bodyTooLarge: true,
|
|
|
+ );
|
|
|
+ self::assertNull($req->json());
|
|
|
+ }
|
|
|
}
|