Skip to content

Symfony 4.4.* / 5.0.* Support #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
language: php
dist: trusty
php:
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4

install:
- composer install
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
],

"require": {
"php": "^5.5.9|^7.0.8|^7.1.3|^7.2.5",
"symfony/http-foundation": "~3.0|~4.0|~5.0"
"php": "^7.2",
"symfony/http-foundation": "^4.4|^5.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8 || ^5.0"
"phpunit/phpunit": "^8.5"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should rather use symfony/phpunit-bridge to avoid bumping PHP version.

This would also eliminate the need of many other changes here.

},

"autoload": {
Expand Down
4 changes: 1 addition & 3 deletions lib/OAuth2.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace OAuth2;

use OAuth2\Model\IOAuth2AccessToken;
use OAuth2\Model\IOAuth2AuthCode;
use OAuth2\Model\IOAuth2Client;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -1008,13 +1007,12 @@ protected function getClientCredentials(array $inputData, array $authHeaders)
*
* @throws OAuth2ServerException
* @throws OAuth2RedirectException
*
* @see http://tools.ietf.org/html/draft-ietf-oauth-v2-20#section-4.1.1
* @see http://tools.ietf.org/html/draft-ietf-oauth-v2-21#section-10.12
*
* @ingroup oauth2_section_3
*/
protected function getAuthorizeParams(Request $request = null)
public function getAuthorizeParams(Request $request = null)
{
$filters = array(
"client_id" => array(
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php"
>
<testsuites>
Expand Down
19 changes: 11 additions & 8 deletions tests/ExtraHeadersTest.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
<?php

namespace OAuth2\Tests;

use OAuth2\OAuth2;
use OAuth2\Model\OAuth2Client;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use OAuth2\Tests\Fixtures\OAuth2GrantUserStub;

/**
* Extra Headers test case.
*/
class ExtraHeadersTest extends PHPUnit_Framework_TestCase
class ExtraHeadersTest extends TestCase
{
public function testErrorResponseContainsExtraHeaders()
public function testErrorResponseContainsExtraHeaders(): void
{
$config = array(
OAuth2::CONFIG_RESPONSE_EXTRA_HEADERS => array(
"Access-Control-Allow-Origin" => "http://www.foo.com",
"X-Extra-Header-1" => "Foo-Bar",
),
OAuth2::CONFIG_RESPONSE_EXTRA_HEADERS => [
'Access-Control-Allow-Origin' => 'http://www.foo.com',
'X-Extra-Header-1' => 'Foo-Bar',
],
);
$stub = new OAuth2GrantUserStub();
$stub->addClient(new OAuth2Client('cid', 'cpass'));
Expand All @@ -32,7 +35,7 @@ public function testErrorResponseContainsExtraHeaders()
'username' => 'foo',
'password' => 'bar',
)));
$this->assertSame("http://www.foo.com", $response->headers->get("Access-Control-Allow-Origin"));
$this->assertSame("Foo-Bar", $response->headers->get("X-Extra-Header-1"));
$this->assertSame('http://www.foo.com', $response->headers->get('Access-Control-Allow-Origin'));
$this->assertSame('Foo-Bar', $response->headers->get('X-Extra-Header-1'));
}
}
9 changes: 5 additions & 4 deletions tests/Model/OAuth2TokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace OAuth2\Tests\Model;

use OAuth2\Model\OAuth2Token;
use PHPUnit\Framework\TestCase;

class OAuth2TokenTest extends \PHPUnit_Framework_TestCase
class OAuth2TokenTest extends TestCase
{
public function testConstruct()
public function testConstruct(): void
{
$expiresAt = time() + 42;
$data = new \stdClass;
Expand All @@ -23,14 +24,14 @@ public function testConstruct()
}

/** @dataProvider getTestExpiresData */
public function testExpires($offset, $expired)
public function testExpires($offset, $expired): void
{
$token = new OAuth2Token('foo', 'bar', time() + $offset);

$this->assertSame($expired, $token->hasExpired());
}

public function getTestExpiresData()
public function getTestExpiresData(): array
{
return array(
array(-10, true),
Expand Down
13 changes: 8 additions & 5 deletions tests/OAuth2ImplicitGrantTypeTest.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
<?php

namespace OAuth2\Tests;

use OAuth2\OAuth2;
use OAuth2\OAuth2ServerException;
use OAuth2\Model\OAuth2Client;
use OAuth2\Tests\Fixtures\OAuth2ImplicitStub;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;

/**
* OAuth2 test case.
*/
class OAuth2ImplicitGrantTypeTest extends PHPUnit_Framework_TestCase
class OAuth2ImplicitGrantTypeTest extends TestCase
{
/**
* Tests OAuth2->grantAccessToken() with implicit
*
*/
public function testGrantAccessTokenWithGrantImplicit()
public function testGrantAccessTokenWithGrantImplicit(): void
{
$stub = new OAuth2ImplicitStub();
$stub->addClient(new OAuth2Client('blah', 'foo', array('http://www.example.com/')));
Expand All @@ -37,7 +40,7 @@ public function testGrantAccessTokenWithGrantImplicit()
* Tests OAuth2->grantAccessToken() with implicit
*
*/
public function testRejectedAccessTokenWithGrantImplicit()
public function testRejectedAccessTokenWithGrantImplicit(): void
{
//$this->fixture->grantAccessToken(/* parameters */);

Expand All @@ -58,9 +61,9 @@ public function testRejectedAccessTokenWithGrantImplicit()
} catch (OAuth2ServerException $e) {
$this->assertSame('access_denied', $e->getMessage());
$this->assertSame('The user denied access to your application', $e->getDescription());
$this->assertSame(array(
$this->assertSame([
'Location' => 'http://www.example.com/?foo=bar#error=access_denied&error_description=The+user+denied+access+to+your+application&state=42',
), $e->getResponseHeaders());
], $e->getResponseHeaders());
}
}
}
58 changes: 39 additions & 19 deletions tests/OAuth2OutputTest.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<?php

namespace OAuth2\Tests;

use OAuth2\OAuth2;
use OAuth2\Model\OAuth2AuthCode;
use OAuth2\Model\OAuth2Client;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use OAuth2\IOAuth2GrantCode;

/**
* OAuth2 test cases that involve capturing output.
*/
class OAuth2OutputTest extends PHPUnit_Framework_TestCase
class OAuth2OutputTest extends TestCase
{
/**
* @var OAuth2
Expand All @@ -19,17 +24,23 @@ class OAuth2OutputTest extends PHPUnit_Framework_TestCase
* Tests OAuth2->grantAccessToken() with successful Auth code grant
*
*/
public function testGrantAccessTokenWithGrantAuthCodeSuccess()
public function testGrantAccessTokenWithGrantAuthCodeSuccess(): void
{
$request = new Request(
array('grant_type' => OAuth2::GRANT_TYPE_AUTH_CODE, 'redirect_uri' => 'http://www.example.com/my/subdir', 'client_id' => 'my_little_app', 'client_secret' => 'b', 'code'=> 'foo')
[
'grant_type' => OAuth2::GRANT_TYPE_AUTH_CODE,
'redirect_uri' => 'http://www.example.com/my/subdir',
'client_id' => 'my_little_app',
'client_secret' => 'b',
'code'=> 'foo'
]
);
$storedToken = new OAuth2AuthCode('my_little_app', '', time() + 60, null, null, 'http://www.example.com');

$mockStorage = $this->createBaseMock('OAuth2\IOAuth2GrantCode');
$mockStorage = $this->createBaseMock(IOAuth2GrantCode::class);
$mockStorage->expects($this->any())
->method('getAuthCode')
->will($this->returnValue($storedToken));
->willReturn($storedToken);

$this->fixture = new OAuth2($mockStorage);
$response = $this->fixture->grantAccessToken($request);
Expand All @@ -41,17 +52,29 @@ public function testGrantAccessTokenWithGrantAuthCodeSuccess()
/**
* Tests OAuth2->grantAccessToken() with successful Auth code grant, but without redreict_uri in the input
*/
public function testGrantAccessTokenWithGrantAuthCodeSuccessWithoutRedirect()
public function testGrantAccessTokenWithGrantAuthCodeSuccessWithoutRedirect(): void
{
$request = new Request(
array('grant_type' => OAuth2::GRANT_TYPE_AUTH_CODE, 'client_id' => 'my_little_app', 'client_secret' => 'b', 'code'=> 'foo')
[
'grant_type' => OAuth2::GRANT_TYPE_AUTH_CODE,
'client_id' => 'my_little_app',
'client_secret' => 'b',
'code'=> 'foo'
]
);
$storedToken = new OAuth2AuthCode(
'my_little_app',
'',
time() + 60,
null,
null,
'http://www.example.com'
);
$storedToken = new OAuth2AuthCode('my_little_app', '', time() + 60, null, null, 'http://www.example.com');

$mockStorage = $this->createBaseMock('OAuth2\IOAuth2GrantCode');
$mockStorage = $this->createBaseMock(IOAuth2GrantCode::class);
$mockStorage->expects($this->any())
->method('getAuthCode')
->will($this->returnValue($storedToken));
->willReturn($storedToken);

$this->fixture = new OAuth2($mockStorage);
$this->fixture->setVariable(OAuth2::CONFIG_ENFORCE_INPUT_REDIRECT, false);
Expand All @@ -63,28 +86,25 @@ public function testGrantAccessTokenWithGrantAuthCodeSuccessWithoutRedirect()

// Utility methods

/**
*
* @param string $interfaceName
*/
protected function createBaseMock($interfaceName)

protected function createBaseMock(string $interfaceName): MockObject
{
$client = new OAuth2Client('my_little_app');

$mockStorage = $this->getMockBuilder($interfaceName)->getMock();
$mockStorage->expects($this->any())
->method('getClient')
->will($this->returnCallback(function ($id) use ($client) {
->willReturnCallback(function ($id) use ($client) {
if ('my_little_app' === $id) {
return $client;
}
}));
});
$mockStorage->expects($this->any())
->method('checkClientCredentials')
->will($this->returnValue(true)); // Always return true for any combination of user/pass
->willReturn(true); // Always return true for any combination of user/pass
$mockStorage->expects($this->any())
->method('checkRestrictedGrantType')
->will($this->returnValue(true)); // Always return true for any combination of user/pass
->willReturn(true); // Always return true for any combination of user/pass

return $mockStorage;
}
Expand Down
Loading