Skip to content

Commit

Permalink
Test for error on excessive known body size
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Oct 19, 2017
1 parent 96d43b6 commit f044fd8
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions tests/Middleware/RequestBodyBufferMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,30 @@ function (ServerRequestInterface $request) use (&$exposedRequest) {
$this->assertSame($body, $exposedRequest->getBody()->getContents());
}

public function testExcessiveSizeImmediatelyReturnsError413ForKnownSize()
{
$loop = Factory::create();

$stream = new ThroughStream();
$stream->end('aa');
$serverRequest = new ServerRequest(
'GET',
'https://example.com/',
array(),
new HttpBodyStream($stream, 2)
);

$buffer = new RequestBodyBufferMiddleware(1);
$response = $buffer(
$serverRequest,
function (ServerRequestInterface $request) {
return $request;
}
);

$this->assertSame(413, $response->getStatusCode());
}

public function testExcessiveSizeReturnsError413()
{
$loop = Factory::create();
Expand All @@ -74,7 +98,7 @@ public function testExcessiveSizeReturnsError413()
'GET',
'https://example.com/',
array(),
new HttpBodyStream($stream)
new HttpBodyStream($stream, null)
);

$buffer = new RequestBodyBufferMiddleware(1);
Expand All @@ -85,7 +109,7 @@ function (ServerRequestInterface $request) {
}
);

$stream->write('aa');
$stream->end('aa');

$exposedResponse = null;
$promise->then(
Expand Down

0 comments on commit f044fd8

Please sign in to comment.