Skip to content

Commit

Permalink
Merge pull request #40 from chadicus/bug/rewind-request-body
Browse files Browse the repository at this point in the history
Bug/rewind request body
  • Loading branch information
chadicus authored Nov 22, 2017
2 parents 2f86900 + d83d35c commit a5753d4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
18 changes: 7 additions & 11 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
filter:
excluded_paths:
- 'vendor/*'
- 'tests/*'
before_commands:
- 'composer install --prefer-source'
checks:
php:
custom_coding_standard:
git_repository: 'https://github.com/chadicus/coding-standard'
git_version: '971fac1625463a72df0034fbfdd263561f2ccb4f'
ruleset_path: 'Chadicus/ruleset.xml'
build:
tests:
override:
- phpcs-run --standard=./vendor/chadicus/coding-standard/Chadicus/ruleset.xml
tools:
php_analyzer: true
php_mess_detector: true
sensiolabs_security_checker: true
php_loc:
excluded_dirs:
- vendor
- tests
php_pdepend: true
php_sim: true
build_failure_conditions:
- 'elements.rating(<= B).new.exists'
- 'issues.label("coding-style").new.exists'
- 'issues.severity(>= MAJOR).new.exists'
- 'elements.rating(< B).new.exists'
- 'issues.label("coding-style").new.exists'
- 'issues.severity(>= MAJOR).new.exists'
- 'project.metric("scrutinizer.quality", < 6)'
5 changes: 4 additions & 1 deletion src/RequestBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ class RequestBridge
*/
final public static function toOAuth2(ServerRequestInterface $request)
{
$contents = $request->getBody()->getContents();
$request->getBody()->rewind();

return new OAuth2\Request(
(array)$request->getQueryParams(),
(array)$request->getParsedBody(),
$request->getAttributes(),
$request->getCookieParams(),
self::convertUploadedFiles($request->getUploadedFiles()),
$request->getServerParams(),
(string)$request->getBody(),
$contents,
self::cleanupHeaders($request->getHeaders())
);
}
Expand Down
24 changes: 24 additions & 0 deletions tests/RequestBridgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,28 @@ public function toOAuth2WithAuthorization()

$this->assertSame('Bearer abc123', $oauth2Request->headers('AUTHORIZATION'));
}

/**
* Verify that steam contents of a passed request is preserved (read and rewound).
*
* @test
* @covers ::toOAuth2
*
* @return void
*/
public function toOAuth2BodyContentsOfRequestPreserved()
{
$uri = 'https://example.com/foos';

$temp = tmpfile();
fwrite($temp, 'foo');
rewind($temp);

$psr7Request = new ServerRequest([], [], $uri, 'POST', $temp);

$oauth2Request = RequestBridge::toOAuth2($psr7Request);

$this->assertSame('foo', $psr7Request->getBody()->getContents());
$this->assertSame('foo', $oauth2Request->getContent());
}
}

0 comments on commit a5753d4

Please sign in to comment.